From a497234f194717b18d22cdd42270c160e23b0c00 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Mon, 14 Oct 2024 13:48:02 -0700 Subject: [PATCH] /* PR_START p--cte 00 */ Make `SqlTable.schema_name` optional. --- .../metricflow_semantics/sql/sql_table.py | 23 ++++++++----------- .../time/time_spine_source.py | 2 +- metricflow/sql/sql_column.py | 2 +- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/metricflow-semantics/metricflow_semantics/sql/sql_table.py b/metricflow-semantics/metricflow_semantics/sql/sql_table.py index 78e2a66d1a..086203f272 100644 --- a/metricflow-semantics/metricflow_semantics/sql/sql_table.py +++ b/metricflow-semantics/metricflow_semantics/sql/sql_table.py @@ -2,7 +2,7 @@ from dataclasses import dataclass from enum import Enum -from typing import Optional, Tuple, Union +from typing import Optional class SqlTableType(Enum): # noqa: D101 @@ -14,7 +14,7 @@ class SqlTableType(Enum): # noqa: D101 class SqlTable: """Represents a reference to a SQL table.""" - schema_name: str + schema_name: Optional[str] table_name: str db_name: Optional[str] = None table_type: SqlTableType = SqlTableType.TABLE @@ -34,14 +34,11 @@ def from_string(sql_str: str) -> SqlTable: # noqa: D102 @property def sql(self) -> str: """Return the snippet that can be used for use in SQL queries.""" - if self.db_name: - return f"{self.db_name}.{self.schema_name}.{self.table_name}" - return f"{self.schema_name}.{self.table_name}" - - @property - def parts_tuple(self) -> Union[Tuple[str, str], Tuple[str, str, str]]: - """Return a tuple of the sql table parts.""" - if self.db_name: - return (self.db_name, self.schema_name, self.table_name) - else: - return (self.schema_name, self.table_name) + items = [] + if self.db_name is not None: + items.append(self.db_name) + if self.schema_name is not None: + items.append(self.schema_name) + items.append(self.table_name) + + return ".".join(items) diff --git a/metricflow-semantics/metricflow_semantics/time/time_spine_source.py b/metricflow-semantics/metricflow_semantics/time/time_spine_source.py index ddc6e17534..f55967d3eb 100644 --- a/metricflow-semantics/metricflow_semantics/time/time_spine_source.py +++ b/metricflow-semantics/metricflow_semantics/time/time_spine_source.py @@ -24,7 +24,7 @@ class TimeSpineSource: Dates should be contiguous. May also contain custom granularity columns. """ - schema_name: str + schema_name: Optional[str] table_name: str = "mf_time_spine" # Name of the column in the table that contains date/time values that map to a standard granularity. base_column: str = "ds" diff --git a/metricflow/sql/sql_column.py b/metricflow/sql/sql_column.py index 2765d36a7d..ff515bbcb5 100644 --- a/metricflow/sql/sql_column.py +++ b/metricflow/sql/sql_column.py @@ -35,7 +35,7 @@ def db_name(self) -> Optional[str]: # noqa: D102 return self.table.db_name @property - def schema_name(self) -> str: # noqa: D102 + def schema_name(self) -> Optional[str]: # noqa: D102 return self.table.schema_name @property