Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions sqlglot/parsers/starrocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions tests/dialects/test_starrocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Loading