Skip to content

Commit

Permalink
feat(snowflake): implement TimestampFromUNIX
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Jan 19, 2023
1 parent 1eba8be commit 314637d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
7 changes: 5 additions & 2 deletions ibis/backends/snowflake/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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]
),
}
)

Expand All @@ -256,7 +260,6 @@ def _map(_, op):
# ibis.expr.operations.temporal
ops.IntervalFromInteger,
ops.TimestampDiff,
ops.TimestampFromUNIX,
}

operation_registry = {
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion ibis/expr/operations/temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 314637d

Please sign in to comment.