Merging upstream version 21.0.2.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
7d0896f08b
commit
b7d506d9b2
58 changed files with 25616 additions and 25078 deletions
|
@ -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]:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue