Skip to content

Commit

Permalink
feat(bigquery): implement struct literal
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-kwitt authored and cpcloud committed Jan 24, 2023
1 parent 765d42e commit c5f2a1d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ibis/backends/bigquery/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ def _literal(translator, op):
return "FROM_BASE64('{}')".format(
base64.b64encode(value).decode(encoding="utf-8")
)
elif dtype.is_struct():
cols = (
f'{translator.translate(ops.Literal(op.value[name], dtype=type_))} AS {name}'
for name, type_ in zip(dtype.names, dtype.types)
)
return "STRUCT({})".format(", ".join(cols))

try:
return literal(translator, op)
Expand Down
2 changes: 1 addition & 1 deletion ibis/backends/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def test_all_fields(struct, struct_df):
_NULL_STRUCT_LITERAL = ibis.NA.cast("struct<a: int64, b: string, c: float64>")


@pytest.mark.notimpl(["postgres", "bigquery"])
@pytest.mark.notimpl(["postgres"])
@pytest.mark.parametrize("field", ["a", "b", "c"])
def test_literal(con, field):
query = _STRUCT_LITERAL[field]
Expand Down

0 comments on commit c5f2a1d

Please sign in to comment.