Skip to content

Commit

Permalink
Handle formula extraction from TML models (#1069)
Browse files Browse the repository at this point in the history
  • Loading branch information
mars-lan authored Jan 22, 2025
1 parent 14eef78 commit e50148e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion metaphor/thought_spot/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,12 @@ def build_formula_map(tml_table):
elif tml.view:
formula_map = build_formula_map(tml.view)
columns = tml.view.view_columns
elif tml.model:
formula_map = build_formula_map(tml.model)
columns = tml.model.columns
else:
return
logger.warning(f"Unknown TML object type: {tml}")
return {}

expr_map = {}
for column in columns:
Expand Down
10 changes: 10 additions & 0 deletions metaphor/thought_spot/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,22 @@ class TMLColumn(BaseModel):
formula_id: Optional[str] = None


# https://docs.thoughtspot.com/cloud/latest/tml-worksheets
class TMLWorksheet(TMLBase):
worksheet_columns: List[TMLColumn]


# https://docs.thoughtspot.com/cloud/latest/tml-views
class TMLView(TMLBase):
view_columns: List[TMLColumn]


# https://docs.thoughtspot.com/cloud/latest/tml-models
class TMLModel(TMLBase):
columns: List[TMLColumn]


# https://docs.thoughtspot.com/cloud/latest/tml-tables
class TMLTable(BaseModel):
name: str
id: Optional[str] = None
Expand All @@ -247,6 +255,7 @@ class TMLAnswerTableObject(BaseModel):
ordered_column_ids: List[str] = Field(default_factory=list)


# https://docs.thoughtspot.com/cloud/latest/tml-answers
class TMLAnswer(TMLBase):
tables: List[TMLTable]
table: TMLAnswerTableObject
Expand All @@ -256,4 +265,5 @@ class TMLObject(BaseModel):
guid: str
worksheet: Optional[TMLWorksheet] = None
view: Optional[TMLView] = None
model: Optional[TMLModel] = None
answer: Optional[TMLAnswer] = None
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "metaphor-connectors"
version = "0.14.179"
version = "0.14.180"
license = "Apache-2.0"
description = "A collection of Python-based 'connectors' that extract metadata from various sources to ingest into the Metaphor app."
authors = ["Metaphor <dev@metaphor.io>"]
Expand Down

0 comments on commit e50148e

Please sign in to comment.