Skip to content

Commit

Permalink
Add test for filtering by the same metric you're querying
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Apr 23, 2024
1 parent c4487f4 commit 96408a8
Show file tree
Hide file tree
Showing 4 changed files with 521 additions and 2 deletions.
1 change: 0 additions & 1 deletion metricflow/model/semantics/linkable_spec_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,6 @@ def _get_joinable_metrics_for_semantic_model(
f"Got semantic model: {semantic_model.reference.semantic_model_name}; "
f"last join path element: {using_join_path.last_semantic_model_reference.semantic_model_name}",
)
# TODO: confirm that this is what we internally consider multi-hop
properties = properties.union(frozenset({LinkableElementProperty.MULTI_HOP}))

path_key_to_linkable_metrics: Dict[ElementPathKey, Tuple[LinkableMetric, ...]] = {}
Expand Down
26 changes: 25 additions & 1 deletion tests/query_rendering/test_metric_filter_rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,28 @@ def test_distinct_values_query_with_metric_filter(
)


# TODO: tests for filters with conversion metrics
@pytest.mark.sql_engine_snapshot
def test_metric_filtered_by_itself(
request: FixtureRequest,
mf_test_configuration: MetricFlowTestConfiguration,
dataflow_plan_builder: DataflowPlanBuilder,
sql_client: SqlClient,
dataflow_to_sql_converter: DataflowToSqlQueryPlanConverter,
query_parser: MetricFlowQueryParser,
) -> None:
"""Tests a query for a metric that filters by the same metric."""
query_spec = query_parser.parse_and_validate_query(
metric_names=("bookers",),
where_constraint=PydanticWhereFilter(
where_sql_template="{{ Metric('bookers', ['guest']) }} > 1.00",
),
)
dataflow_plan = dataflow_plan_builder.build_plan(query_spec)

convert_and_check(
request=request,
mf_test_configuration=mf_test_configuration,
dataflow_to_sql_converter=dataflow_to_sql_converter,
sql_client=sql_client,
node=dataflow_plan.sink_output_nodes[0].parent_node,
)
Loading

0 comments on commit 96408a8

Please sign in to comment.