Skip to content

Commit

Permalink
feat(trino): implement json getitem support
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud authored and kszucs committed Dec 21, 2022
1 parent 0c7d3b3 commit 7c41566
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pytest import param


@pytest.mark.notimpl(["bigquery", "datafusion", "pyspark", "mssql", "trino"])
@pytest.mark.notimpl(["bigquery", "datafusion", "pyspark", "mssql"])
@pytest.mark.notyet(["clickhouse"], reason="upstream is broken")
@pytest.mark.never(["impala"], reason="doesn't support JSON and never will")
@pytest.mark.parametrize(
Expand Down
8 changes: 8 additions & 0 deletions ibis/backends/trino/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ def _arbitrary(t, op):
return reduction(sa.func.arbitrary)(t, op)


def _json_get_item(t, op):
arg = t.translate(op.arg)
index = t.translate(op.index)
fmt = "%d" if op.index.output_dtype.is_integer() else '"%s"'
return sa.func.json_extract(arg, sa.func.format(f"$[{fmt}]", index))


operation_registry.update(
{
# conditional expressions
Expand All @@ -36,5 +43,6 @@ def _arbitrary(t, op):
ops.Covariance: _covar,
ops.ExtractMillisecond: unary(sa.func.millisecond),
ops.Arbitrary: _arbitrary,
ops.JSONGetItem: _json_get_item,
}
)

0 comments on commit 7c41566

Please sign in to comment.