Skip to content

Commit

Permalink
feat(duckdb): implement ops.TimestampDiff, ops.IntervalAdd, ops.Inter…
Browse files Browse the repository at this point in the history
…valSubtract
  • Loading branch information
krzysztof-kwitt authored and cpcloud committed Jan 28, 2023
1 parent b5c32fe commit a7fd8fb
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 3 additions & 4 deletions ibis/backends/duckdb/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _literal(t, op):
value = op.value

if dtype.is_interval():
return sa.text(f"INTERVAL '{value} {dtype.resolution}'")
return sa.literal_column(f"INTERVAL '{value} {dtype.resolution}'")
elif dtype.is_set() or (
isinstance(value, collections.abc.Sequence) and not isinstance(value, str)
):
Expand Down Expand Up @@ -220,7 +220,6 @@ def _struct_column(t, op):
)
),
ops.TableColumn: _table_column,
ops.TimestampDiff: fixed_arity(sa.func.age, 2),
ops.TimestampFromUNIX: _timestamp_from_unix,
ops.TimestampNow: fixed_arity(
# duckdb 0.6.0 changes now to be a tiemstamp with time zone force
Expand Down Expand Up @@ -253,6 +252,8 @@ def _struct_column(t, op):
ops.Quantile: reduction(sa.func.quantile_cont),
ops.MultiQuantile: reduction(sa.func.quantile_cont),
ops.TypeOf: unary(sa.func.typeof),
ops.IntervalAdd: fixed_arity(operator.add, 2),
ops.IntervalSubtract: fixed_arity(operator.sub, 2),
}
)

Expand All @@ -266,8 +267,6 @@ def _struct_column(t, op):
# ibis.expr.operations.strings
ops.Capitalize,
ops.Translate,
# ibis.expr.operations.temporal
ops.TimestampDiff,
# ibis.expr.operations.maps
ops.MapGet,
ops.MapContains,
Expand Down
3 changes: 1 addition & 2 deletions ibis/backends/tests/test_temporal.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ def convert_to_offset(x):
"bigquery",
"clickhouse",
"dask",
"duckdb",
"impala",
"mysql",
"pandas",
Expand Down Expand Up @@ -393,7 +392,7 @@ def convert_to_offset(x):
)
).dt.floor("s"),
id='timestamp-subtract-timestamp',
marks=pytest.mark.notimpl(["bigquery", "duckdb", "pyspark", "snowflake"]),
marks=pytest.mark.notimpl(["bigquery", "pyspark", "snowflake"]),
),
param(
lambda t, _: t.timestamp_col.date() - ibis.date(date_value),
Expand Down

0 comments on commit a7fd8fb

Please sign in to comment.