Skip to content

Commit

Permalink
fix(duckdb): add casts to literals to fix binding errors
Browse files Browse the repository at this point in the history
Fixes #3629
  • Loading branch information
gforsyth authored and cpcloud committed Mar 22, 2022
1 parent a4f2cbf commit 1977a55
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ibis/backends/duckdb/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _literal(_, expr):
f"`{type(value).__name__}` isn't yet supported with the duckdb "
"backend"
)
return sa.literal(value)
return sa.cast(sa.literal(value), sqla_type)


def _array_column(t, expr):
Expand Down
11 changes: 11 additions & 0 deletions ibis/backends/tests/test_aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,3 +461,14 @@ def collect_udf(v):
)

backend.assert_frame_equal(result, expected, check_like=True)


@pytest.mark.notimpl(["datafusion", "pyspark"])
def test_binds_are_cast(alltypes):
expr = alltypes.aggregate(
high_line_count=(
alltypes.string_col.case().when('1-URGENT', 1).else_(0).end().sum()
)
)

expr.execute()
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_coalesce(backend, con, expr, expected):
# False
assert result == decimal.Decimal(str(expected))
else:
assert result == expected
assert result == pytest.approx(expected)


# TODO(dask) - identicalTo - #2553
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 @@ -362,7 +362,7 @@ def convert_to_offset(x):
lambda t, be: t.timestamp_col.date() - ibis.date(date_value),
lambda t, be: t.timestamp_col.dt.floor('d') - date_value,
id='date-subtract-date',
marks=pytest.mark.notimpl(["duckdb", 'pyspark']),
marks=pytest.mark.notimpl(["pyspark"]),
),
],
)
Expand Down

0 comments on commit 1977a55

Please sign in to comment.