Skip to content

Commit

Permalink
depr(api): deprecate how parameter to arbitrary
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrist committed Mar 28, 2024
1 parent 7d593c4 commit be451a4
Show file tree
Hide file tree
Showing 29 changed files with 90 additions and 327 deletions.
9 changes: 1 addition & 8 deletions ibis/backends/bigquery/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class BigQueryCompiler(SQLGlotCompiler):
)

SIMPLE_OPS = {
ops.Arbitrary: "any_value",
ops.StringAscii: "ascii",
ops.BitAnd: "bit_and",
ops.BitOr: "bit_or",
Expand Down Expand Up @@ -496,14 +497,6 @@ def visit_Last(self, op, *, arg, where):
array = self.f.array_reverse(self.f.array_agg(sge.IgnoreNulls(this=arg)))
return array[self.f.safe_offset(0)]

def visit_Arbitrary(self, op, *, arg, how, where):
if how != "first":
raise com.UnsupportedOperationError(
f"{how!r} value not supported for arbitrary in BigQuery"
)

return self.agg.any_value(arg, where=where)

def visit_ArrayFilter(self, op, *, arg, body, param):
return self.f.array(
sg.select(param).from_(self._unnest(arg, as_=param)).where(body)
Expand Down
10 changes: 1 addition & 9 deletions ibis/backends/clickhouse/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class ClickHouseCompiler(SQLGlotCompiler):
ops.Any: "max",
ops.ApproxCountDistinct: "uniqHLL12",
ops.ApproxMedian: "median",
ops.Arbitrary: "any",
ops.ArgMax: "argMax",
ops.ArgMin: "argMin",
ops.ArrayCollect: "groupArray",
Expand Down Expand Up @@ -202,15 +203,6 @@ def visit_Correlation(self, op, *, left, right, how, where):
)
return self.agg.corr(left, right, where=where)

def visit_Arbitrary(self, op, *, arg, how, where):
if how == "first":
return self.agg.any(arg, where=where)
elif how == "last":
return self.agg.anyLast(arg, where=where)
else:
assert how == "heavy"
return self.agg.anyHeavy(arg, where=where)

def visit_Substring(self, op, *, arg, start, length):
# Clickhouse is 1-indexed
suffix = (length,) * (length is not None)
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/datafusion/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class DataFusionCompiler(SQLGlotCompiler):

UNSUPPORTED_OPERATIONS = frozenset(
(
ops.Arbitrary,
ops.ArgMax,
ops.ArgMin,
ops.ArrayDistinct,
Expand Down Expand Up @@ -65,6 +64,7 @@ class DataFusionCompiler(SQLGlotCompiler):
)

SIMPLE_OPS = {
ops.Arbitrary: "first_value",
ops.ApproxMedian: "approx_median",
ops.ArrayRemove: "array_remove_all",
ops.BitAnd: "bit_and",
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/druid/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class DruidCompiler(SQLGlotCompiler):
UNSUPPORTED_OPERATIONS = frozenset(
(
ops.ApproxMedian,
ops.Arbitrary,
ops.ArgMax,
ops.ArgMin,
ops.ArrayCollect,
Expand Down
1 change: 1 addition & 0 deletions ibis/backends/duckdb/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class DuckDBCompiler(SQLGlotCompiler):
type_mapper = DuckDBType

SIMPLE_OPS = {
ops.Arbitrary: "any_value",
ops.ArrayPosition: "list_indexof",
ops.BitAnd: "bit_and",
ops.BitOr: "bit_or",
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/exasol/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ExasolCompiler(SQLGlotCompiler):
(
ops.AnalyticVectorizedUDF,
ops.ApproxMedian,
ops.Arbitrary,
ops.ArgMax,
ops.ArgMin,
ops.ArrayCollect,
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/flink/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class FlinkCompiler(SQLGlotCompiler):
(
ops.AnalyticVectorizedUDF,
ops.ApproxMedian,
ops.Arbitrary,
ops.ArgMax,
ops.ArgMin,
ops.ArrayCollect,
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/impala/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class ImpalaCompiler(SQLGlotCompiler):

UNSUPPORTED_OPERATIONS = frozenset(
(
ops.Arbitrary,
ops.ArgMax,
ops.ArgMin,
ops.ArrayCollect,
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/mssql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ class MSSQLCompiler(SQLGlotCompiler):
UNSUPPORTED_OPERATIONS = frozenset(
(
ops.ApproxMedian,
ops.Arbitrary,
ops.ArgMax,
ops.ArgMin,
ops.ArrayCollect,
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/mysql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def POS_INF(self):
UNSUPPORTED_OPERATIONS = frozenset(
(
ops.ApproxMedian,
ops.Arbitrary,
ops.ArgMax,
ops.ArgMin,
ops.ArrayCollect,
Expand Down
1 change: 0 additions & 1 deletion ibis/backends/oracle/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ class OracleCompiler(SQLGlotCompiler):

UNSUPPORTED_OPERATIONS = frozenset(
(
ops.Arbitrary,
ops.ArgMax,
ops.ArgMin,
ops.ArrayCollect,
Expand Down
7 changes: 1 addition & 6 deletions ibis/backends/pandas/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,7 @@ def agg(df):

@classmethod
def visit(cls, op: ops.Arbitrary, arg, where, how):
if how == "first":
return cls.agg(cls.kernels.reductions[ops.First], arg, where)
elif how == "last":
return cls.agg(cls.kernels.reductions[ops.Last], arg, where)
else:
raise OperationNotDefinedError(f"Arbitrary {how!r} is not supported")
return cls.agg(cls.kernels.reductions[ops.First], arg, where)

@classmethod
def visit(cls, op: ops.ArgMin | ops.ArgMax, arg, key, where):
Expand Down
1 change: 1 addition & 0 deletions ibis/backends/postgres/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class PostgresCompiler(SQLGlotCompiler):
)

SIMPLE_OPS = {
ops.Arbitrary: "first", # could use any_value for postgres>=16
ops.ArrayCollect: "array_agg",
ops.ArrayRemove: "array_remove",
ops.BitAnd: "bit_and",
Expand Down
13 changes: 3 additions & 10 deletions ibis/backends/pyspark/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,18 +238,11 @@ def visit_Last(self, op, *, arg, where):
arg = self.if_(where, arg, NULL)
return sge.IgnoreNulls(this=self.f.last(arg))

def visit_Arbitrary(self, op, *, arg, how, where):
def visit_Arbitrary(self, op, *, arg, where):
# For Spark>=3.4 we could use any_value here
if where is not None:
arg = self.if_(where, arg, NULL)
if how == "first":
return sge.IgnoreNulls(this=self.f.first(arg))
elif how == "last":
return sge.IgnoreNulls(this=self.f.last(arg))
else:
raise com.UnsupportedOperationError(
f"PySpark backend does not support arbitrary with how={how}. "
"Supported values are `first` and `last`."
)
return sge.IgnoreNulls(this=self.f.first(arg))

def visit_Median(self, op, *, arg, where):
return self.agg.percentile(arg, 0.5, where=where)
Expand Down
1 change: 1 addition & 0 deletions ibis/backends/risingwave/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class RisingwaveCompiler(PostgresCompiler):

UNSUPPORTED_OPERATIONS = frozenset(
(
ops.Arbitrary,
ops.DateFromYMD,
ops.Mode,
ops.RandomUUID,
Expand Down
12 changes: 2 additions & 10 deletions ibis/backends/snowflake/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ class SnowflakeCompiler(SQLGlotCompiler):
)

SIMPLE_OPS = {
ops.Any: "max",
ops.All: "min",
ops.Any: "max",
ops.Arbitrary: "any_value",
ops.ArrayDistinct: "array_distinct",
ops.ArrayFlatten: "array_flatten",
ops.ArrayIndex: "get",
Expand Down Expand Up @@ -380,15 +381,6 @@ def visit_TimestampBucket(self, op, *, arg, interval, offset):

return self.f.time_slice(arg, interval.value, interval.dtype.unit.name)

def visit_Arbitrary(self, op, *, arg, how, where):
if how == "first":
return self.f.get(self.agg.array_agg(arg, where=where), 0)
elif how == "last":
expr = self.agg.array_agg(arg, where=where)
return self.f.get(expr, self.f.array_size(expr) - 1)
else:
raise com.UnsupportedOperationError("how must be 'first' or 'last'")

def visit_ArraySlice(self, op, *, arg, start, stop):
if start is None:
start = 0
Expand Down
7 changes: 0 additions & 7 deletions ibis/backends/sql/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,13 +930,6 @@ def visit_VarianceStandardDevCovariance(self, op, *, how, where, **kw):
visit_VarianceStandardDevCovariance
)

def visit_Arbitrary(self, op, *, arg, how, where):
if how == "heavy":
raise com.UnsupportedOperationError(
f"how='heavy' not supported in the {self.dialect} backend"
)
return self.agg[how](arg, where=where)

def visit_SimpleCase(self, op, *, base=None, cases, results, default):
return sge.Case(
this=base, ifs=list(map(self.if_, cases, results)), default=default
Expand Down
13 changes: 3 additions & 10 deletions ibis/backends/sqlite/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class SQLiteCompiler(SQLGlotCompiler):
)

SIMPLE_OPS = {
ops.Arbitrary: "_ibis_first",
ops.RegexReplace: "_ibis_regex_replace",
ops.RegexExtract: "_ibis_regex_extract",
ops.RegexSearch: "_ibis_regex_search",
Expand All @@ -92,8 +93,8 @@ class SQLiteCompiler(SQLGlotCompiler):
ops.BitOr: "_ibis_bit_or",
ops.BitAnd: "_ibis_bit_and",
ops.BitXor: "_ibis_bit_xor",
ops.First: "_ibis_arbitrary_first",
ops.Last: "_ibis_arbitrary_last",
ops.First: "_ibis_first",
ops.Last: "_ibis_last",
ops.Mode: "_ibis_mode",
ops.Time: "time",
ops.Date: "date",
Expand Down Expand Up @@ -213,14 +214,6 @@ def visit_RandomScalar(self, op):
def visit_Cot(self, op, *, arg):
return 1 / self.f.tan(arg)

def visit_Arbitrary(self, op, *, arg, how, where):
if op.how == "heavy":
raise com.OperationNotDefinedError(
"how='heavy' not implemented for the SQLite backend"
)

return self._aggregate(f"_ibis_arbitrary_{how}", arg, where=where)

def visit_ArgMin(self, *args, **kwargs):
return self._visit_arg_reduction("min", *args, **kwargs)

Expand Down
6 changes: 3 additions & 3 deletions ibis/backends/sqlite/udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def __init__(self):
super().__init__(operator.xor)


class _ibis_arbitrary(abc.ABC):
class _ibis_first_last(abc.ABC):
def __init__(self) -> None:
self.value = None

Expand All @@ -450,14 +450,14 @@ def finalize(self) -> int | None:


@udaf
class _ibis_arbitrary_first(_ibis_arbitrary):
class _ibis_first(_ibis_first_last):
def step(self, value):
if self.value is None:
self.value = value


@udaf
class _ibis_arbitrary_last(_ibis_arbitrary):
class _ibis_last(_ibis_first_last):
def step(self, value):
if value is not None:
self.value = value
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH "t5" AS (
SELECT
"t4"."field_of_study",
FIRST("t4"."diff") AS "diff"
ANY_VALUE("t4"."diff") AS "diff"
FROM (
SELECT
"t3"."field_of_study",
Expand Down

This file was deleted.

Loading

0 comments on commit be451a4

Please sign in to comment.