Skip to content

Commit

Permalink
fix(sqlite): ensure ibis.uuid() generates a unique uuid per row
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Mar 4, 2024
1 parent e8bc3b9 commit 606a260
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
5 changes: 3 additions & 2 deletions ibis/backends/sqlite/udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def pi():
return math.pi


@udf(skip_if_exists=True)
@udf(skip_if_exists=True, deterministic=False)
def uuid():
return str(uuid4())

Expand Down Expand Up @@ -432,7 +432,8 @@ def __init__(self) -> None:
self.value = None

@abc.abstractmethod
def step(self, value): ...
def step(self, value):
...

def finalize(self) -> int | None:
return self.value
Expand Down
23 changes: 23 additions & 0 deletions ibis/backends/tests/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,26 @@ def test_uuid_function(con):
obj = con.execute(ibis.uuid())
assert isinstance(obj, uuid.UUID)
assert obj.version == 4


@pytest.mark.notimpl(
[
"datafusion",
"druid",
"exasol",
"flink",
"mssql",
"mysql",
"oracle",
"polars",
"pyspark",
"risingwave",
],
raises=com.OperationNotDefinedError,
)
@pytest.mark.notimpl(["pandas", "dask"], raises=ValueError)
def test_uuid_unique_each_row(con):
expr = (
con.tables.functional_alltypes.mutate(uuid=ibis.uuid()).limit(2).uuid.nunique()
)
assert expr.execute() == 2

0 comments on commit 606a260

Please sign in to comment.