pypika
pypika copied to clipboard
Implement STRUCT with optional field names
This PR implements the ability to create STRUCT with optional field names, i.e. STRUCT(expr1 [AS field_name] [, ... ])
. Does not implement typed STRUCT, e.g. STRUCT<INT64>
. Partially resolve #591.
Examples (included as unit tests):
Query.from_(Table('abc')).select(Struct(1, "a", ["b", 2, 3]))
>>> SELECT STRUCT(1,'a',['b',2,3]) FROM "abc"
Query.from_(Table('abc')).select(Struct(1, "a", ["b", 2, 3], field_names=["col1", "col2", "col3"]))
>>> SELECT STRUCT(1 AS col1,'a' AS col2,['b',2,3] AS col3) FROM "abc"
Discussion points:
- Do you suggest a different API to specify
field_names
? Perhaps next to the value itself? - Even though #591 mentions BigQuery, but I think STRUCT is ANSI SQL. I'm open to moving STRUCT to inside BigQuery dialect.