1
0
Fork 0

Merging upstream version 26.29.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-06-19 07:53:46 +02:00
parent 141a93f866
commit 4c1ec9be5a
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
58 changed files with 17605 additions and 17151 deletions

View file

@ -1580,3 +1580,40 @@ FROM READ_CSV('tests/fixtures/optimizer/tpc-h/nation.csv.gz', 'delimiter', '|')
self.assertTrue(annotated.selects[0].is_type("INT"))
self.assertTrue(annotated.selects[1].is_type("VARCHAR"))
def test_annotate_table_as_struct_bigquery(self):
dialect = "bigquery"
schema = {"d": {"s": {"t": {"c1": "int64", "c2": "struct<f1 int64, f2 string>"}}}}
def _annotate(query: str) -> exp.Expression:
expression = parse_one(example_query, dialect=dialect)
qual = optimizer.qualify.qualify(expression, schema=schema, dialect=dialect)
return optimizer.annotate_types.annotate_types(qual, schema=schema, dialect=dialect)
example_query = "SELECT t FROM d.s.t"
annotated = _annotate(example_query)
self.assertIsInstance(annotated.selects[0].this, exp.TableColumn)
self.assertEqual(
annotated.sql("bigquery"), "SELECT `t` AS `_col_0` FROM `d`.`s`.`t` AS `t`"
)
self.assertTrue(
annotated.selects[0].is_type("STRUCT<c1 BIGINT, c2 STRUCT<f1 BIGINT, f2 TEXT>>")
)
example_query = "SELECT subq FROM (SELECT * from d.s.t) subq"
annotated = _annotate(example_query)
self.assertTrue(
annotated.selects[0].is_type("STRUCT<c1 BIGINT, c2 STRUCT<f1 BIGINT, f2 TEXT>>")
)
example_query = "WITH t AS (SELECT 1 AS c) SELECT t FROM t"
annotated = _annotate(example_query)
self.assertTrue(annotated.selects[0].is_type("STRUCT<c INT>"))
example_query = "WITH t AS (SELECT FOO() AS c) SELECT t FROM t"
annotated = _annotate(example_query)
self.assertTrue(annotated.selects[0].is_type("UNKNOWN"))