Skip to content

Commit

Permalink
Chore: parser accepts ctes without as keyword again, except for click…
Browse files Browse the repository at this point in the history
…house (#4612)
  • Loading branch information
georgesittas authored Jan 14, 2025
1 parent 21df3c6 commit b447322
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
1 change: 1 addition & 0 deletions sqlglot/dialects/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ class Parser(parser.Parser):
# * select x from t1 union all (select x from t2 limit 1);
MODIFIERS_ATTACHED_TO_SET_OP = False
INTERVAL_SPANS = False
OPTIONAL_ALIAS_TOKEN_CTE = False

FUNCTIONS = {
**parser.Parser.FUNCTIONS,
Expand Down
2 changes: 0 additions & 2 deletions sqlglot/dialects/spark.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ class Tokenizer(Spark2.Tokenizer):
]

class Parser(Spark2.Parser):
OPTIONAL_ALIAS_TOKEN_CTE = True

FUNCTIONS = {
**Spark2.Parser.FUNCTIONS,
"ANY_VALUE": _build_with_ignore_nulls(exp.AnyValue),
Expand Down
2 changes: 1 addition & 1 deletion sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ class Parser(metaclass=_Parser):
WRAPPED_TRANSFORM_COLUMN_CONSTRAINT = True

# Whether the 'AS' keyword is optional in the CTE definition syntax
OPTIONAL_ALIAS_TOKEN_CTE = False
OPTIONAL_ALIAS_TOKEN_CTE = True

__slots__ = (
"error_level",
Expand Down
4 changes: 4 additions & 0 deletions tests/dialects/test_snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def test_snowflake(self):
self.validate_identity(
"SELECT * FROM DATA AS DATA_L ASOF JOIN DATA AS DATA_R MATCH_CONDITION (DATA_L.VAL > DATA_R.VAL) ON DATA_L.ID = DATA_R.ID"
)
self.validate_identity(
"WITH t (SELECT 1 AS c) SELECT c FROM t",
"WITH t AS (SELECT 1 AS c) SELECT c FROM t",
)
self.validate_identity(
"GET_PATH(json_data, '$id')",
"""GET_PATH(json_data, '["$id"]')""",
Expand Down

0 comments on commit b447322

Please sign in to comment.