Skip to content

Commit

Permalink
move the relation creation into _parse_list_relations_result to avoid…
Browse files Browse the repository at this point in the history
… returning a large number of tuples and encapsulate the result to relation intention of this method
  • Loading branch information
mikealfare committed May 21, 2024
1 parent e7fead8 commit 4963af3
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions dbt/adapters/snowflake/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,28 +143,15 @@ def list_relations_without_caching(
return []
raise

relations = []
quote_policy = {"database": True, "schema": True, "identifier": True}

# this can be reduced to always including `is_dynamic` once bundle `2024_03` is mandatory
columns = ["database_name", "schema_name", "name", "kind"]
if "is_dynamic" in results.column_names:
columns.append("is_dynamic")

for result in results.select(columns):
database, schema, identifier, relation_type = self._parse_list_relations_result(result)
relations.append(
self.Relation.create(
database=database,
schema=schema,
identifier=identifier,
type=relation_type,
quote_policy=quote_policy,
)
)

return relations
return [self._parse_list_relations_result(result) for result in results.select(columns)]

def _parse_list_relations_result(self, result: agate.Row) -> Tuple[str, str, str, str]:
def _parse_list_relations_result(self, result: agate.Row) -> SnowflakeRelation:
# this can be reduced to always including `is_dynamic` once bundle `2024_03` is mandatory
try:
database, schema, identifier, relation_type, is_dynamic = result
except ValueError:
Expand All @@ -179,7 +166,14 @@ def _parse_list_relations_result(self, result: agate.Row) -> Tuple[str, str, str
if relation_type == self.Relation.Table and is_dynamic == "Y":
relation_type = self.Relation.DynamicTable

return database, schema, identifier, relation_type
quote_policy = {"database": True, "schema": True, "identifier": True}
return self.Relation.create(
database=database,
schema=schema,
identifier=identifier,
type=relation_type,
quote_policy=quote_policy,
)

def quote_seed_column(self, column: str, quote_config: Optional[bool]) -> str:
quote_columns: bool = False
Expand Down

0 comments on commit 4963af3

Please sign in to comment.