pypika icon indicating copy to clipboard operation
pypika copied to clipboard

Implement STRUCT with optional field names

Open anhqle opened this issue 3 years ago • 1 comments

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:

  1. Do you suggest a different API to specify field_names? Perhaps next to the value itself?
  2. Even though #591 mentions BigQuery, but I think STRUCT is ANSI SQL. I'm open to moving STRUCT to inside BigQuery dialect.

anhqle avatar Oct 07 '21 04:10 anhqle

Coverage Status

Coverage decreased (-0.01%) to 98.409% when pulling 60c8d0872c2c05e36afea2963b91dacf5eabe2d0 on anhqle:implement-struct2 into a7b01dac790f4c6e93a961b0be26a9645fe7cf5c on kayak:master.

coveralls avatar Oct 07 '21 04:10 coveralls