Skip to content

Commit 1693984

Browse files
committed
fix(udf): make udfs impure and avoid merging selects with impure functions
1 parent 9377966 commit 1693984

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

ibis/backends/sql/rewrites.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import annotations
44

55
import operator
6+
import sys
67
from collections.abc import Mapping
78
from functools import reduce
89
from typing import TYPE_CHECKING, Any
@@ -230,6 +231,9 @@ def complexity(node):
230231
def accum(node, *args):
231232
if isinstance(node, ops.Field):
232233
return 1
234+
elif isinstance(node, ops.Impure):
235+
# consider (potentially) impure functions maximally complex
236+
return sys.maxsize
233237
else:
234238
return 1 + sum(args)
235239

ibis/expr/operations/generic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,15 +189,15 @@ class Impure(Value):
189189

190190

191191
@public
192-
class TimestampNow(Constant):
192+
class TimestampNow(Impure):
193193
"""Return the current timestamp."""
194194

195195
dtype = dt.timestamp
196196
shape = ds.scalar
197197

198198

199199
@public
200-
class DateNow(Constant):
200+
class DateNow(Impure):
201201
"""Return the current date."""
202202

203203
dtype = dt.date

ibis/expr/operations/udf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class InputType(enum.Enum):
5151

5252

5353
@public
54-
class ScalarUDF(ops.Value):
54+
class ScalarUDF(ops.Impure):
5555
@attribute
5656
def shape(self):
5757
if not (args := getattr(self, "args")): # noqa: B009
@@ -65,7 +65,7 @@ def shape(self):
6565

6666

6767
@public
68-
class AggUDF(ops.Reduction):
68+
class AggUDF(ops.Reduction, ops.Impure):
6969
where: Optional[ops.Value[dt.Boolean]] = None
7070

7171

0 commit comments

Comments
 (0)