diff --git a/sqlglot/parsers/starrocks.py b/sqlglot/parsers/starrocks.py index 7190e40533..1ba30f1c4c 100644 --- a/sqlglot/parsers/starrocks.py +++ b/sqlglot/parsers/starrocks.py @@ -130,13 +130,12 @@ def _parse_unnest(self, with_alias: bool = True) -> exp.Unnest | None: if not alias: # Starrocks defaults to naming the table alias as "unnest" - alias = exp.TableAlias( - this=exp.to_identifier("unnest"), columns=[exp.to_identifier("unnest")] - ) + alias = exp.TableAlias(this=exp.to_identifier("unnest")) unnest.set("alias", alias) - elif not alias.args.get("columns"): - # Starrocks defaults to naming the UNNEST column as "unnest" - # if it's not otherwise specified + + # Starrocks defaults to naming the UNNEST column as "unnest" if it's not otherwise + # specified. With several arrays every column is named "unnest", so none is added. + if not alias.args.get("columns") and len(unnest.expressions) == 1: alias.set("columns", [exp.to_identifier("unnest")]) return unnest diff --git a/tests/dialects/test_starrocks.py b/tests/dialects/test_starrocks.py index 3f8063aeae..b39f78d486 100644 --- a/tests/dialects/test_starrocks.py +++ b/tests/dialects/test_starrocks.py @@ -408,6 +408,15 @@ def test_unnest(self): }, ) + # Every column of a multi-array UNNEST is named "unnest", so no column alias is added + self.validate_identity( + "SELECT * FROM (SELECT 1 AS id) AS s, UNNEST([1, 2], ['a', 'b'])", + "SELECT * FROM (SELECT 1 AS id) AS s, UNNEST([1, 2], ['a', 'b']) AS unnest", + ) + self.validate_identity( + "SELECT * FROM (SELECT 1 AS id) AS s, UNNEST([1, 2], ['a', 'b']) AS t" + ) + def test_ignore_respect_nulls(self): for func in ("FIRST_VALUE", "LAST_VALUE", "LAG", "LEAD"): with self.subTest(func=func):