diff --git a/dbt/adapters/snowflake/catalog.py b/dbt/adapters/snowflake/catalog.py new file mode 100644 index 000000000..0a05d88c5 --- /dev/null +++ b/dbt/adapters/snowflake/catalog.py @@ -0,0 +1,29 @@ +from dbt.adapters.base import BaseRelation +from dbt.adapters.base.catalog import ExternalCatalogIntegration + + +class SnowflakeExternalCatalogIntegration(ExternalCatalogIntegration): + + def relation_exists(self, relation: BaseRelation) -> bool: + response, result = self._connection_manager.execute(f"DESCRIBE ICEBERG TABLE {relation.render()}") + if result and result.rows: + return True + return False + + def _exists(self) -> bool: + if not self._exists: + response, result = self._connection_manager.execute( + f"DESCRIBE CATALOG INTEGRATION {self.external_catalog.name}") + if result and result.rows: + self._exists = True + else: + self._exists = False + return self._exists + + def refresh_relation(self, relation: BaseRelation) -> None: + self._connection_manager.execute(f"ALTER ICEBERG TABLE {relation.render()} REFRESH") + + def create_relation(self, relation: BaseRelation) -> None: + self._connection_manager.execute(f"CREATE ICEBERG TABLE {relation.render()}" + f"EXTERNAL_VOLUME '{self.external_catalog.configuration.external_volume.name}'" + f"CATALOG='{self.external_catalog.name}'") diff --git a/dbt/adapters/snowflake/impl.py b/dbt/adapters/snowflake/impl.py index 6320893e1..fe7ea676e 100644 --- a/dbt/adapters/snowflake/impl.py +++ b/dbt/adapters/snowflake/impl.py @@ -4,6 +4,7 @@ from dbt.adapters.base.impl import AdapterConfig, ConstraintSupport from dbt.adapters.base.meta import available from dbt.adapters.capability import CapabilityDict, CapabilitySupport, Support, Capability +from dbt.adapters.snowflake.catalog import SnowflakeExternalCatalogIntegration from dbt.adapters.sql import SQLAdapter from dbt.adapters.sql.impl import ( LIST_SCHEMAS_MACRO_NAME, @@ -58,6 +59,7 @@ class SnowflakeAdapter(SQLAdapter): Relation = SnowflakeRelation Column = SnowflakeColumn ConnectionManager = SnowflakeConnectionManager + ExternalCatalogIntegration = SnowflakeExternalCatalogIntegration AdapterSpecificConfigs = SnowflakeConfig