Merging upstream version 16.4.2.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
2426bb8908
commit
2e72f978c2
79 changed files with 72289 additions and 29264 deletions
|
@ -275,6 +275,7 @@ class Snowflake(Dialect):
|
|||
|
||||
KEYWORDS = {
|
||||
**tokens.Tokenizer.KEYWORDS,
|
||||
"BYTEINT": TokenType.INT,
|
||||
"CHAR VARYING": TokenType.VARCHAR,
|
||||
"CHARACTER VARYING": TokenType.VARCHAR,
|
||||
"EXCLUDE": TokenType.EXCEPT,
|
||||
|
|
|
@ -163,6 +163,7 @@ ENV = {
|
|||
"IF": lambda predicate, true, false: true if predicate else false,
|
||||
"INTDIV": null_if_any(lambda e, this: e // this),
|
||||
"INTERVAL": interval,
|
||||
"LEFT": null_if_any(lambda this, e: this[:e]),
|
||||
"LIKE": null_if_any(
|
||||
lambda this, e: bool(re.match(e.replace("_", ".").replace("%", ".*"), this))
|
||||
),
|
||||
|
@ -176,6 +177,7 @@ ENV = {
|
|||
"ORD": null_if_any(ord),
|
||||
"ORDERED": ordered,
|
||||
"POW": pow,
|
||||
"RIGHT": null_if_any(lambda this, e: this[-e:]),
|
||||
"STRPOSITION": str_position,
|
||||
"SUB": null_if_any(lambda e, this: e - this),
|
||||
"SUBSTRING": substring,
|
||||
|
|
|
@ -420,7 +420,7 @@ class Python(Dialect):
|
|||
exp.Column: lambda self, e: f"scope[{self.sql(e, 'table') or None}][{self.sql(e.this)}]",
|
||||
exp.Distinct: lambda self, e: f"set({self.sql(e, 'this')})",
|
||||
exp.Extract: lambda self, e: f"EXTRACT('{e.name.lower()}', {self.sql(e, 'expression')})",
|
||||
exp.In: lambda self, e: f"{self.sql(e, 'this')} in ({self.expressions(e, flat=True)})",
|
||||
exp.In: lambda self, e: f"{self.sql(e, 'this')} in {{{self.expressions(e, flat=True)}}}",
|
||||
exp.Interval: lambda self, e: f"INTERVAL({self.sql(e.this)}, '{self.sql(e.unit)}')",
|
||||
exp.Is: lambda self, e: self.binary(e, "is"),
|
||||
exp.Lambda: _lambda_sql,
|
||||
|
|
|
@ -1528,6 +1528,7 @@ class Insert(Expression):
|
|||
"exists": False,
|
||||
"partition": False,
|
||||
"alternative": False,
|
||||
"where": False,
|
||||
}
|
||||
|
||||
def with_(
|
||||
|
@ -5704,11 +5705,12 @@ def column_table_names(expression: Expression, exclude: str = "") -> t.Set[str]:
|
|||
}
|
||||
|
||||
|
||||
def table_name(table: Table | str) -> str:
|
||||
def table_name(table: Table | str, dialect: DialectType = None) -> str:
|
||||
"""Get the full name of a table as a string.
|
||||
|
||||
Args:
|
||||
table: table expression node or string.
|
||||
table: Table expression node or string.
|
||||
dialect: The dialect to generate the table name for.
|
||||
|
||||
Examples:
|
||||
>>> from sqlglot import exp, parse_one
|
||||
|
@ -5724,7 +5726,10 @@ def table_name(table: Table | str) -> str:
|
|||
if not table:
|
||||
raise ValueError(f"Cannot parse {table}")
|
||||
|
||||
return ".".join(part for part in (table.text("catalog"), table.text("db"), table.name) if part)
|
||||
return ".".join(
|
||||
part.sql(dialect=dialect) if not SAFE_IDENTIFIER_RE.match(part.name) else part.name
|
||||
for part in table.parts
|
||||
)
|
||||
|
||||
|
||||
def replace_tables(expression: E, mapping: t.Dict[str, str], copy: bool = True) -> E:
|
||||
|
|
|
@ -912,7 +912,7 @@ class Generator:
|
|||
return f"{prefix}{string}"
|
||||
|
||||
def partition_sql(self, expression: exp.Partition) -> str:
|
||||
return f"PARTITION({self.expressions(expression)})"
|
||||
return f"PARTITION({self.expressions(expression, flat=True)})"
|
||||
|
||||
def properties_sql(self, expression: exp.Properties) -> str:
|
||||
root_properties = []
|
||||
|
@ -1102,23 +1102,24 @@ class Generator:
|
|||
overwrite = expression.args.get("overwrite")
|
||||
|
||||
if isinstance(expression.this, exp.Directory):
|
||||
this = "OVERWRITE " if overwrite else "INTO "
|
||||
this = " OVERWRITE" if overwrite else " INTO"
|
||||
else:
|
||||
this = "OVERWRITE TABLE " if overwrite else "INTO "
|
||||
this = " OVERWRITE TABLE" if overwrite else " INTO"
|
||||
|
||||
alternative = expression.args.get("alternative")
|
||||
alternative = f" OR {alternative} " if alternative else " "
|
||||
this = f"{this}{self.sql(expression, 'this')}"
|
||||
alternative = f" OR {alternative}" if alternative else ""
|
||||
this = f"{this} {self.sql(expression, 'this')}"
|
||||
|
||||
exists = " IF EXISTS " if expression.args.get("exists") else " "
|
||||
exists = " IF EXISTS" if expression.args.get("exists") else ""
|
||||
partition_sql = (
|
||||
self.sql(expression, "partition") if expression.args.get("partition") else ""
|
||||
f" {self.sql(expression, 'partition')}" if expression.args.get("partition") else ""
|
||||
)
|
||||
expression_sql = self.sql(expression, "expression")
|
||||
where = self.sql(expression, "where")
|
||||
where = f"{self.sep()}REPLACE WHERE {where}" if where else ""
|
||||
expression_sql = f"{self.sep()}{self.sql(expression, 'expression')}"
|
||||
conflict = self.sql(expression, "conflict")
|
||||
returning = self.sql(expression, "returning")
|
||||
sep = self.sep() if partition_sql else ""
|
||||
sql = f"INSERT{alternative}{this}{exists}{partition_sql}{sep}{expression_sql}{conflict}{returning}"
|
||||
sql = f"INSERT{alternative}{this}{exists}{partition_sql}{where}{expression_sql}{conflict}{returning}"
|
||||
return self.prepend_ctes(expression, sql)
|
||||
|
||||
def intersect_sql(self, expression: exp.Intersect) -> str:
|
||||
|
|
|
@ -1677,6 +1677,8 @@ class Parser(metaclass=_Parser):
|
|||
this=this,
|
||||
exists=self._parse_exists(),
|
||||
partition=self._parse_partition(),
|
||||
where=self._match_pair(TokenType.REPLACE, TokenType.WHERE)
|
||||
and self._parse_conjunction(),
|
||||
expression=self._parse_ddl_select(),
|
||||
conflict=self._parse_on_conflict(),
|
||||
returning=self._parse_returning(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue