diff --git a/sqlglot/dialects/clickhouse.py b/sqlglot/dialects/clickhouse.py index b9fce71a31..675cc7a8a7 100644 --- a/sqlglot/dialects/clickhouse.py +++ b/sqlglot/dialects/clickhouse.py @@ -769,7 +769,9 @@ def _parse_join( ) -> t.Optional[exp.Join]: join = super()._parse_join(skip_join_token=skip_join_token, parse_bracket=True) if join: - join.set("global", join.args.pop("method", None)) + method = join.args.get("method") + join.set("method", None) + 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 diff --git a/sqlglot/dialects/dialect.py b/sqlglot/dialects/dialect.py index 7f5765c359..5ffc01d1b8 100644 --- a/sqlglot/dialects/dialect.py +++ b/sqlglot/dialects/dialect.py @@ -1196,7 +1196,7 @@ def no_paren_current_date_sql(self: Generator, expression: exp.CurrentDate) -> s def no_recursive_cte_sql(self: Generator, expression: exp.With) -> str: if expression.args.get("recursive"): self.unsupported("Recursive CTEs are unsupported") - expression.args["recursive"] = False + expression.set("recursive", False) return self.with_sql(expression) diff --git a/sqlglot/dialects/duckdb.py b/sqlglot/dialects/duckdb.py index b2e6dd3435..7b9c2b4cba 100644 --- a/sqlglot/dialects/duckdb.py +++ b/sqlglot/dialects/duckdb.py @@ -1038,8 +1038,8 @@ def join_sql(self, expression: exp.Join) -> str: if isinstance(expression.this, exp.Unnest): return super().join_sql(expression.on(exp.true())) - expression.args.pop("side", None) - expression.args.pop("kind", None) + expression.set("side", None) + expression.set("kind", None) return super().join_sql(expression) diff --git a/sqlglot/dialects/postgres.py b/sqlglot/dialects/postgres.py index 7b4ae4d740..a6d2919849 100644 --- a/sqlglot/dialects/postgres.py +++ b/sqlglot/dialects/postgres.py @@ -67,7 +67,7 @@ def func(self: Postgres.Generator, expression: DATE_ADD_OR_SUB) -> str: e = self._simplify_unless_literal(expression.expression) if isinstance(e, exp.Literal): - e.args["is_string"] = True + e.set("is_string", True) elif e.is_number: e = exp.Literal.string(e.to_py()) else: diff --git a/sqlglot/dialects/tsql.py b/sqlglot/dialects/tsql.py index db51499215..537441174f 100644 --- a/sqlglot/dialects/tsql.py +++ b/sqlglot/dialects/tsql.py @@ -1219,7 +1219,8 @@ def createable_sql(self, expression: exp.Create, locations: t.DefaultDict) -> st def create_sql(self, expression: exp.Create) -> str: kind = expression.kind - exists = expression.args.pop("exists", None) + exists = expression.args.get("exists") + expression.set("exists", None) like_property = expression.find(exp.LikeProperty) if like_property: diff --git a/sqlglot/expressions.py b/sqlglot/expressions.py index 213b03e506..97d40d63b0 100644 --- a/sqlglot/expressions.py +++ b/sqlglot/expressions.py @@ -1008,8 +1008,8 @@ def rlike(self, other: ExpOrStr) -> RegexpLike: def div(self, other: ExpOrStr, typed: bool = False, safe: bool = False) -> Div: div = self._binop(Div, other) - div.args["typed"] = typed - div.args["safe"] = safe + div.set("typed", typed) + div.set("safe", safe) return div def asc(self, nulls_first: bool = True) -> Ordered: diff --git a/sqlglot/optimizer/qualify_columns.py b/sqlglot/optimizer/qualify_columns.py index 7daf0d22f0..c8a0cc859d 100644 --- a/sqlglot/optimizer/qualify_columns.py +++ b/sqlglot/optimizer/qualify_columns.py @@ -162,7 +162,7 @@ def _pop_table_column_aliases(derived_tables: t.List[exp.CTE | exp.Subquery]) -> continue table_alias = derived_table.args.get("alias") if table_alias: - table_alias.args.pop("columns", None) + table_alias.set("columns", None) def _expand_using(scope: Scope, resolver: Resolver) -> t.Dict[str, t.Any]: @@ -239,7 +239,7 @@ def _update_source_columns(source_name: str) -> None: if join_table not in tables: tables[join_table] = None - join.args.pop("using") + join.set("using", None) join.set("on", exp.and_(*conditions, copy=False)) if column_tables: diff --git a/sqlglot/optimizer/qualify_tables.py b/sqlglot/optimizer/qualify_tables.py index 6d33105218..2fcfed8bc1 100644 --- a/sqlglot/optimizer/qualify_tables.py +++ b/sqlglot/optimizer/qualify_tables.py @@ -72,7 +72,8 @@ def _qualify(table: exp.Table) -> None: if isinstance(derived_table, exp.Subquery): unnested = derived_table.unnest() if isinstance(unnested, exp.Table): - joins = unnested.args.pop("joins", None) + joins = unnested.args.get("joins") + unnested.set("joins", None) derived_table.this.replace(exp.select("*").from_(unnested.copy(), copy=False)) derived_table.this.set("joins", joins) diff --git a/sqlglot/optimizer/unnest_subqueries.py b/sqlglot/optimizer/unnest_subqueries.py index eef97f1c01..e42bd7617b 100644 --- a/sqlglot/optimizer/unnest_subqueries.py +++ b/sqlglot/optimizer/unnest_subqueries.py @@ -189,7 +189,7 @@ def decorrelate(select, parent_select, external_columns, next_alias_name): # exists queries should not have any selects as it only checks if there are any rows # all selects will be added by the optimizer and only used for join keys if isinstance(parent_predicate, exp.Exists): - select.args["expressions"] = [] + select.set("expressions", []) for key, alias in key_aliases.items(): if key in group_by: diff --git a/sqlglot/parser.py b/sqlglot/parser.py index 6e4f10fd3a..d6209480a2 100644 --- a/sqlglot/parser.py +++ b/sqlglot/parser.py @@ -3571,7 +3571,8 @@ def _parse_query_modifiers(self, this): this.set(key, expression) if key == "limit": - offset = expression.args.pop("offset", None) + offset = expression.args.get("offset") + expression.set("offset", None) if offset: offset = exp.Offset(expression=offset) @@ -5271,8 +5272,8 @@ def _parse_factor(self) -> t.Optional[exp.Expression]: this = self.expression(klass, this=this, comments=comments, expression=expression) if isinstance(this, exp.Div): - this.args["typed"] = self.dialect.TYPED_DIVISION - this.args["safe"] = self.dialect.SAFE_DIVISION + this.set("typed", self.dialect.TYPED_DIVISION) + this.set("safe", self.dialect.SAFE_DIVISION) return this diff --git a/sqlglot/transforms.py b/sqlglot/transforms.py index fb08ce0624..47ea1f69ce 100644 --- a/sqlglot/transforms.py +++ b/sqlglot/transforms.py @@ -650,8 +650,8 @@ def eliminate_full_outer_join(expression: exp.Expression) -> exp.Expression: anti_join_clause = exp.select("1").from_(expression.args["from"]).where(join_conditions) expression_copy.args["joins"][index].set("side", "right") expression_copy = expression_copy.where(exp.Exists(this=anti_join_clause).not_()) - expression_copy.args.pop("with", None) # remove CTEs from RIGHT side - expression.args.pop("order", None) # remove order by from LEFT side + expression_copy.set("with", None) # remove CTEs from RIGHT side + expression.set("order", None) # remove order by from LEFT side return exp.union(expression, expression_copy, copy=False, distinct=False)