Skip to content

[data] Monotonically increasing id - #59290

Merged
alexeykudinkin merged 12 commits into
ray-project:masterfrom
rishic3:mono-incr-id
Feb 10, 2026
Merged

alexeykudinkin merged 12 commits into
ray-project:masterfrom
rishic3:mono-incr-id

Conversation

@rishic3

@rishic3 rishic3 commented Dec 9, 2025 •

Copy link
Copy Markdown
Contributor

Description

Implements monotonically increasing ID expression. This closely follows the Spark implementation https://github.com/apache/spark/blob/9bbdc0743034b40a904ca87a08da4e0bf2b1386c/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/MonotonicallyIncreasingID.scala.

Example usage:

from ray.data.expressions import monotonically_increasing_id

ds = ray.data.range(100)
ds = ds.with_column("uid", monotonically_increasing_id())
train, test = ds_with_id.streaming_train_test_split(test_size=0.25, split_type="hash", hash_column="uid")

Related issues

Closes #57806

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces add_unique_id to add a monotonically increasing ID column to a dataset, which is a valuable addition. The implementation is clear and follows the described logic from Spark. However, I've identified a significant correctness issue in the handling of pyarrow.Table objects, which results in creating a nested list column instead of a flat integer column. I've also provided suggestions to improve efficiency, remove unreachable code, and enhance the clarity of the documentation. The tests are well-structured, but they may not be catching the pyarrow bug I've pointed out.

Comment thread python/ray/data/dataset.py Resolved
Comment thread python/ray/data/dataset.py Resolved
Comment thread python/ray/data/dataset.py Resolved
Comment thread python/ray/data/dataset.py Resolved
@ray-gardener ray-gardener Bot added data Ray Data-related issues community-contribution Contributed by the community labels Dec 9, 2025
@richardliaw

Copy link
Copy Markdown
Contributor

awesome! thanks a bunch for this contribution. will let @gvspraveen find someone to shepherd this.

@gvspraveen

Copy link
Copy Markdown
Contributor

Thanks for the contribution. @bveeramani to shepherd this.

@richardliaw

Copy link
Copy Markdown
Contributor

hey @rishic3, thanks a bunch for the contribution! if you're interested in chatting more with the contributors, feel free to join our community sync -- https://docs.google.com/forms/d/e/1FAIpQLSeYWjNExnr6gbhO5rpM0i6wm4TBTdsm3y5S0LR8Syzk_2gelQ/viewform

@rishic3

rishic3 commented Dec 10, 2025 •

Copy link
Copy Markdown
Contributor Author

Previous commit implemented as a dataset method (see e0fc987). Pushed an update that instead implements as an expression as per original issue intended.

@bveeramani

Copy link
Copy Markdown
Member

Hey @rishic3 , thanks for opening the PR! I'll review first thing tomorrow

Comment on lines +699 to +702
if ctx is None:
raise RuntimeError(
"monotonically_increasing_id() must be evaluated within a Ray task"
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: This seems more of an internal correctness assumption. Would this be better as an assertion?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense, done

Comment on lines +178 to +184
def visit_monotonically_increasing_id(
self, expr: "MonotonicallyIncreasingIdExpr"
) -> "BooleanExpression | UnboundTerm[Any] | Literal[Any]":
"""Monotonically increasing ID expressions cannot be converted to Iceberg expressions."""
raise TypeError(
"monotonically_increasing_id expressions cannot be converted to Iceberg filter expressions."
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking for this PR since it's internal, but I'm worried that we'll need to expand the visitor interface each time we introduce a new expression, and that'll become unwieldy.

@goutamvenkat-anyscale what's your take? Is there an easy solution?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's exactly the goal of the visitor pattern -- to guarantee that all expressions are being properly handled

Comment on lines +965 to +967
def structurally_equals(self, other: Any) -> bool:
# Non-deterministic, never structurally equal to another expression
return False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goutamvenkat-anyscale in Ray Data's context, what does structurally equal mean? I read the docstring but it doesn't really answer my question: """Compare two expression ASTs for structural equality."""

Should two MonotonicallyIncreasingIdExpr be structurally equal?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't seem used by optimizer yet but I'm assuming for e.g. common subexpression elimination which we wouldn't want applied to non-deterministic expressions.

Comment thread python/ray/data/expressions.py Resolved
Comment thread python/ray/data/expressions.py Resolved
@rishic3

rishic3 commented Dec 14, 2025 •

Copy link
Copy Markdown
Contributor Author

This expr is the first to depend on TaskContext. Looks like using it with shuffle will fail

ds = ray.data.range(10, override_num_blocks=2)
ds = ds.with_column("uid", monotonically_increasing_id())
ds = ds.random_shuffle()
ds.take_all()

With AssertionError: TaskContext is required for monotonically_increasing_id()

(traceback>
2025-12-14 12:45:51,868	ERROR worker.py:433 -- Unhandled error (suppress with 'RAY_IGNORE_UNHANDLED_ERRORS=1'): �[36mray::map()�[39m (pid=443311, ip=10.110.47.100)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 781, in eval_projection
    names, output_cols = zip(*[(e.name, eval_expr(e, block)) for e in projection_exprs])
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 781, in <listcomp>
    names, output_cols = zip(*[(e.name, eval_expr(e, block)) for e in projection_exprs])
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 737, in eval_expr
    return evaluator.visit(expr)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/expressions.py", line 96, in visit
    return self.visit_alias(expr)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 657, in visit_alias
    return self.visit(expr.expr)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/expressions.py", line 104, in visit
    return self.visit_monotonically_increasing_id(expr)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 700, in visit_monotonically_increasing_id
    ctx is not None
AssertionError: TaskContext is required for monotonically_increasing_id()

The above exception was the direct cause of the following exception:

�[36mray::map()�[39m (pid=443311, ip=10.110.47.100)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/exchange/shuffle_task_spec.py", line 63, in map
    mapped_block = next(upstream_map_iter)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/execution/operators/map_transformer.py", line 102, in __call__
    yield from self._post_process(results)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/execution/operators/map_transformer.py", line 84, in _shape_blocks
    for result in results:
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/execution/operators/map_transformer.py", line 406, in _apply_transform
    yield from self._block_fn(blocks, ctx)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_udf_map_op.py", line 608, in transform_fn
    out_block = fn(block)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_udf_map_op.py", line 129, in _project_block
    _try_wrap_udf_exception(e)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_udf_map_op.py", line 427, in _try_wrap_udf_exception
    raise UserCodeException("UDF failed to process a data block.") from e
ray.exceptions.UserCodeException: UDF failed to process a data block.

...as the shuffle schedulers e.g.

do not propagate the task ctx to ShuffleTaskSpec.map().

Quick fix could be wrapping execution of the upstream map fn in the shuffle task spec in a new task context

or I suppose the more complete change is creating the task ctx at the scheduler level and changing the downstream functions to accept task ctx.

Wondering if this path makes sense or if implementing this as a dedicated operator (like e0fc987) would be preferred to keep expressions independent of task context in the first place. @bveeramani @goutamvenkat-anyscale

@bveeramani

Copy link
Copy Markdown
Member

This expr is the first to depend on TaskContext. Looks like using it with shuffle will fail

ds = ray.data.range(10, override_num_blocks=2)
ds = ds.with_column("uid", monotonically_increasing_id())
ds = ds.random_shuffle()
ds.take_all()

With AssertionError: TaskContext is required for monotonically_increasing_id()

(traceback>

2025-12-14 12:45:51,868	ERROR worker.py:433 -- Unhandled error (suppress with 'RAY_IGNORE_UNHANDLED_ERRORS=1'): �[36mray::map()�[39m (pid=443311, ip=10.110.47.100)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 781, in eval_projection
    names, output_cols = zip(*[(e.name, eval_expr(e, block)) for e in projection_exprs])
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 781, in <listcomp>
    names, output_cols = zip(*[(e.name, eval_expr(e, block)) for e in projection_exprs])
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 737, in eval_expr
    return evaluator.visit(expr)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/expressions.py", line 96, in visit
    return self.visit_alias(expr)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 657, in visit_alias
    return self.visit(expr.expr)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/expressions.py", line 104, in visit
    return self.visit_monotonically_increasing_id(expr)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_expression/expression_evaluator.py", line 700, in visit_monotonically_increasing_id
    ctx is not None
AssertionError: TaskContext is required for monotonically_increasing_id()

The above exception was the direct cause of the following exception:

�[36mray::map()�[39m (pid=443311, ip=10.110.47.100)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/exchange/shuffle_task_spec.py", line 63, in map
    mapped_block = next(upstream_map_iter)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/execution/operators/map_transformer.py", line 102, in __call__
    yield from self._post_process(results)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/execution/operators/map_transformer.py", line 84, in _shape_blocks
    for result in results:
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/execution/operators/map_transformer.py", line 406, in _apply_transform
    yield from self._block_fn(blocks, ctx)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_udf_map_op.py", line 608, in transform_fn
    out_block = fn(block)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_udf_map_op.py", line 129, in _project_block
    _try_wrap_udf_exception(e)
  File "/home/rishic/anaconda3/envs/ray-dev/lib/python3.10/site-packages/ray/data/_internal/planner/plan_udf_map_op.py", line 427, in _try_wrap_udf_exception
    raise UserCodeException("UDF failed to process a data block.") from e
ray.exceptions.UserCodeException: UDF failed to process a data block.

...as the shuffle schedulers e.g.

do not propagate the task ctx to ShuffleTaskSpec.map().
Quick fix could be wrapping execution of the upstream map fn in the shuffle task spec in a new task context

or I suppose the more complete change is creating the task ctx at the scheduler level and changing the downstream functions to accept task ctx.
Wondering if this path makes sense or if implementing this as a dedicated operator (like e0fc987) would be preferred to keep expressions independent of task context in the first place. @bveeramani @goutamvenkat-anyscale

Got it. Will defer to @goutamvenkat-anyscale since he's the resident expressions expert

The assumption is that the dataset schedules less than 1 billion tasks, and
each task processes less than 8 billion records.

The function is non-deterministic because its result depends on task IDs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task has to be deterministic assuming its inputs are fixed (and this method is deterministic in that def)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree that it is deterministic at the granularity of a task, though at dataset level task assignment would be non-deterministic - so still seems like right description from user POV?

Comment on lines +703 to +707
# Key the counter by expression instance ID so that multiple expressions
# in the same projection will have isolated row count state
counter_key = f"_mono_id_{expr._instance_id}_counter"

start_idx = ctx.kwargs.get(counter_key, 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rishic3 we'd not store state like that inside TaskContext.

Besides -- we don't need to provide a guarantee that 2 expressions will produce different results.

(but even if we did we can do that by just simply shuffling the ids w/in a block)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to provide a guarantee that 2 expressions will produce different results

Not quite following - keying by instance ID here so that two expressions don't increment each other's row counts when executed by the same task (so if anything, would ensure in such a case ids are the same)

we'd not store state like that inside TaskContext.

Agree it's not ideal. Was considering making it an instance attribute of MonotonicallyIncreasingIdExpr, though would require it to be stateful (might necessitate a new non-frozen base class).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rishic3 my point is -- why do you need start_idx in the TaskContext at all?

  • Because every task's range is isolated (via task id bits) you just need to run a counter from 0 to num_rows in every block
  • If you want different expressions (which is not a requirement btw) just shuffle row ids

@rishic3 rishic3 Jan 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct me if i'm wrong, but my understanding is a single task could process multiple blocks:

def transform_fn(blocks: Iterable[Block], _: TaskContext) -> Iterable[Block]:

For example if I force this behavior by setting max block size to 32 bytes (4 int64 rows per block, across 5 tasks below):

from ray.data.expressions import monotonically_increasing_id

ctx = ray.data.DataContext.get_current()
ctx.target_max_block_size = 32

ds = ray.data.range(100, override_num_blocks=5)
ds = ds.with_column("uid", monotonically_increasing_id())
result = ds.take_all()

With a print statement in visit_monotonically_increasing_id this shows

(ReadRange->Project pid=496751) Task ID 2 is starting at start_idx: 0
(ReadRange->Project pid=496751) Task ID 2 is starting at start_idx: 4
(ReadRange->Project pid=496751) Task ID 2 is starting at start_idx: 8
(ReadRange->Project pid=496751) Task ID 2 is starting at start_idx: 12
(ReadRange->Project pid=496751) Task ID 2 is starting at start_idx: 16

so if we were to just run a counter we'd lost monotonicity across these blocks (i.e., these would all start at 0).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, you're right -- we actually compress into 1 block for file-based datasources but not for all data-sources (which we should btw).

Can you please leave a comment why we're doing this.

Please also add a test for it!

Comment on lines +713 to +715
ids = partition_mask + np.arange(
start_idx, start_idx + num_rows, dtype=np.int64
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to apply mask on the num rows to make sure it's not exceeding 32 bits

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, added exceptions on overflows

@wingkitlee0

Copy link
Copy Markdown
Contributor

FYI, I am implementing random() and uuid() expressions in #59656... and adding a NullaryExpr...so probably related to this (i.e., we only need one visit_nullary() instead of many visit methods)

@rishic3

rishic3 commented Dec 30, 2025

Copy link
Copy Markdown
Contributor Author

@goutamvenkat-anyscale do you mind taking a look when you get the chance? Thanks!

@rishic3

rishic3 commented Jan 16, 2026

Copy link
Copy Markdown
Contributor Author

Added task context to shuffle task spec to unblock the shuffle issue, since it looks like other expressions will need it.

@wingkitlee0

wingkitlee0 commented Jan 16, 2026 •

Copy link
Copy Markdown
Contributor

@rishic3 @iamjustinhsu @bveeramani @alexeykudinkin @goutamvenkat-anyscale

Can you guys take a look of a similar PR (for random and uuid) in #59656
(adding the core logics of monotonically_increasing_id() into that framework (in that PR) should be straight-forward)

Likely we will need some coordinations (and some decisions from Ray team)

@github-actions

Copy link
Copy Markdown

This pull request has been automatically marked as stale because it has not had
any activity for 14 days. It will be closed in another 14 days if no further activity occurs.
Thank you for your contributions.

You can always ask for help on our discussion forum or Ray's public slack channel.

If you'd like to keep this open, just leave any comment, and the stale label will be removed.

@github-actions github-actions Bot added the stale The issue is stale. It will be closed within 7 days unless there are further conversation label Jan 31, 2026
@rishic3

rishic3 commented Jan 31, 2026

Copy link
Copy Markdown
Contributor Author

Unstaling.

@github-actions github-actions Bot added unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it. and removed stale The issue is stale. It will be closed within 7 days unless there are further conversation labels Jan 31, 2026
Signed-off-by: Rishi Chandra <[email protected]>

# Conflicts:
#	python/ray/data/tests/test_map.py

Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Signed-off-by: Rishi Chandra <[email protected]>
@rishic3

rishic3 commented Feb 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@rishic3 i'm gonna land your PR as is, but please follow-up with adding the test (see my comments inline)

Thanks -- had to add a missing doc in expressions.rst, so went ahead and addressed your comments as well.

(Aside, looks like there's an unrelated failure with missing pkg_reources for sphinxemoji on docs build, also affecting other PRs. Might be setuptools deprecation per SO.)

@alexeykudinkin
alexeykudinkin merged commit 27698a6 into ray-project:master Feb 10, 2026
3 checks passed
ans9868 pushed a commit to ans9868/ray that referenced this pull request Feb 18, 2026
## Description
Implements monotonically increasing ID expression. This closely follows
the Spark implementation
https://github.com/apache/spark/blob/9bbdc0743034b40a904ca87a08da4e0bf2b1386c/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/MonotonicallyIncreasingID.scala.

Example usage:
```python
from ray.data.expressions import monotonically_increasing_id

ds = ray.data.range(100)
ds = ds.with_column("uid", monotonically_increasing_id())
train, test = ds_with_id.streaming_train_test_split(test_size=0.25, split_type="hash", hash_column="uid")
```

## Related issues
Closes ray-project#57806

---------

Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
Signed-off-by: Adel Nour <[email protected]>
Aydin-ab pushed a commit to kunling-anyscale/ray that referenced this pull request Feb 20, 2026
## Description
Implements monotonically increasing ID expression. This closely follows
the Spark implementation
https://github.com/apache/spark/blob/9bbdc0743034b40a904ca87a08da4e0bf2b1386c/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/MonotonicallyIncreasingID.scala.

Example usage:
```python
from ray.data.expressions import monotonically_increasing_id

ds = ray.data.range(100)
ds = ds.with_column("uid", monotonically_increasing_id())
train, test = ds_with_id.streaming_train_test_split(test_size=0.25, split_type="hash", hash_column="uid")
```

## Related issues
Closes ray-project#57806

---------

Signed-off-by: Alexey Kudinkin <[email protected]>
Signed-off-by: Rishi Chandra <[email protected]>
richardliaw pushed a commit that referenced this pull request Mar 24, 2026
## Description

Adding two new expressions:
* `random()` for generating a column of uniform random number.
* `uuid()` for generating UUID (a column of unique strings)

`random()` accepts two arguments, related to reproducibility:
* `seed`: a "base" random seed. Default is `None`.
* `reseed_after_execution`: This is a flag that affects the random
number generation across different iteration of `iter_batches` (i.e.,
across different epochs in the context of epochs). See also,
#59528. It only matters when the
`seed` is set. If False, each dataset execution will generate the same
set of random number. If True, each dataset execution (i.e., training
epoch) will give a new but reproducible set of random number.

`uuid()` takes no argument.

## Related issues
Related to #55275

Related to #59662 as well. I did this PR first...so probably I could use
the same `RandomSeedConfig` in that PR.

## Additional information

[Random seed business] The actual seed sequence used to initialize the
random number generator is `[block_idx, task_idx, execution_idx,
base_seed]`. The block idx is tracked by a counter (like in
`monotonically_increasing_id()`). The task and execution indices are
coming from `TaskContext` and `DataContext`, respectively. The way I
used `execution_idx` is slightly different to what `FileShuffleConfig`
is doing, but I think all these random seed business could be
consolidated in the future (e.g., random_sample)

[Independent visit functions] Following the discussion in
#59290, there are separate
`visit_uuid()` and `visit_random` for these expressions.

Signed-off-by: Kit Lee <[email protected]>
ryanaoleary pushed a commit to ryanaoleary/ray that referenced this pull request Mar 25, 2026
## Description

Adding two new expressions:
* `random()` for generating a column of uniform random number.
* `uuid()` for generating UUID (a column of unique strings)

`random()` accepts two arguments, related to reproducibility:
* `seed`: a "base" random seed. Default is `None`.
* `reseed_after_execution`: This is a flag that affects the random
number generation across different iteration of `iter_batches` (i.e.,
across different epochs in the context of epochs). See also,
ray-project#59528. It only matters when the
`seed` is set. If False, each dataset execution will generate the same
set of random number. If True, each dataset execution (i.e., training
epoch) will give a new but reproducible set of random number.

`uuid()` takes no argument.

## Related issues
Related to ray-project#55275

Related to ray-project#59662 as well. I did this PR first...so probably I could use
the same `RandomSeedConfig` in that PR.

## Additional information

[Random seed business] The actual seed sequence used to initialize the
random number generator is `[block_idx, task_idx, execution_idx,
base_seed]`. The block idx is tracked by a counter (like in
`monotonically_increasing_id()`). The task and execution indices are
coming from `TaskContext` and `DataContext`, respectively. The way I
used `execution_idx` is slightly different to what `FileShuffleConfig`
is doing, but I think all these random seed business could be
consolidated in the future (e.g., random_sample)

[Independent visit functions] Following the discussion in
ray-project#59290, there are separate
`visit_uuid()` and `visit_random` for these expressions.

Signed-off-by: Kit Lee <[email protected]>
Lucas61000 pushed a commit to Lucas61000/ray that referenced this pull request May 15, 2026
## Description

Adding two new expressions:
* `random()` for generating a column of uniform random number.
* `uuid()` for generating UUID (a column of unique strings)

`random()` accepts two arguments, related to reproducibility:
* `seed`: a "base" random seed. Default is `None`.
* `reseed_after_execution`: This is a flag that affects the random
number generation across different iteration of `iter_batches` (i.e.,
across different epochs in the context of epochs). See also,
ray-project#59528. It only matters when the
`seed` is set. If False, each dataset execution will generate the same
set of random number. If True, each dataset execution (i.e., training
epoch) will give a new but reproducible set of random number.

`uuid()` takes no argument.

## Related issues
Related to ray-project#55275

Related to ray-project#59662 as well. I did this PR first...so probably I could use
the same `RandomSeedConfig` in that PR.

## Additional information

[Random seed business] The actual seed sequence used to initialize the
random number generator is `[block_idx, task_idx, execution_idx,
base_seed]`. The block idx is tracked by a counter (like in
`monotonically_increasing_id()`). The task and execution indices are
coming from `TaskContext` and `DataContext`, respectively. The way I
used `execution_idx` is slightly different to what `FileShuffleConfig`
is doing, but I think all these random seed business could be
consolidated in the future (e.g., random_sample)

[Independent visit functions] Following the discussion in
ray-project#59290, there are separate
`visit_uuid()` and `visit_random` for these expressions.

Signed-off-by: Kit Lee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community data Ray Data-related issues go add ONLY when ready to merge, run all tests unstale A PR that has been marked unstale. It will not get marked stale again if this label is on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[data] Support expression for monotonically increasing id

7 participants