From 5b4b2f7cb186b2c8cddee85cf4ea7f54dee79505 Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 16 Oct 2024 11:34:04 -0700 Subject: [PATCH 1/2] Add SnowflakeExternalCatalogIntegration to impl --- dbt/adapters/snowflake/impl.py | 2 ++ 1 file changed, 2 insertions(+) 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 From cb898d2dda087a08ebdb72c69e58134f0f8670ba Mon Sep 17 00:00:00 2001 From: Colin Date: Wed, 16 Oct 2024 11:36:06 -0700 Subject: [PATCH 2/2] Add SnowflakeExternalCatalogIntegration to impl --- dbt/adapters/snowflake/catalog.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 dbt/adapters/snowflake/catalog.py 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}'")