1
0
Fork 0

Adding upstream version 26.10.1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-03-17 07:38:52 +01:00
parent 412e82cbc6
commit 5b8e67f8b8
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
66 changed files with 79349 additions and 76628 deletions

View file

@ -11,6 +11,7 @@ SQL expressions, such as `sqlglot.expressions.select`.
"""
from __future__ import annotations
import datetime
import math
import numbers
@ -37,6 +38,7 @@ from sqlglot.tokens import Token, TokenError
if t.TYPE_CHECKING:
from typing_extensions import Self
from sqlglot._typing import E, Lit
from sqlglot.dialects.dialect import DialectType
@ -410,8 +412,7 @@ class Expression(metaclass=_Expression):
def iter_expressions(self, reverse: bool = False) -> t.Iterator[Expression]:
"""Yields the key and expression for all arguments, exploding list args."""
# remove tuple when python 3.7 is deprecated
for vs in reversed(tuple(self.args.values())) if reverse else self.args.values(): # type: ignore
for vs in reversed(self.args.values()) if reverse else self.args.values(): # type: ignore
if type(vs) is list:
for v in reversed(vs) if reverse else vs: # type: ignore
if hasattr(v, "parent"):
@ -2586,6 +2587,18 @@ class Lateral(UDTF):
}
# https://docs.snowflake.com/sql-reference/literals-table
# https://docs.snowflake.com/en/sql-reference/functions-table#using-a-table-function
class TableFromRows(UDTF):
arg_types = {
"this": True,
"alias": False,
"joins": False,
"pivots": False,
"sample": False,
}
class MatchRecognizeMeasure(Expression):
arg_types = {
"this": True,
@ -8495,7 +8508,7 @@ def replace_placeholders(expression: Expression, *args, **kwargs) -> Expression:
def expand(
expression: Expression,
sources: t.Dict[str, Query],
sources: t.Dict[str, Query | t.Callable[[], Query]],
dialect: DialectType = None,
copy: bool = True,
) -> Expression:
@ -8511,23 +8524,29 @@ def expand(
Args:
expression: The expression to expand.
sources: A dictionary of name to Queries.
dialect: The dialect of the sources dict.
sources: A dict of name to query or a callable that provides a query on demand.
dialect: The dialect of the sources dict or the callable.
copy: Whether to copy the expression during transformation. Defaults to True.
Returns:
The transformed expression.
"""
sources = {normalize_table_name(k, dialect=dialect): v for k, v in sources.items()}
normalized_sources = {normalize_table_name(k, dialect=dialect): v for k, v in sources.items()}
def _expand(node: Expression):
if isinstance(node, Table):
name = normalize_table_name(node, dialect=dialect)
source = sources.get(name)
source = normalized_sources.get(name)
if source:
subquery = source.subquery(node.alias or name)
# Create a subquery with the same alias (or table name if no alias)
parsed_source = source() if callable(source) else source
subquery = parsed_source.subquery(node.alias or name)
subquery.comments = [f"source: {name}"]
# Continue expanding within the subquery
return subquery.transform(_expand, copy=False)
return node
return expression.transform(_expand, copy=copy)