Skip to content

Commit

Permalink
Refactor: Rename exp.RenameTable to exp.AlterRename (#4224)
Browse files Browse the repository at this point in the history
  • Loading branch information
VaggelisD authored Oct 8, 2024
1 parent 9834694 commit 0882f03
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion sqlglot/dialects/tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1166,7 +1166,7 @@ def partition_sql(self, expression: exp.Partition) -> str:

def alter_sql(self, expression: exp.Alter) -> str:
action = seq_get(expression.args.get("actions") or [], 0)
if isinstance(action, exp.RenameTable):
if isinstance(action, exp.AlterRename):
return f"EXEC sp_rename '{self.sql(expression.this)}', '{action.this.name}'"
return super().alter_sql(expression)

Expand Down
4 changes: 2 additions & 2 deletions sqlglot/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1697,7 +1697,7 @@ class RenameColumn(Expression):
arg_types = {"this": True, "to": True, "exists": False}


class RenameTable(Expression):
class AlterRename(Expression):
pass


Expand Down Expand Up @@ -7795,7 +7795,7 @@ def rename_table(
this=old_table,
kind="TABLE",
actions=[
RenameTable(this=new_table),
AlterRename(this=new_table),
],
)

Expand Down
4 changes: 2 additions & 2 deletions sqlglot/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3225,12 +3225,12 @@ def altersortkey_sql(self, expression: exp.AlterSortKey) -> str:
expressions = f"({expressions})" if expressions else ""
return f"ALTER{compound} SORTKEY {this or expressions}"

def renametable_sql(self, expression: exp.RenameTable) -> str:
def alterrename_sql(self, expression: exp.AlterRename) -> str:
if not self.RENAME_TABLE_WITH_DB:
# Remove db from tables
expression = expression.transform(
lambda n: exp.table_(n.this) if isinstance(n, exp.Table) else n
).assert_is(exp.RenameTable)
).assert_is(exp.AlterRename)
this = self.sql(expression, "this")
return f"RENAME TO {this}"

Expand Down
4 changes: 2 additions & 2 deletions sqlglot/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -6764,7 +6764,7 @@ def _parse_alter_table_drop(self) -> t.List[exp.Expression]:
self._retreat(index)
return self._parse_csv(self._parse_drop_column)

def _parse_alter_table_rename(self) -> t.Optional[exp.RenameTable | exp.RenameColumn]:
def _parse_alter_table_rename(self) -> t.Optional[exp.AlterRename | exp.RenameColumn]:
if self._match(TokenType.COLUMN):
exists = self._parse_exists()
old_column = self._parse_column()
Expand All @@ -6777,7 +6777,7 @@ def _parse_alter_table_rename(self) -> t.Optional[exp.RenameTable | exp.RenameCo
return self.expression(exp.RenameColumn, this=old_column, to=new_column, exists=exists)

self._match_text_seq("TO")
return self.expression(exp.RenameTable, this=self._parse_table(schema=True))
return self.expression(exp.AlterRename, this=self._parse_table(schema=True))

def _parse_alter_table_set(self) -> exp.AlterSet:
alter_set = self.expression(exp.AlterSet)
Expand Down

0 comments on commit 0882f03

Please sign in to comment.