Repository navigation
M kovalsky/snowflake - #1333
M kovalsky/snowflake#1333Michael Kovalsky (m-kovalsky) wants to merge 8 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Several public API surfaces have fixable contract/maintainability issues (return type annotations, redundant logic) and the large YAML assets under src/ risk shipping unnecessary package bloat.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR adds Snowflake semantic-view support by converting Snowflake Semantic View YAML into the project’s model_map format, generating a Direct Lake Model.bim, and expanding the SQL→DAX translator to cover more Snowflake-style scalar functions while safely falling back to BLANK() for unsupported/unresolvable expressions.
Changes:
- Added Snowflake semantic view conversion pipeline (
convert_from_snowflake) plus Snowflake REST helpers to enumerate base-table columns. - Introduced
convert_model_map_to_bimto emit Direct Lake TMSL (Model.bim) from amodel_mapand exported it viasempy_labs.semantic_model. - Enhanced
convert_sql_to_daxwith more scalar/function translations and stricter “untranslatable → BLANK()” behavior; added tests and updated the SQL→DAX skill guide.
File summaries
| File | Description |
|---|---|
| tests/test_sql_to_dax.py | Adds unit tests for new SQL→DAX translations and BLANK() fallback behavior. |
| tests/test_convert_model_map.py | Adds unit tests validating model_map → Model.bim output structure and annotations. |
| src/sempy_labs/semantic_model/snowflakeSM.yaml | Adds a large example Snowflake semantic view YAML. |
| src/sempy_labs/semantic_model/snowflake.yaml | Adds a template/spec-style Snowflake semantic view YAML skeleton. |
| src/sempy_labs/semantic_model/_snowflake.py | Implements YAML→model_map conversion + optional semantic model creation from BIM. |
| src/sempy_labs/semantic_model/_helper.py | Extends SQL→DAX translation and standardizes unsupported/unparseable handling to BLANK(). |
| src/sempy_labs/semantic_model/_convert_model_map.py | Introduces conversion from model_map to Direct Lake TMSL (Model.bim). |
| src/sempy_labs/semantic_model/init.py | Exports convert_model_map_to_bim from the semantic_model package. |
| src/sempy_labs/_snowflake.py | Adds Snowflake API wrappers for listing tables/columns. |
| .claude/skills/sql_to_dax/SKILL.md | Documents the new SQL→DAX translation rules and edge cases. |
Review details
Suppressed comments (1)
src/sempy_labs/_snowflake.py:75
- The function returns response.json() when return_dataframe=False, but the return type is annotated as pd.DataFrame. Please update the annotation to reflect the JSON return option for a stable public API contract.
def list_snowflake_columns(
account: str,
token: str,
database: str,
schema: str,
table: str,
return_dataframe: bool = True,
) -> pd.DataFrame:
- Files reviewed: 10/10 changed files
- Comments generated: 7
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| def list_snowflake_tables( | ||
| account: str, | ||
| token: str, | ||
| database: str, | ||
| schema: str, | ||
| table: Optional[str] = None, | ||
| return_dataframe: bool = True, | ||
| ) -> pd.DataFrame: |
| if rows: | ||
| df = pd.DataFrame(rows, columns=columns.keys()) | ||
|
|
||
| return df |
| @log | ||
| def convert_from_snowflake( | ||
| yaml_file: str, | ||
| account: str, | ||
| token: str, | ||
| source_item: str | UUID, |
| # Name and description of the semantic view. | ||
| name: <name> | ||
| description: <string> | ||
|
|
||
| # Logical table-level concepts | ||
| # A semantic view can contain one or more logical tables. | ||
| tables: | ||
| # A logical table on top of a base table. | ||
| - name: <name> | ||
| description: <string> |
| name: MKVIEW | ||
| description: >- | ||
| Store-channel retail analytics semantic view over the DEMO.STORE schema. | ||
| Covers store sales, store returns, customers, stores and the shared calendar, | ||
| including profitability, discount, promotion and return-behavior metrics. | ||
| tables: |
| """ | ||
| Converts a Snowflake semantic view YAML definition into the a Power BI semantic model in Direct Lake mode. | ||
|
|
| if hasattr(yaml_file, "read"): | ||
| data = yaml.safe_load(yaml_file) | ||
| else: | ||
| data = yaml.safe_load(yaml_file) | ||
|
|
No description provided.