Skip to content

Commit c5f2a1d

Browse files
krzysztof-kwittcpcloud
authored andcommitted
feat(bigquery): implement struct literal
1 parent 765d42e commit c5f2a1d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

ibis/backends/bigquery/registry.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,12 @@ def _literal(translator, op):
239239
return "FROM_BASE64('{}')".format(
240240
base64.b64encode(value).decode(encoding="utf-8")
241241
)
242+
elif dtype.is_struct():
243+
cols = (
244+
f'{translator.translate(ops.Literal(op.value[name], dtype=type_))} AS {name}'
245+
for name, type_ in zip(dtype.names, dtype.types)
246+
)
247+
return "STRUCT({})".format(", ".join(cols))
242248

243249
try:
244250
return literal(translator, op)

ibis/backends/tests/test_struct.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_all_fields(struct, struct_df):
5151
_NULL_STRUCT_LITERAL = ibis.NA.cast("struct<a: int64, b: string, c: float64>")
5252

5353

54-
@pytest.mark.notimpl(["postgres", "bigquery"])
54+
@pytest.mark.notimpl(["postgres"])
5555
@pytest.mark.parametrize("field", ["a", "b", "c"])
5656
def test_literal(con, field):
5757
query = _STRUCT_LITERAL[field]

0 commit comments

Comments
 (0)