Skip to content

Commit

Permalink
/* PR_START p--cte 00 */ Make SqlTable.schema_name optional.
Browse files Browse the repository at this point in the history
  • Loading branch information
plypaul committed Oct 15, 2024
1 parent 15a6ae7 commit a497234
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
23 changes: 10 additions & 13 deletions metricflow-semantics/metricflow_semantics/sql/sql_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion metricflow/sql/sql_column.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a497234

Please sign in to comment.