From 035f856f76235cc1059d16d37b8ec889fc2975bd Mon Sep 17 00:00:00 2001 From: Phillip Cloud <417981+cpcloud@users.noreply.github.com> Date: Mon, 16 Jan 2023 07:30:49 -0500 Subject: [PATCH] feat(snowflake): date from ymd --- ibis/backends/snowflake/registry.py | 2 +- ibis/backends/tests/test_param.py | 28 +++++++++++++--------------- ibis/backends/tests/test_temporal.py | 13 ++----------- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/ibis/backends/snowflake/registry.py b/ibis/backends/snowflake/registry.py index 93b0d8d945f6..77ca1d0707a9 100644 --- a/ibis/backends/snowflake/registry.py +++ b/ibis/backends/snowflake/registry.py @@ -224,6 +224,7 @@ def _map(_, op): ops.BitAnd: reduction(sa.func.bitand_agg), ops.BitOr: reduction(sa.func.bitor_agg), ops.BitXor: reduction(sa.func.bitxor_agg), + ops.DateFromYMD: fixed_arity(sa.func.date_from_parts, 3), } ) @@ -247,7 +248,6 @@ def _map(_, op): # ibis.expr.operations.structs ops.StructField, # ibis.expr.operations.temporal - ops.DateFromYMD, ops.ExtractMillisecond, ops.IntervalFromInteger, ops.StringToTimestamp, diff --git a/ibis/backends/tests/test_param.py b/ibis/backends/tests/test_param.py index c91e9bd62c7a..85bdf5f5f8f0 100644 --- a/ibis/backends/tests/test_param.py +++ b/ibis/backends/tests/test_param.py @@ -135,26 +135,24 @@ def test_scalar_param(alltypes, df, value, dtype, col): @pytest.mark.parametrize( - ("value", "dtype"), - [ - param("2009-01-20", "date", id="string_date"), - param(datetime.date(2009, 1, 20), "date", id="date_date"), - param(datetime.datetime(2009, 1, 20), "date", id="datetime_date"), - ], -) -@pytest.mark.notimpl( - ["mysql", "polars", "dask", "datafusion", "sqlite", "impala", "mssql"] + "value", + ["2009-01-20", datetime.date(2009, 1, 20), datetime.datetime(2009, 1, 20)], + ids=["string", "date", "datetime"], ) -def test_scalar_param_date(backend, alltypes, value, dtype): - param = ibis.param(dtype) - ds_col = alltypes.date_string_col.split("/") - month, day, year = ds_col[0], ds_col[1], ds_col[2] - date_col = ibis.literal("-").join(["20" + year, month, day]).cast(dtype) +@pytest.mark.notimpl(["datafusion"]) +@pytest.mark.notyet(["impala"], reason="impala doesn't support dates") +def test_scalar_param_date(backend, alltypes, value): + param = ibis.param("date") + ds_col = alltypes.date_string_col + month = ds_col[:2] + day = ds_col[3:5] + year = "20" + ds_col[6:8] + date_col = (year + "-" + month + "-" + day).cast(param.type()) base = alltypes.mutate(date_col=date_col) expr = ( alltypes.mutate(date_col=date_col) - .filter([lambda t: t.date_col == param]) + .filter(lambda t: t.date_col == param) .drop("date_col") ) diff --git a/ibis/backends/tests/test_temporal.py b/ibis/backends/tests/test_temporal.py index be9db1062460..928087b58636 100644 --- a/ibis/backends/tests/test_temporal.py +++ b/ibis/backends/tests/test_temporal.py @@ -779,7 +779,7 @@ def test_now_from_projection(alltypes): tm.assert_series_equal(ts.dt.year, year_expected) -@pytest.mark.notimpl(["pandas", "datafusion", "mysql", "dask", "pyspark", "snowflake"]) +@pytest.mark.notimpl(["pandas", "datafusion", "mysql", "dask", "pyspark"]) @pytest.mark.notyet(["clickhouse", "impala"]) def test_date_literal(con): expr = ibis.date(2022, 2, 4) @@ -816,16 +816,7 @@ def test_time_literal(con): assert str(result) == '16:20:00' -@pytest.mark.notimpl( - [ - "pandas", - "datafusion", - "mysql", - "dask", - "pyspark", - "snowflake", - ] -) +@pytest.mark.notimpl(["pandas", "datafusion", "mysql", "dask", "pyspark"]) @pytest.mark.notyet(["clickhouse", "impala"]) def test_date_column_from_ymd(con, alltypes, df): c = alltypes.timestamp_col