-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Script for populating all persistent source schemas
- Loading branch information
1 parent
043bbbb
commit 07d9d5d
Showing
3 changed files
with
63 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Script to help generate persistent source schemas with test data for all relevant engines.""" | ||
|
||
from __future__ import annotations | ||
|
||
import logging | ||
import os | ||
|
||
from dbt_semantic_interfaces.enum_extension import assert_values_exhausted | ||
|
||
from metricflow.protocols.sql_client import SqlEngine | ||
from metricflow.test.generate_snapshots import ( | ||
MetricFlowTestConfiguration, | ||
run_cli, | ||
run_command, | ||
set_engine_env_variables, | ||
) | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def populate_schemas(test_configuration: MetricFlowTestConfiguration) -> None: # noqa: D | ||
set_engine_env_variables(test_configuration) | ||
|
||
if test_configuration.engine is SqlEngine.DUCKDB or test_configuration.engine is SqlEngine.POSTGRES: | ||
# DuckDB & Postgres don't use persistent source schema | ||
return None | ||
elif ( | ||
test_configuration.engine is SqlEngine.SNOWFLAKE | ||
or test_configuration.engine is SqlEngine.BIGQUERY | ||
or test_configuration.engine is SqlEngine.DATABRICKS | ||
or test_configuration.engine is SqlEngine.REDSHIFT | ||
): | ||
engine_name = test_configuration.engine.value.lower() | ||
os.environ["MF_TEST_ADAPTER_TYPE"] = engine_name | ||
hatch_env = f"{engine_name}-env" | ||
run_command( | ||
f"hatch -v run {hatch_env}:pytest -vv --use-persistent-source-schema " | ||
"metricflow/test/source_schema_tools.py::populate_source_schema" | ||
) | ||
else: | ||
assert_values_exhausted(test_configuration.engine) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_cli(populate_schemas) |