Skip to content

Commit

Permalink
feat(bigquery): implementt ops.NthValue
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-kwitt authored and cpcloud committed Jan 6, 2023
1 parent 2bbf73c commit b43ba28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ibis/backends/bigquery/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,15 @@ def _clip(t, op):
return arg


def _nth_value(t, op):
arg = t.translate(op.arg)

if not isinstance(nth_op := op.nth, ops.Literal):
raise TypeError(f"Bigquery nth must be a literal; got {type(op.nth)}")

return f'NTH_VALUE({arg}, {nth_op.value + 1})'


OPERATION_REGISTRY = {
**operation_registry,
# Literal
Expand Down Expand Up @@ -670,6 +679,7 @@ def _clip(t, op):
ops.Pi: lambda *_: "ACOS(-1)",
ops.E: lambda *_: "EXP(1)",
ops.RandomScalar: fixed_arity("RAND", 0),
ops.NthValue: _nth_value,
}

_invalid_operations = {
Expand Down
7 changes: 6 additions & 1 deletion ibis/backends/tests/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ def calc_zscore(s):
),
id="nth",
marks=[
pytest.mark.notimpl(["bigquery", "pandas", "snowflake"]),
pytest.mark.notimpl(["pandas", "snowflake"]),
pytest.mark.notyet(["impala", "mssql"]),
pytest.mark.broken(
"bigquery",
strict=False,
reason="output types is float64 instead of the expected float32",
),
],
),
param(
Expand Down

0 comments on commit b43ba28

Please sign in to comment.