diff --git a/metricflow/dataflow/builder/dataflow_plan_builder.py b/metricflow/dataflow/builder/dataflow_plan_builder.py index f413aec44..c7cdc5ebb 100644 --- a/metricflow/dataflow/builder/dataflow_plan_builder.py +++ b/metricflow/dataflow/builder/dataflow_plan_builder.py @@ -1482,10 +1482,12 @@ def __get_required_linkable_specs( required_linkable_specs = queried_linkable_specs.merge(extraneous_linkable_specs).dedupe() # Custom grains require joining to their base grain, so add base grain to extraneous specs. - base_grain_set = LinkableSpecSet.create_from_specs( - [spec.with_base_grain() for spec in required_linkable_specs.time_dimension_specs_with_custom_grain] - ) - extraneous_linkable_specs = extraneous_linkable_specs.merge(base_grain_set).dedupe() + if required_linkable_specs.time_dimension_specs_with_custom_grain: + base_grain_set = LinkableSpecSet.create_from_specs( + [spec.with_base_grain() for spec in required_linkable_specs.time_dimension_specs_with_custom_grain] + ) + extraneous_linkable_specs = extraneous_linkable_specs.merge(base_grain_set).dedupe() + required_linkable_specs = required_linkable_specs.merge(extraneous_linkable_specs).dedupe() return required_linkable_specs @@ -1761,7 +1763,7 @@ def _build_pre_aggregation_plan( if measure_properties and measure_properties.non_additive_dimension_spec: if queried_linkable_specs is None: raise ValueError( - "`queried_linkable_specs` must be provided in _build_pre_aggregation_plan() if " + "`queried_linkable_specs` must be provided in when building pre-aggregation plan if " "`non_additive_dimension_spec` is present." ) output_node = self._build_semi_additive_join_node( @@ -1769,7 +1771,6 @@ def _build_pre_aggregation_plan( queried_linkable_specs=queried_linkable_specs, parent_node=output_node, ) - output_node = FilterElementsNode.create( parent_node=output_node, include_specs=filter_to_specs, distinct=distinct ) diff --git a/metricflow/dataflow/builder/node_evaluator.py b/metricflow/dataflow/builder/node_evaluator.py index 63bda2ceb..fbc11da09 100644 --- a/metricflow/dataflow/builder/node_evaluator.py +++ b/metricflow/dataflow/builder/node_evaluator.py @@ -122,7 +122,7 @@ def join_description(self) -> JoinDescription: ) filtered_node_to_join = FilterElementsNode.create( - parent_node=self.node_to_join, include_specs=group_specs_by_type(include_specs) + parent_node=self.node_to_join, include_specs=group_specs_by_type(include_specs).dedupe() ) return JoinDescription( diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0.sql index 545235e18..10b057d2c 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0.sql @@ -429,7 +429,7 @@ FROM ( ) subq_0 ) subq_1 LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] + -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing'] SELECT subq_3.listing , subq_3.is_lux_latest @@ -841,7 +841,7 @@ FULL OUTER JOIN ( ) subq_10 ) subq_11 LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] + -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing'] SELECT subq_13.listing , subq_13.is_lux_latest @@ -1419,7 +1419,7 @@ FULL OUTER JOIN ( ) subq_20 ) subq_21 LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] + -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing'] SELECT subq_23.listing , subq_23.is_lux_latest @@ -1831,7 +1831,7 @@ FULL OUTER JOIN ( ) subq_30 ) subq_31 LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] + -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing'] SELECT subq_33.listing , subq_33.is_lux_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql index 8f6e97df8..3c1c49963 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql @@ -425,7 +425,7 @@ FROM ( ) subq_0 ) subq_1 LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing'] SELECT subq_3.listing , subq_3.country_latest