Skip to content

Commit

Permalink
Fix(snowflake): implement correct semantics of EXCEPT, RENAME (#2268)
Browse files Browse the repository at this point in the history
* Fix(snowflake): implement correct semantics of EXCEPT, RENAME

* Constrain setuptools_scm version to be <8.0.1 for now

* Revert setuptools_scm version constraint, first attempt at ignoring _version.py in mypy

* Second attempt at excluding _version.py

* Third attempt at excluding _version.py

* Fourth attempt...

* Sigh.

* try pre-commit exclude flag

* Add sqlglot/ prefix

* Another try

* ...

* Try non-stringified sqlglot/_version.py

* Constraint setuptools_scm in setup_requires instead...
  • Loading branch information
georgesittas authored Sep 20, 2023
1 parent bca7570 commit d5b229a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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"],
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

0 comments on commit d5b229a

Please sign in to comment.