Skip to content

Commit

Permalink
feat(snowflake): implement ops.Arbitrary
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jan 22, 2023
1 parent 3d94082 commit 45f4f05
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ibis/backends/snowflake/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ def _nth_value(t, op):
return sa.func.nth_value(t.translate(op.arg), nth.value + 1)


def _arbitrary(t, op):
if op.how != "first":
raise ValueError(
"Snowflake only supports the `first` option for `.arbitrary()`"
)

# we can't use any_value here because it respects nulls
#
# yes it's slower, but it's also consistent with every other backend
return t._reduction(sa.func.min, op)


_TIMESTAMP_UNITS_TO_SCALE = {"s": 0, "ms": 3, "us": 6, "ns": 9}

_SF_POS_INF = sa.func.to_double("Inf")
Expand Down Expand Up @@ -247,6 +259,7 @@ def _nth_value(t, op):
sa.func.get(t.translate(op.arg), op.field), t.get_sqla_type(op.output_dtype)
),
ops.NthValue: _nth_value,
ops.Arbitrary: _arbitrary,
}
)

Expand Down
2 changes: 0 additions & 2 deletions ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ def mean_and_std(v):
'postgres',
'mysql',
'sqlite',
'snowflake',
'polars',
'datafusion',
"mssql",
Expand All @@ -401,7 +400,6 @@ def mean_and_std(v):
'postgres',
'mysql',
'sqlite',
'snowflake',
'polars',
'datafusion',
"mssql",
Expand Down

0 comments on commit 45f4f05

Please sign in to comment.