Skip to content

Commit 741063a

Browse files
kszucscpcloud
andauthored
fix(ir): make impure ibis.random() and ibis.uuid() functions return unique node instances (ibis-project#8967)
Co-authored-by: Phillip Cloud <417981+cpcloud@users.noreply.github.com>
1 parent 200e4ea commit 741063a

55 files changed

Lines changed: 502 additions & 54 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ibis/backends/bigquery/compiler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ class BigQueryCompiler(SQLGlotCompiler):
120120
ops.RPad: "rpad",
121121
ops.Levenshtein: "edit_distance",
122122
ops.Modulus: "mod",
123-
ops.RandomScalar: "rand",
124-
ops.RandomUUID: "generate_uuid",
125123
ops.RegexReplace: "regexp_replace",
126124
ops.RegexSearch: "regexp_contains",
127125
ops.Time: "time",
@@ -695,3 +693,6 @@ def visit_CountDistinct(self, op, *, arg, where):
695693
if where is not None:
696694
arg = self.if_(where, arg, NULL)
697695
return self.f.count(sge.Distinct(expressions=[arg]))
696+
697+
def visit_RandomUUID(self, op, **kwargs):
698+
return self.f.generate_uuid()

ibis/backends/clickhouse/compiler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ class ClickHouseCompiler(SQLGlotCompiler):
9898
ops.NotNull: "isNotNull",
9999
ops.NullIf: "nullIf",
100100
ops.RStrip: "trimRight",
101-
ops.RandomScalar: "randCanonical",
102-
ops.RandomUUID: "generateUUIDv4",
103101
ops.RegexReplace: "replaceRegexpAll",
104102
ops.RowNumber: "row_number",
105103
ops.StartsWith: "startsWith",
@@ -635,6 +633,12 @@ def visit_TimestampRange(self, op, *, start, stop, step):
635633
def visit_RegexSplit(self, op, *, arg, pattern):
636634
return self.f.splitByRegexp(pattern, self.cast(arg, dt.String(nullable=False)))
637635

636+
def visit_RandomScalar(self, op, **kwargs):
637+
return self.f.randCanonical()
638+
639+
def visit_RandomUUID(self, op, **kwargs):
640+
return self.f.generateUUIDv4()
641+
638642
@staticmethod
639643
def _generate_groups(groups):
640644
return groups

ibis/backends/datafusion/compiler.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ class DataFusionCompiler(SQLGlotCompiler):
7575
ops.Last: "last_value",
7676
ops.Median: "median",
7777
ops.StringLength: "character_length",
78-
ops.RandomUUID: "uuid",
7978
ops.RegexSplit: "regex_split",
8079
ops.EndsWith: "ends_with",
8180
ops.ArrayIntersect: "array_intersect",

ibis/backends/druid/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class DruidCompiler(SQLGlotCompiler):
5959
ops.Median,
6060
ops.MultiQuantile,
6161
ops.Quantile,
62+
ops.RandomUUID,
6263
ops.RegexReplace,
6364
ops.RegexSplit,
6465
ops.RowID,

ibis/backends/duckdb/compiler.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class DuckDBCompiler(SQLGlotCompiler):
4848
ops.MapMerge: "map_concat",
4949
ops.MapValues: "map_values",
5050
ops.Mode: "mode",
51-
ops.RandomUUID: "uuid",
5251
ops.TimeFromHMS: "make_time",
5352
ops.TypeOf: "typeof",
5453
ops.GeoPoint: "st_point",
@@ -450,3 +449,9 @@ def visit_StructField(self, op, *, arg, field):
450449
expression=sg.to_identifier(field, quoted=self.quoted),
451450
)
452451
return super().visit_StructField(op, arg=arg, field=field)
452+
453+
def visit_RandomScalar(self, op, **kwargs):
454+
return self.f.random()
455+
456+
def visit_RandomUUID(self, op, **kwargs):
457+
return self.f.uuid()

ibis/backends/exasol/compiler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ class ExasolCompiler(SQLGlotCompiler):
6767
ops.Median,
6868
ops.MultiQuantile,
6969
ops.Quantile,
70+
ops.RandomUUID,
7071
ops.ReductionVectorizedUDF,
7172
ops.RegexExtract,
7273
ops.RegexReplace,

ibis/backends/flink/compiler.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,6 @@ class FlinkCompiler(SQLGlotCompiler):
7979
ops.MapKeys: "map_keys",
8080
ops.MapValues: "map_values",
8181
ops.Power: "power",
82-
ops.RandomScalar: "rand",
83-
ops.RandomUUID: "uuid",
8482
ops.RegexSearch: "regexp",
8583
ops.StrRight: "right",
8684
ops.StringLength: "char_length",

ibis/backends/impala/compiler.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ class ImpalaCompiler(SQLGlotCompiler):
7676
ops.Hash: "fnv_hash",
7777
ops.LStrip: "ltrim",
7878
ops.Ln: "ln",
79-
ops.RandomUUID: "uuid",
8079
ops.RStrip: "rtrim",
8180
ops.Strip: "trim",
8281
ops.TypeOf: "typeof",
@@ -146,7 +145,7 @@ def visit_CountDistinct(self, op, *, arg, where):
146145
def visit_Xor(self, op, *, left, right):
147146
return sg.and_(sg.or_(left, right), sg.not_(sg.and_(left, right)))
148147

149-
def visit_RandomScalar(self, op):
148+
def visit_RandomScalar(self, op, **_):
150149
return self.f.rand(self.f.utc_to_unix_micros(self.f.utc_timestamp()))
151150

152151
def visit_DayOfWeekIndex(self, op, *, arg):

ibis/backends/mssql/compiler.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,6 @@ class MSSQLCompiler(SQLGlotCompiler):
129129
ops.Ln: "log",
130130
ops.Log10: "log10",
131131
ops.Power: "power",
132-
ops.RandomScalar: "rand",
133-
ops.RandomUUID: "newid",
134132
ops.Repeat: "replicate",
135133
ops.Reverse: "reverse",
136134
ops.StringAscii: "ascii",
@@ -172,6 +170,9 @@ def _minimize_spec(start, end, spec):
172170
return None
173171
return spec
174172

173+
def visit_RandomUUID(self, op, **kwargs):
174+
return self.f.newid()
175+
175176
def visit_StringLength(self, op, *, arg):
176177
"""The MSSQL LEN function doesn't count trailing spaces.
177178

ibis/backends/oracle/compiler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class OracleCompiler(SQLGlotCompiler):
8080
ops.ExtractWeekOfYear,
8181
ops.ExtractDayOfYear,
8282
ops.RowID,
83+
ops.RandomUUID,
8384
)
8485
)
8586

@@ -221,7 +222,7 @@ def visit_Log(self, op, *, arg, base):
221222
def visit_IsInf(self, op, *, arg):
222223
return arg.isin(self.POS_INF, self.NEG_INF)
223224

224-
def visit_RandomScalar(self, op):
225+
def visit_RandomScalar(self, op, **_):
225226
# Not using FuncGen here because of dotted function call
226227
return sg.func("dbms_random.value")
227228

0 commit comments

Comments
 (0)