From 314637decd913003767119defc8ce95909189fdc Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Tue, 17 Jan 2023 18:12:14 -0500 Subject: [PATCH] feat(snowflake): implement `TimestampFromUNIX` --- ibis/backends/snowflake/registry.py | 7 +++++-- ibis/backends/tests/test_temporal.py | 2 +- ibis/expr/operations/temporal.py | 1 - 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ibis/backends/snowflake/registry.py b/ibis/backends/snowflake/registry.py index afec3990ce4b..5da658dcaacc 100644 --- a/ibis/backends/snowflake/registry.py +++ b/ibis/backends/snowflake/registry.py @@ -95,7 +95,6 @@ def _extract_url_query(t, op): return sa.func.nullif(sa.func.as_varchar(r), "") -<<<<<<< HEAD def _array_slice(t, op): arg = t.translate(op.arg) @@ -124,6 +123,8 @@ def _map(_, op): ) +_TIMESTAMP_UNITS_TO_SCALE = {"s": 0, "ms": 3, "us": 6, "ns": 9} + _SF_POS_INF = sa.func.to_double("Inf") _SF_NEG_INF = sa.func.to_double("-Inf") _SF_NAN = sa.func.to_double("NaN") @@ -234,6 +235,9 @@ def _map(_, op): 1, ), ops.TimestampFromYMDHMS: fixed_arity(sa.func.timestamp_from_parts, 6), + ops.TimestampFromUNIX: lambda t, op: sa.func.to_timestamp( + t.translate(op.arg), _TIMESTAMP_UNITS_TO_SCALE[op.unit] + ), } ) @@ -256,7 +260,6 @@ def _map(_, op): # ibis.expr.operations.temporal ops.IntervalFromInteger, ops.TimestampDiff, - ops.TimestampFromUNIX, } operation_registry = { diff --git a/ibis/backends/tests/test_temporal.py b/ibis/backends/tests/test_temporal.py index 355786cd48fe..8436af7064b4 100644 --- a/ibis/backends/tests/test_temporal.py +++ b/ibis/backends/tests/test_temporal.py @@ -605,7 +605,7 @@ def test_strftime(backend, alltypes, df, expr_fn, pandas_pattern): ), ], ) -@pytest.mark.notimpl(["datafusion", "mysql", "postgres", "sqlite", "snowflake"]) +@pytest.mark.notimpl(["datafusion", "mysql", "postgres", "sqlite"]) def test_integer_to_timestamp(backend, con, unit): backend_unit = backend.returned_timestamp_unit factor = unit_factors[unit] diff --git a/ibis/expr/operations/temporal.py b/ibis/expr/operations/temporal.py index a915c94dd534..5d7e0a561242 100644 --- a/ibis/expr/operations/temporal.py +++ b/ibis/expr/operations/temporal.py @@ -254,7 +254,6 @@ class TimestampFromYMDHMS(Value): @public class TimestampFromUNIX(Value): arg = rlz.any - # Only pandas-based backends support 'ns' unit = rlz.isin({'s', 'ms', 'us', 'ns'}) output_dtype = dt.timestamp