Skip to content

Commit 65fb037

Browse files
committed
Add supported drop cascade object indicators
1 parent 1daf71e commit 65fb037

File tree

9 files changed

+15
-16
lines changed

9 files changed

+15
-16
lines changed

sqlmesh/core/engine_adapter/athena.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class AthenaEngineAdapter(PandasNativeFetchDFSupportMixin, RowDiffMixin):
4545
# >>> self._execute('/* test */ DESCRIBE foo')
4646
# pyathena.error.OperationalError: FAILED: ParseException line 1:0 cannot recognize input near '/' '*' 'test'
4747
ATTACH_CORRELATION_ID = False
48+
SUPPORTED_DROP_CASCADE_OBJECT_KINDS = ["DATABASE", "SCHEMA"]
4849

4950
def __init__(
5051
self, *args: t.Any, s3_warehouse_location: t.Optional[str] = None, **kwargs: t.Any

sqlmesh/core/engine_adapter/base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class EngineAdapter:
108108
SUPPORTS_CLONING = False
109109
SUPPORTS_MANAGED_MODELS = False
110110
SUPPORTS_CREATE_DROP_CATALOG = False
111+
SUPPORTED_DROP_CASCADE_OBJECT_KINDS: t.List[str] = []
111112
SCHEMA_DIFFER = SchemaDiffer()
112113
SUPPORTS_TUPLE_IN = True
113114
HAS_VIEW_BINDING = False
@@ -1060,6 +1061,7 @@ def _drop_object(
10601061
name: TableName | SchemaName,
10611062
exists: bool = True,
10621063
kind: str = "TABLE",
1064+
cascade: bool = False,
10631065
**drop_args: t.Any,
10641066
) -> None:
10651067
"""Drops an object.
@@ -1070,8 +1072,13 @@ def _drop_object(
10701072
name: The name of the table to drop.
10711073
exists: If exists, defaults to True.
10721074
kind: What kind of object to drop. Defaults to TABLE
1075+
cascade: Whether or not to DROP ... CASCADE.
1076+
Note that this is ignored for :kind's that are not present in self.SUPPORTED_DROP_CASCADE_OBJECT_KINDS
10731077
**drop_args: Any extra arguments to set on the Drop expression
10741078
"""
1079+
if cascade and kind.upper() in self.SUPPORTED_DROP_CASCADE_OBJECT_KINDS:
1080+
drop_args["cascade"] = cascade
1081+
10751082
self.execute(exp.Drop(this=exp.to_table(name), kind=kind, exists=exists, **drop_args))
10761083

10771084
def get_alter_expressions(

sqlmesh/core/engine_adapter/base_postgres.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class BasePostgresEngineAdapter(EngineAdapter):
2424
DEFAULT_BATCH_SIZE = 400
2525
COMMENT_CREATION_TABLE = CommentCreationTable.COMMENT_COMMAND_ONLY
2626
COMMENT_CREATION_VIEW = CommentCreationView.COMMENT_COMMAND_ONLY
27+
SUPPORTED_DROP_CASCADE_OBJECT_KINDS = ["SCHEMA", "TABLE", "VIEW"]
2728

2829
def columns(
2930
self, table_name: TableName, include_pseudo_columns: bool = False

sqlmesh/core/engine_adapter/bigquery.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ class BigQueryEngineAdapter(InsertOverwriteWithMergeMixin, ClusteredByMixin, Row
6868
SUPPORTS_CLONING = True
6969
MAX_TABLE_COMMENT_LENGTH = 1024
7070
MAX_COLUMN_COMMENT_LENGTH = 1024
71+
SUPPORTED_DROP_CASCADE_OBJECT_KINDS = ["SCHEMA"]
7172

7273
SCHEMA_DIFFER = SchemaDiffer(
7374
compatible_types={
@@ -1260,21 +1261,6 @@ def _native_df_to_pandas_df(
12601261

12611262
return super()._native_df_to_pandas_df(query_or_df)
12621263

1263-
def _drop_object(
1264-
self,
1265-
name: TableName | SchemaName,
1266-
exists: bool = True,
1267-
kind: str = "TABLE",
1268-
**drop_args: t.Any,
1269-
) -> None:
1270-
if kind.upper() == "TABLE" and "cascade" in drop_args:
1271-
# BigQuery doesnt support DROP CASCADE for tables
1272-
# ref: https://cloud.google.com/bigquery/docs/reference/standard-sql/data-definition-language#drop_table_statement
1273-
# so set it to False here so SQLGlot doesnt output a CASCADE argument
1274-
drop_args["cascade"] = False
1275-
1276-
super()._drop_object(name=name, exists=exists, kind=kind, **drop_args)
1277-
12781264
@property
12791265
def _query_data(self) -> t.Any:
12801266
return self._connection_pool.get_attribute("query_data")

sqlmesh/core/engine_adapter/clickhouse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,7 @@ def _drop_object(
614614
name: TableName | SchemaName,
615615
exists: bool = True,
616616
kind: str = "TABLE",
617+
cascade: bool = False,
617618
**drop_args: t.Any,
618619
) -> None:
619620
"""Drops an object.
@@ -626,7 +627,6 @@ def _drop_object(
626627
kind: What kind of object to drop. Defaults to TABLE
627628
**drop_args: Any extra arguments to set on the Drop expression
628629
"""
629-
drop_args.pop("cascade", None)
630630
self.execute(
631631
exp.Drop(
632632
this=exp.to_table(name),

sqlmesh/core/engine_adapter/duckdb.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class DuckDBEngineAdapter(LogicalMergeMixin, GetCurrentCatalogFromFunctionMixin,
3737
COMMENT_CREATION_TABLE = CommentCreationTable.COMMENT_COMMAND_ONLY
3838
COMMENT_CREATION_VIEW = CommentCreationView.COMMENT_COMMAND_ONLY
3939
SUPPORTS_CREATE_DROP_CATALOG = True
40+
SUPPORTED_DROP_CASCADE_OBJECT_KINDS = ["SCHEMA", "TABLE", "VIEW"]
4041

4142
@property
4243
def catalog_support(self) -> CatalogSupport:

sqlmesh/core/engine_adapter/snowflake.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class SnowflakeEngineAdapter(GetCurrentCatalogFromFunctionMixin, ClusteredByMixi
5555
SUPPORTS_MANAGED_MODELS = True
5656
CURRENT_CATALOG_EXPRESSION = exp.func("current_database")
5757
SUPPORTS_CREATE_DROP_CATALOG = True
58+
SUPPORTED_DROP_CASCADE_OBJECT_KINDS = ["DATABASE", "SCHEMA", "TABLE"]
5859
SCHEMA_DIFFER = SchemaDiffer(
5960
parameterized_type_defaults={
6061
exp.DataType.build("BINARY", dialect=DIALECT).this: [(8388608,)],

sqlmesh/core/engine_adapter/spark.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ class SparkEngineAdapter(
5757
# currently check for storage formats we say we don't support REPLACE TABLE
5858
SUPPORTS_REPLACE_TABLE = False
5959
QUOTE_IDENTIFIERS_IN_VIEWS = False
60+
SUPPORTED_DROP_CASCADE_OBJECT_KINDS = ["DATABASE", "SCHEMA"]
6061

6162
WAP_PREFIX = "wap_"
6263
BRANCH_PREFIX = "branch_"

sqlmesh/core/engine_adapter/trino.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class TrinoEngineAdapter(
5353
COMMENT_CREATION_TABLE = CommentCreationTable.IN_SCHEMA_DEF_NO_CTAS
5454
COMMENT_CREATION_VIEW = CommentCreationView.COMMENT_COMMAND_ONLY
5555
SUPPORTS_REPLACE_TABLE = False
56+
SUPPORTED_DROP_CASCADE_OBJECT_KINDS = ["SCHEMA"]
5657
DEFAULT_CATALOG_TYPE = "hive"
5758
QUOTE_IDENTIFIERS_IN_VIEWS = False
5859
SCHEMA_DIFFER = SchemaDiffer(

0 commit comments

Comments
 (0)