Skip to content

Commit

Permalink
feat(duckdb): implement partial json collection casting
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Oct 11, 2023
1 parent 652ceab commit aae28e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 7 additions & 3 deletions ibis/backends/duckdb/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,11 @@ def _try_cast(t, op):
)


def _to_json_collection(t, op):
typ = t.get_sqla_type(op.dtype)
return try_cast(t.translate(op.arg), typ, type_=typ)


operation_registry.update(
{
ops.ArrayColumn: (
Expand Down Expand Up @@ -477,6 +482,8 @@ def _try_cast(t, op):
ops.TimeDelta: _temporal_delta,
ops.DateDelta: _temporal_delta,
ops.TimestampDelta: _temporal_delta,
ops.ToJSONMap: _to_json_collection,
ops.ToJSONArray: _to_json_collection,
}
)

Expand All @@ -486,9 +493,6 @@ def _try_cast(t, op):
ops.NTile,
# ibis.expr.operations.strings
ops.Translate,
# ibis.expr.operations.json
ops.ToJSONMap,
ops.ToJSONArray,
}

operation_registry = {
Expand Down
4 changes: 0 additions & 4 deletions ibis/backends/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
from packaging.version import parse as vparse
from pytest import param

from ibis.common.exceptions import OperationNotDefinedError

pytestmark = [
pytest.mark.never(["impala"], reason="doesn't support JSON and never will"),
pytest.mark.notyet(["clickhouse"], reason="upstream is broken"),
Expand Down Expand Up @@ -50,7 +48,6 @@ def test_json_getitem(json_t, expr_fn, expected):
@pytest.mark.notyet(
["pyspark", "trino"], reason="should work but doesn't deserialize JSON"
)
@pytest.mark.notimpl(["duckdb"], raises=OperationNotDefinedError)
def test_json_map(json_t):
expr = json_t.js.map.name("res")
result = expr.execute()
Expand All @@ -75,7 +72,6 @@ def test_json_map(json_t):
["pyspark", "trino"], reason="should work but doesn't deserialize JSON"
)
@pytest.mark.notyet(["bigquery"], reason="doesn't allow null in arrays")
@pytest.mark.notimpl(["duckdb"], raises=OperationNotDefinedError)
def test_json_array(json_t):
expr = json_t.js.array.name("res")
result = expr.execute()
Expand Down

0 comments on commit aae28e9

Please sign in to comment.