Skip to content

Commit a63cee9

Browse files
cpcloudjcrist
authored andcommitted
feat(datafusion): struct literals
1 parent 2330b0c commit a63cee9

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

ibis/backends/sql/compilers/datafusion.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ def visit_NonNullLiteral(self, op, *, value, dtype):
122122
return sg.exp.HexString(this=value.hex())
123123
elif dtype.is_uuid():
124124
return sge.convert(str(value))
125+
elif dtype.is_struct():
126+
args = []
127+
for name, field_value in value.items():
128+
args.append(sge.convert(name))
129+
args.append(field_value)
130+
return self.f.named_struct(*args)
125131
else:
126132
return None
127133

ibis/backends/tests/test_struct.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
pytestmark = [
2525
pytest.mark.never(["mysql", "sqlite", "mssql"], reason="No struct support"),
2626
pytest.mark.notyet(["impala"]),
27-
pytest.mark.notimpl(["datafusion", "druid", "oracle", "exasol"]),
27+
pytest.mark.notimpl(["druid", "oracle", "exasol"]),
2828
]
2929

3030

@@ -76,6 +76,7 @@ def test_all_fields(struct, struct_df):
7676

7777

7878
@pytest.mark.notimpl(["postgres", "risingwave"])
79+
@pytest.mark.notyet(["datafusion"], raises=Exception, reason="unsupported syntax")
7980
@pytest.mark.parametrize("field", ["a", "b", "c"])
8081
def test_literal(backend, con, field):
8182
query = _STRUCT_LITERAL[field]
@@ -87,6 +88,7 @@ def test_literal(backend, con, field):
8788

8889

8990
@pytest.mark.notimpl(["postgres"])
91+
@pytest.mark.notyet(["datafusion"], raises=Exception, reason="unsupported syntax")
9092
@pytest.mark.parametrize("field", ["a", "b", "c"])
9193
@pytest.mark.notyet(
9294
["clickhouse"], reason="clickhouse doesn't support nullable nested types"
@@ -112,6 +114,7 @@ def test_struct_column(alltypes, df):
112114

113115

114116
@pytest.mark.notimpl(["postgres", "risingwave", "polars"])
117+
@pytest.mark.notyet(["datafusion"], raises=Exception, reason="unsupported syntax")
115118
@pytest.mark.notyet(
116119
["flink"], reason="flink doesn't support creating struct columns from collect"
117120
)
@@ -144,6 +147,7 @@ def test_collect_into_struct(alltypes):
144147
reason="struct literals not implemented",
145148
raises=PsycoPg2InternalError,
146149
)
150+
@pytest.mark.notyet(["datafusion"], raises=Exception, reason="unsupported syntax")
147151
@pytest.mark.notimpl(["flink"], raises=Py4JJavaError, reason="not implemented in ibis")
148152
def test_field_access_after_case(con):
149153
s = ibis.struct({"a": 3})
@@ -201,6 +205,7 @@ def test_field_access_after_case(con):
201205
raises=AssertionError,
202206
reason="snowflake doesn't have strongly typed structs",
203207
)
208+
@pytest.mark.notyet(["datafusion"], raises=Exception, reason="unsupported syntax")
204209
def test_keyword_fields(con, nullable):
205210
schema = ibis.schema(
206211
{
@@ -260,6 +265,7 @@ def test_keyword_fields(con, nullable):
260265
raises=Py4JJavaError,
261266
reason="fails to parse due to an unsupported operation; flink docs say the syntax is supported",
262267
)
268+
@pytest.mark.notyet(["datafusion"], raises=Exception, reason="unsupported syntax")
263269
def test_isin_struct(con):
264270
needle1 = ibis.struct({"x": 1, "y": 2})
265271
needle2 = ibis.struct({"x": 2, "y": 3})

0 commit comments

Comments
 (0)