summaryrefslogtreecommitdiffstats
path: root/sqlglot/parser.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-10 08:53:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-10-10 08:53:14 +0000
commitcd37a3bcaced9283c20baa52837c96b524baec54 (patch)
tree101b1c1487aa832a982dd635cd3b00d4d2ea3ae9 /sqlglot/parser.py
parentReleasing progress-linux version 18.11.2-1. (diff)
downloadsqlglot-cd37a3bcaced9283c20baa52837c96b524baec54.tar.xz
sqlglot-cd37a3bcaced9283c20baa52837c96b524baec54.zip
Merging upstream version 18.11.6.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/parser.py')
-rw-r--r--sqlglot/parser.py39
1 files changed, 37 insertions, 2 deletions
diff --git a/sqlglot/parser.py b/sqlglot/parser.py
index 5e56961..510abfb 100644
--- a/sqlglot/parser.py
+++ b/sqlglot/parser.py
@@ -236,6 +236,7 @@ class Parser(metaclass=_Parser):
TokenType.SCHEMA,
TokenType.TABLE,
TokenType.VIEW,
+ TokenType.MODEL,
TokenType.DICTIONARY,
}
@@ -649,6 +650,7 @@ class Parser(metaclass=_Parser):
"IMMUTABLE": lambda self: self.expression(
exp.StabilityProperty, this=exp.Literal.string("IMMUTABLE")
),
+ "INPUT": lambda self: self.expression(exp.InputModelProperty, this=self._parse_schema()),
"JOURNAL": lambda self, **kwargs: self._parse_journal(**kwargs),
"LANGUAGE": lambda self: self._parse_property_assignment(exp.LanguageProperty),
"LAYOUT": lambda self: self._parse_dict_property(this="LAYOUT"),
@@ -664,11 +666,13 @@ class Parser(metaclass=_Parser):
"NO": lambda self: self._parse_no_property(),
"ON": lambda self: self._parse_on_property(),
"ORDER BY": lambda self: self._parse_order(skip_order_token=True),
+ "OUTPUT": lambda self: self.expression(exp.OutputModelProperty, this=self._parse_schema()),
"PARTITION BY": lambda self: self._parse_partitioned_by(),
"PARTITIONED BY": lambda self: self._parse_partitioned_by(),
"PARTITIONED_BY": lambda self: self._parse_partitioned_by(),
"PRIMARY KEY": lambda self: self._parse_primary_key(in_props=True),
"RANGE": lambda self: self._parse_dict_range(this="RANGE"),
+ "REMOTE": lambda self: self._parse_remote_with_connection(),
"RETURNS": lambda self: self._parse_returns(),
"ROW": lambda self: self._parse_row(),
"ROW_FORMAT": lambda self: self._parse_property_assignment(exp.RowFormatProperty),
@@ -690,6 +694,9 @@ class Parser(metaclass=_Parser):
"TEMPORARY": lambda self: self.expression(exp.TemporaryProperty),
"TO": lambda self: self._parse_to_table(),
"TRANSIENT": lambda self: self.expression(exp.TransientProperty),
+ "TRANSFORM": lambda self: self.expression(
+ exp.TransformModelProperty, expressions=self._parse_wrapped_csv(self._parse_expression)
+ ),
"TTL": lambda self: self._parse_ttl(),
"USING": lambda self: self._parse_property_assignment(exp.FileFormatProperty),
"VOLATILE": lambda self: self._parse_volatile_property(),
@@ -789,6 +796,7 @@ class Parser(metaclass=_Parser):
"MATCH": lambda self: self._parse_match_against(),
"OPENJSON": lambda self: self._parse_open_json(),
"POSITION": lambda self: self._parse_position(),
+ "PREDICT": lambda self: self._parse_predict(),
"SAFE_CAST": lambda self: self._parse_cast(False),
"STRING_AGG": lambda self: self._parse_string_agg(),
"SUBSTRING": lambda self: self._parse_substring(),
@@ -1787,6 +1795,12 @@ class Parser(metaclass=_Parser):
exp.CharacterSetProperty, this=self._parse_var_or_string(), default=default
)
+ def _parse_remote_with_connection(self) -> exp.RemoteWithConnectionModelProperty:
+ self._match_text_seq("WITH", "CONNECTION")
+ return self.expression(
+ exp.RemoteWithConnectionModelProperty, this=self._parse_table_parts()
+ )
+
def _parse_returns(self) -> exp.ReturnsProperty:
value: t.Optional[exp.Expression]
is_table = self._match(TokenType.TABLE)
@@ -2622,7 +2636,9 @@ class Parser(metaclass=_Parser):
bracket = parse_bracket and self._parse_bracket(None)
bracket = self.expression(exp.Table, this=bracket) if bracket else None
- this: exp.Expression = bracket or self._parse_table_parts(schema=schema)
+ this = t.cast(
+ exp.Expression, bracket or self._parse_bracket(self._parse_table_parts(schema=schema))
+ )
if schema:
return self._parse_schema(this=this)
@@ -2639,6 +2655,9 @@ class Parser(metaclass=_Parser):
if alias:
this.set("alias", alias)
+ if self._match_text_seq("AT"):
+ this.set("index", self._parse_id_var())
+
this.set("hints", self._parse_table_hints())
if not this.args.get("pivots"):
@@ -3886,7 +3905,9 @@ class Parser(metaclass=_Parser):
def _parse_unnamed_constraint(
self, constraints: t.Optional[t.Collection[str]] = None
) -> t.Optional[exp.Expression]:
- if not self._match_texts(constraints or self.CONSTRAINT_PARSERS):
+ if self._match(TokenType.IDENTIFIER, advance=False) or not self._match_texts(
+ constraints or self.CONSTRAINT_PARSERS
+ ):
return None
constraint = self._prev.text.upper()
@@ -4402,6 +4423,20 @@ class Parser(metaclass=_Parser):
exp.StrPosition, this=haystack, substr=needle, position=seq_get(args, 2)
)
+ def _parse_predict(self) -> exp.Predict:
+ self._match_text_seq("MODEL")
+ this = self._parse_table()
+
+ self._match(TokenType.COMMA)
+ self._match_text_seq("TABLE")
+
+ return self.expression(
+ exp.Predict,
+ this=this,
+ expression=self._parse_table(),
+ params_struct=self._match(TokenType.COMMA) and self._parse_bitwise(),
+ )
+
def _parse_join_hint(self, func_name: str) -> exp.JoinHint:
args = self._parse_csv(self._parse_table)
return exp.JoinHint(this=func_name.upper(), expressions=args)