Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlglot/dialects/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ def _parse_join(
if join:
method = join.args.get("method")
join.set("method", None)
join.set("global", method)
join.set("global_", method)

# tbl ARRAY JOIN arr <-- this should be a `Column` reference, not a `Table`
# https://clickhouse.com/docs/en/sql-reference/statements/select/array-join
Expand Down
10 changes: 4 additions & 6 deletions sqlglot/dialects/duckdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,11 +662,9 @@ def _parse_force(self) -> exp.Install | exp.Command:
def _parse_install(self, force: bool = False) -> exp.Install:
return self.expression(
exp.Install,
**{ # type: ignore
"this": self._parse_id_var(),
"from": self._parse_var_or_string() if self._match(TokenType.FROM) else None,
"force": force,
},
this=self._parse_id_var(),
from_=self._parse_var_or_string() if self._match(TokenType.FROM) else None,
force=force,
)

def _parse_primary(self) -> t.Optional[exp.Expression]:
Expand Down Expand Up @@ -1008,7 +1006,7 @@ def show_sql(self, expression: exp.Show) -> str:
def install_sql(self, expression: exp.Install) -> str:
force = "FORCE " if expression.args.get("force") else ""
this = self.sql(expression, "this")
from_clause = expression.args.get("from")
from_clause = expression.args.get("from_")
from_clause = f" FROM {from_clause}" if from_clause else ""
return f"{force}INSTALL {this}{from_clause}"

Expand Down
2 changes: 1 addition & 1 deletion sqlglot/dialects/hive.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ def alterset_sql(self, expression: exp.AlterSet) -> str:
return f"SET{serde}{exprs}{location}{file_format}{tags}"

def serdeproperties_sql(self, expression: exp.SerdeProperties) -> str:
prefix = "WITH " if expression.args.get("with") else ""
prefix = "WITH " if expression.args.get("with_") else ""
exprs = self.expressions(expression, flat=True)

return f"{prefix}SERDEPROPERTIES ({exprs})"
Expand Down
4 changes: 2 additions & 2 deletions sqlglot/dialects/mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ def _parse_show_mysql(
for_role=for_role,
into_outfile=into_outfile,
json=json,
**{"global": global_}, # type: ignore
global_=global_,
)

def _parse_oldstyle_limit(
Expand Down Expand Up @@ -1229,7 +1229,7 @@ def cast_sql(self, expression: exp.Cast, safe_prefix: t.Optional[str] = None) ->
def show_sql(self, expression: exp.Show) -> str:
this = f" {expression.name}"
full = " FULL" if expression.args.get("full") else ""
global_ = " GLOBAL" if expression.args.get("global") else ""
global_ = " GLOBAL" if expression.args.get("global_") else ""

target = self.sql(expression, "target")
target = f" {target}" if target else ""
Expand Down
8 changes: 7 additions & 1 deletion sqlglot/dialects/presto.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,13 @@ class Generator(generator.Generator):
TRANSFORMS = {
**generator.Generator.TRANSFORMS,
exp.AnyValue: rename_func("ARBITRARY"),
exp.ApproxQuantile: rename_func("APPROX_PERCENTILE"),
exp.ApproxQuantile: lambda self, e: self.func(
"APPROX_PERCENTILE",
e.this,
e.args.get("weight"),
e.args.get("quantile"),
e.args.get("accuracy"),
),
exp.ArgMax: rename_func("MAX_BY"),
exp.ArgMin: rename_func("MIN_BY"),
exp.Array: transforms.preprocess(
Expand Down
2 changes: 1 addition & 1 deletion sqlglot/dialects/singlestore.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ def _unicode_substitute(m: re.Match[str]) -> str:
"offset",
"starts_with",
"limit",
"from",
"from_",
"scope",
"scope_kind",
"mutex",
Expand Down
26 changes: 12 additions & 14 deletions sqlglot/dialects/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -1114,19 +1114,17 @@ def _parse_show_snowflake(self, this: str) -> exp.Show:

return self.expression(
exp.Show,
**{
"terse": terse,
"this": this,
"history": history,
"like": like,
"scope": scope,
"scope_kind": scope_kind,
"starts_with": self._match_text_seq("STARTS", "WITH") and self._parse_string(),
"limit": self._parse_limit(),
"from": self._parse_string() if self._match(TokenType.FROM) else None,
"privileges": self._match_text_seq("WITH", "PRIVILEGES")
and self._parse_csv(lambda: self._parse_var(any_token=True, upper=True)),
},
terse=terse,
this=this,
history=history,
like=like,
scope=scope,
scope_kind=scope_kind,
starts_with=self._match_text_seq("STARTS", "WITH") and self._parse_string(),
limit=self._parse_limit(),
from_=self._parse_string() if self._match(TokenType.FROM) else None,
privileges=self._match_text_seq("WITH", "PRIVILEGES")
and self._parse_csv(lambda: self._parse_var(any_token=True, upper=True)),
)

def _parse_put(self) -> exp.Put | exp.Command:
Expand Down Expand Up @@ -1652,7 +1650,7 @@ def show_sql(self, expression: exp.Show) -> str:

limit = self.sql(expression, "limit")

from_ = self.sql(expression, "from")
from_ = self.sql(expression, "from_")
if from_:
from_ = f" FROM {from_}"

Expand Down
13 changes: 5 additions & 8 deletions sqlglot/dialects/teradata.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,10 @@ def _parse_translate(self) -> exp.TranslateCharacters:
def _parse_update(self) -> exp.Update:
return self.expression(
exp.Update,
**{ # type: ignore
"this": self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
"from": self._parse_from(joins=True),
"expressions": self._match(TokenType.SET)
and self._parse_csv(self._parse_equality),
"where": self._parse_where(),
},
this=self._parse_table(alias_tokens=self.UPDATE_ALIAS_TOKENS),
from_=self._parse_from(joins=True),
expressions=self._match(TokenType.SET) and self._parse_csv(self._parse_equality),
where=self._parse_where(),
)

def _parse_rangen(self):
Expand Down Expand Up @@ -387,7 +384,7 @@ def partitionedbyproperty_sql(self, expression: exp.PartitionedByProperty) -> st
# https://docs.teradata.com/r/Enterprise_IntelliFlex_VMware/Teradata-VantageTM-SQL-Data-Manipulation-Language-17.20/Statement-Syntax/UPDATE/UPDATE-Syntax-Basic-Form-FROM-Clause
def update_sql(self, expression: exp.Update) -> str:
this = self.sql(expression, "this")
from_sql = self.sql(expression, "from")
from_sql = self.sql(expression, "from_")
set_sql = self.expressions(expression, flat=True)
where_sql = self.sql(expression, "where")
sql = f"UPDATE {this}{from_sql} SET {set_sql}{where_sql}"
Expand Down
11 changes: 5 additions & 6 deletions sqlglot/dialects/tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ class Parser(parser.Parser):
QUERY_MODIFIER_PARSERS = {
**parser.Parser.QUERY_MODIFIER_PARSERS,
TokenType.OPTION: lambda self: ("options", self._parse_options()),
TokenType.FOR: lambda self: ("for", self._parse_for()),
TokenType.FOR: lambda self: ("for_", self._parse_for()),
}

# T-SQL does not allow BEGIN to be used as an identifier
Expand Down Expand Up @@ -825,7 +825,6 @@ def _parse_convert(
args = [this, *self._parse_csv(self._parse_assignment)]
convert = exp.Convert.from_arg_list(args)
convert.set("safe", safe)
convert.set("strict", strict)
return convert

def _parse_column_def(
Expand Down Expand Up @@ -882,7 +881,7 @@ def _parse_id_var(
this = super()._parse_id_var(any_token=any_token, tokens=tokens)
if this:
if is_global:
this.set("global", True)
this.set("global_", True)
elif is_temporary:
this.set("temporary", True)

Expand Down Expand Up @@ -1241,12 +1240,12 @@ def create_sql(self, expression: exp.Create) -> str:

if kind == "VIEW":
expression.this.set("catalog", None)
with_ = expression.args.get("with")
with_ = expression.args.get("with_")
if ctas_expression and with_:
# We've already preprocessed the Create expression to bubble up any nested CTEs,
# but CREATE VIEW actually requires the WITH clause to come after it so we need
# to amend the AST by moving the CTEs to the CREATE VIEW statement's query.
ctas_expression.set("with", with_.pop())
ctas_expression.set("with_", with_.pop())

table = expression.find(exp.Table)

Expand Down Expand Up @@ -1362,7 +1361,7 @@ def rollback_sql(self, expression: exp.Rollback) -> str:
def identifier_sql(self, expression: exp.Identifier) -> str:
identifier = super().identifier_sql(expression)

if expression.args.get("global"):
if expression.args.get("global_"):
identifier = f"##{identifier}"
elif expression.args.get("temporary"):
identifier = f"#{identifier}"
Expand Down
Loading