Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(snowflake): implement correct semantics of EXCEPT, RENAME #2268

Merged
merged 13 commits into from
Sep 20, 2023
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"fallback_version": "0.0.0",
"local_scheme": "no-local-version",
},
setup_requires=["setuptools_scm"],
setup_requires=["setuptools_scm<8.0.1"],
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Temporary workaround - see pypa/setuptools-scm#912

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bugfix incoming in pypa/setuptools-scm#915

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks!

python_requires=">=3.7",
extras_require={
"dev": [
Expand Down
8 changes: 6 additions & 2 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4616,14 +4616,18 @@ def _parse_except(self) -> t.Optional[t.List[exp.Expression]]:
return None
if self._match(TokenType.L_PAREN, advance=False):
return self._parse_wrapped_csv(self._parse_column)
return self._parse_csv(self._parse_column)

except_column = self._parse_column()
return [except_column] if except_column else None

def _parse_replace(self) -> t.Optional[t.List[exp.Expression]]:
if not self._match(TokenType.REPLACE):
return None
if self._match(TokenType.L_PAREN, advance=False):
return self._parse_wrapped_csv(self._parse_expression)
return self._parse_expressions()

replace_expression = self._parse_expression()
return [replace_expression] if replace_expression else None

def _parse_csv(
self, parse_method: t.Callable, sep: TokenType = TokenType.COMMA
Expand Down
4 changes: 2 additions & 2 deletions tests/dialects/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,13 +279,13 @@ def test_snowflake(self):
self.validate_all(
"SELECT * EXCLUDE a, b FROM xxx",
write={
"snowflake": "SELECT * EXCLUDE (a, b) FROM xxx",
"snowflake": "SELECT * EXCLUDE (a), b FROM xxx",
},
)
self.validate_all(
"SELECT * RENAME a AS b, c AS d FROM xxx",
write={
"snowflake": "SELECT * RENAME (a AS b, c AS d) FROM xxx",
"snowflake": "SELECT * RENAME (a AS b), c AS d FROM xxx",
},
)
self.validate_all(
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/pretty.sql
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,8 @@ CROSS JOIN UNNEST(fruit_basket) WITH ORDINALITY AS fruit(basket_index);
SELECT A.* EXCEPT A.COL_1, A.COL_2 FROM TABLE_1 A;
SELECT
A.*
EXCEPT (A.COL_1, A.COL_2)
EXCEPT (A.COL_1),
A.COL_2
FROM TABLE_1 AS A;

SELECT *
Expand Down