diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-02-12 06:15:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-02-12 06:15:14 +0000 |
commit | 8fd7374bf370b99577a40d4de1716ad990d5a34b (patch) | |
tree | 061ecaf38b8a390a8a70348eea1fd11233f9e19c /sqlglot/parser.py | |
parent | Adding upstream version 21.0.1. (diff) | |
download | sqlglot-8fd7374bf370b99577a40d4de1716ad990d5a34b.tar.xz sqlglot-8fd7374bf370b99577a40d4de1716ad990d5a34b.zip |
Adding upstream version 21.0.2.upstream/21.0.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sqlglot/parser.py')
-rw-r--r-- | sqlglot/parser.py | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/sqlglot/parser.py b/sqlglot/parser.py index a89e4fa..dfa3024 100644 --- a/sqlglot/parser.py +++ b/sqlglot/parser.py @@ -872,7 +872,6 @@ class Parser(metaclass=_Parser): FUNCTIONS_WITH_ALIASED_ARGS = {"STRUCT"} FUNCTION_PARSERS = { - "ANY_VALUE": lambda self: self._parse_any_value(), "CAST": lambda self: self._parse_cast(self.STRICT_CAST), "CONVERT": lambda self: self._parse_convert(self.STRICT_CAST), "DECODE": lambda self: self._parse_decode(), @@ -2465,8 +2464,14 @@ class Parser(metaclass=_Parser): this.set(key, expression) if key == "limit": offset = expression.args.pop("offset", None) + if offset: - this.set("offset", exp.Offset(expression=offset)) + offset = exp.Offset(expression=offset) + this.set("offset", offset) + + limit_by_expressions = expression.expressions + expression.set("expressions", None) + offset.set("expressions", limit_by_expressions) continue break return this @@ -3341,7 +3346,12 @@ class Parser(metaclass=_Parser): offset = None limit_exp = self.expression( - exp.Limit, this=this, expression=expression, offset=offset, comments=comments + exp.Limit, + this=this, + expression=expression, + offset=offset, + comments=comments, + expressions=self._parse_limit_by(), ) return limit_exp @@ -3377,7 +3387,13 @@ class Parser(metaclass=_Parser): count = self._parse_term() self._match_set((TokenType.ROW, TokenType.ROWS)) - return self.expression(exp.Offset, this=this, expression=count) + + return self.expression( + exp.Offset, this=this, expression=count, expressions=self._parse_limit_by() + ) + + def _parse_limit_by(self) -> t.Optional[t.List[exp.Expression]]: + return self._match_text_seq("BY") and self._parse_csv(self._parse_bitwise) def _parse_locks(self) -> t.List[exp.Lock]: locks = [] @@ -4115,7 +4131,9 @@ class Parser(metaclass=_Parser): else: this = self._parse_select_or_expression(alias=alias) - return self._parse_limit(self._parse_order(self._parse_respect_or_ignore_nulls(this))) + return self._parse_limit( + self._parse_order(self._parse_having_max(self._parse_respect_or_ignore_nulls(this))) + ) def _parse_schema(self, this: t.Optional[exp.Expression] = None) -> t.Optional[exp.Expression]: index = self._index @@ -4549,18 +4567,6 @@ class Parser(metaclass=_Parser): return self.expression(exp.Extract, this=this, expression=self._parse_bitwise()) - def _parse_any_value(self) -> exp.AnyValue: - this = self._parse_lambda() - is_max = None - having = None - - if self._match(TokenType.HAVING): - self._match_texts(("MAX", "MIN")) - is_max = self._prev.text == "MAX" - having = self._parse_column() - - return self.expression(exp.AnyValue, this=this, having=having, max=is_max) - def _parse_cast(self, strict: bool, safe: t.Optional[bool] = None) -> exp.Expression: this = self._parse_conjunction() @@ -4941,6 +4947,16 @@ class Parser(metaclass=_Parser): return self.expression(exp.RespectNulls, this=this) return this + def _parse_having_max(self, this: t.Optional[exp.Expression]) -> t.Optional[exp.Expression]: + if self._match(TokenType.HAVING): + self._match_texts(("MAX", "MIN")) + max = self._prev.text.upper() != "MIN" + return self.expression( + exp.HavingMax, this=this, expression=self._parse_column(), max=max + ) + + return this + def _parse_window( self, this: t.Optional[exp.Expression], alias: bool = False ) -> t.Optional[exp.Expression]: |