Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update aggregated conversion node to only have queried linkable specs #1381

Merged
merged 7 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ def post_aggregation_spec(self) -> MeasureSpec:
fill_nulls_with=self.fill_nulls_with,
)
else:
return self.measure_spec
return MeasureSpec(
element_name=self.measure_spec.element_name,
non_additive_dimension_spec=self.measure_spec.non_additive_dimension_spec,
fill_nulls_with=self.fill_nulls_with,
)


@dataclass(frozen=True)
Expand Down
17 changes: 16 additions & 1 deletion metricflow/dataflow/builder/dataflow_plan_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def _build_aggregated_conversion_node(
)

# Build measure recipes
base_required_linkable_specs, _ = self.__get_required_and_extraneous_linkable_specs(
base_required_linkable_specs, extraneous_linkable_specs = self.__get_required_and_extraneous_linkable_specs(
queried_linkable_specs=queried_linkable_specs,
filter_specs=base_measure_spec.filter_spec_set.all_filter_specs,
)
Expand Down Expand Up @@ -333,6 +333,11 @@ def _build_aggregated_conversion_node(
unaggregated_base_measure_node = JoinOnEntitiesNode.create(
left_node=unaggregated_base_measure_node, join_targets=base_measure_recipe.join_targets
)
if len(base_measure_spec.filter_spec_set.all_filter_specs) > 0:
unaggregated_base_measure_node = WhereConstraintNode.create(
parent_node=unaggregated_base_measure_node,
where_specs=base_measure_spec.filter_spec_set.all_filter_specs,
)
filtered_unaggregated_base_node = FilterElementsNode.create(
parent_node=unaggregated_base_measure_node,
include_specs=group_specs_by_type(required_local_specs)
Expand Down Expand Up @@ -372,6 +377,16 @@ def _build_aggregated_conversion_node(
predicate_pushdown_state=disabled_pushdown_state,
measure_recipe=recipe_with_join_conversion_source_node,
)
if not extraneous_linkable_specs.is_subset_of(queried_linkable_specs):
WilliamDee marked this conversation as resolved.
Show resolved Hide resolved
# At this point, it's the case that there are extraneous specs are not a subset of the queried
# linkable specs. A filter is needed after, say, a where clause so that the linkable specs in the where clause don't
# show up in the final result.
aggregated_conversions_node = FilterElementsNode.create(
parent_node=aggregated_conversions_node,
include_specs=InstanceSpecSet(measure_specs=(conversion_measure_spec.post_aggregation_spec,)).merge(
InstanceSpecSet.create_from_specs(queried_linkable_specs.as_tuple)
),
)

# Combine the aggregated opportunities and conversion data sets
return CombineAggregatedOutputsNode.create(
Expand Down