From 9db7d2e43662d350c967a073c8b3db1f370c2bf1 Mon Sep 17 00:00:00 2001 From: Will Deng Date: Tue, 30 Jul 2024 14:29:16 -0400 Subject: [PATCH] added description to validation task --- .../validation/data_warehouse_model_validator.py | 14 ++++++++++++-- .../validation/test_data_warehouse_tasks.py | 8 ++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/metricflow/validation/data_warehouse_model_validator.py b/metricflow/validation/data_warehouse_model_validator.py index 8ed5360353..ffc0e89190 100644 --- a/metricflow/validation/data_warehouse_model_validator.py +++ b/metricflow/validation/data_warehouse_model_validator.py @@ -87,6 +87,7 @@ class DataWarehouseValidationTask: query_and_params_callable: Callable[[], Tuple[str, SqlBindParameters]] error_message: str + description: str context: Optional[ValidationContext] = None on_fail_subtasks: List[DataWarehouseValidationTask] = field(default_factory=lambda: []) @@ -155,6 +156,7 @@ def gen_semantic_model_tasks( semantic_model=SemanticModelReference(semantic_model_name=semantic_model.name), ), error_message=f"Unable to access semantic model `{semantic_model.name}` in data warehouse", + description=f"Validating semantic_model {semantic_model.name}", ) ) @@ -236,6 +238,7 @@ def gen_dimension_tasks( element_type=SemanticModelElementType.DIMENSION, ), error_message=f"Unable to query dimension `{spec.qualified_name}` on semantic model `{semantic_model.name}` in data warehouse", + description=f"Validating dimension `{spec.qualified_name}` in semantic_model `{semantic_model.name}`", ) ) @@ -261,6 +264,7 @@ def gen_dimension_tasks( ), error_message=f"Failed to query dimensions in data warehouse for semantic model `{semantic_model.name}`", on_fail_subtasks=semantic_model_sub_tasks, + description=f"Validating all dimensions in semantic_model `{semantic_model.name}`", ) ) return tasks @@ -317,6 +321,7 @@ def gen_entity_tasks( element_type=SemanticModelElementType.ENTITY, ), error_message=f"Unable to query entity `{spec.element_name}` on semantic model `{semantic_model.name}` in data warehouse", + description=f"Validating entity `{spec.element_name}` in semantic_model `{semantic_model.name}`", ) ) @@ -341,6 +346,7 @@ def gen_entity_tasks( ), error_message=f"Failed to query entities in data warehouse for semantic model `{semantic_model.name}`", on_fail_subtasks=semantic_model_sub_tasks, + description=f"Validating all entities in semantic_model `{semantic_model.name}`", ) ) return tasks @@ -413,6 +419,7 @@ def gen_measure_tasks( element_type=SemanticModelElementType.MEASURE, ), error_message=f"Unable to query measure `{spec.element_name}` on semantic model `{semantic_model.name}` in data warehouse", + description=f"Validating measure `{spec.element_name}` in semantic_model `{semantic_model.name}`", ) ) @@ -435,6 +442,7 @@ def gen_measure_tasks( ), error_message=f"Failed to query measures in data warehouse for semantic model `{semantic_model.name}`", on_fail_subtasks=source_node_to_sub_task[source_node], + description=f"Validating all measures in semantic_model `{semantic_model.name}`", ) ) return tasks @@ -478,7 +486,8 @@ def gen_metric_tasks( file_context=FileContext.from_metadata(metadata=metric.metadata), metric=MetricModelReference(metric_name=metric.name), ), - error_message=f"Unable to query metric `{metric.name}`.", + error_message=f"Unable to query metric `{metric.name}`", + description=f"Validating metric `{metric.name}`", ) ) return tasks @@ -513,7 +522,8 @@ def gen_saved_query_tasks( element_type=SavedQueryElementType.METRIC, element_value=saved_query.name, ), - error_message=f"Unable to query saved query `{saved_query.name}`.", + error_message=f"Unable to query saved query `{saved_query.name}`", + description=f"Validating saved_query `{saved_query.name}`", ) ) return tasks diff --git a/tests_metricflow/validation/test_data_warehouse_tasks.py b/tests_metricflow/validation/test_data_warehouse_tasks.py index b79ae1df56..7047d26126 100644 --- a/tests_metricflow/validation/test_data_warehouse_tasks.py +++ b/tests_metricflow/validation/test_data_warehouse_tasks.py @@ -63,7 +63,9 @@ def good_query() -> Tuple[str, SqlBindParameters]: return ("SELECT 'foo' AS foo", SqlBindParameters()) tasks = [ - DataWarehouseValidationTask(query_and_params_callable=good_query, error_message="Could not select foo"), + DataWarehouseValidationTask( + query_and_params_callable=good_query, description="Validating foo", error_message="Could not select foo" + ), ] issues = dw_validator.run_tasks(tasks=tasks) @@ -73,7 +75,9 @@ def bad_query() -> Tuple[str, SqlBindParameters]: return ("SELECT (true) AS col1 FROM doesnt_exist", SqlBindParameters()) err_msg_bad = "Could not access table 'doesnt_exist' in data warehouse" - bad_task = DataWarehouseValidationTask(query_and_params_callable=bad_query, error_message=err_msg_bad) + bad_task = DataWarehouseValidationTask( + query_and_params_callable=bad_query, description="Validating foo", error_message=err_msg_bad + ) tasks.append(bad_task) issues = dw_validator.run_tasks(tasks=tasks)