Skip to content

Commit

Permalink
feat(snowflake): implement scalar
Browse files Browse the repository at this point in the history
  • Loading branch information
mik-laj authored and cpcloud committed Nov 11, 2022
1 parent 409f497 commit cc07d91
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions ibis/backends/snowflake/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def _round(t, op):
return sa.func.round(*args)


def _random(t, op):
min_value = sa.cast(0, sa.dialects.postgresql.FLOAT())
max_value = sa.cast(1, sa.dialects.postgresql.FLOAT())
return sa.func.uniform(min_value, max_value, sa.func.random())


_SF_POS_INF = sa.cast(sa.literal("Inf"), sa.FLOAT)
_SF_NEG_INF = -_SF_POS_INF
_SF_NAN = sa.cast(sa.literal("NaN"), sa.FLOAT)
Expand All @@ -59,5 +65,7 @@ def _round(t, op):
ops.Round: _round,
ops.Modulus: fixed_arity(sa.func.mod, 2),
ops.Mode: reduction(sa.func.mode),
# numbers
ops.RandomScalar: _random,
}
)
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def test_sa_default_numeric_precision_and_scale(

@pytest.mark.notimpl(["dask", "datafusion", "impala", "pandas", "sqlite", "polars"])
@pytest.mark.notyet(
["clickhouse", "snowflake"],
["clickhouse"],
reason="backend doesn't implement a [0.0, 1.0) random function",
)
def test_random(con):
Expand Down

0 comments on commit cc07d91

Please sign in to comment.