Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
courtneyholcomb committed Nov 6, 2023
1 parent 38adb04 commit dd3e2ed
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ install-hatch:
test:
hatch -v run dev-env:pytest -vv -n $(PARALLELISM) $(ADDITIONAL_PYTEST_OPTIONS) metricflow/test/

# Run tests until first failure
.PHONY: testx
testx:
make test ADDITIONAL_PYTEST_OPTIONS=-x

.PHONY: test-postgresql
test-postgresql:
hatch -v run postgres-env:pytest -vv -n $(PARALLELISM) $(ADDITIONAL_PYTEST_OPTIONS) metricflow/test/
Expand Down
18 changes: 18 additions & 0 deletions metricflow/plan_conversion/dataflow_to_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@ def visit_compute_metrics_node(self, node: ComputeMetricsNode) -> SqlDataSet:
MetricInstance(
associated_columns=(output_column_association,),
defined_from=(MetricModelReference(metric_name=metric_spec.element_name),),
# Here we remove element name in favor of alias
spec=metric_spec.alias_spec,
)
)
Expand Down Expand Up @@ -894,6 +895,23 @@ def _make_select_columns_for_metrics(
else:
select_expression = column_reference_expression

input_measures = self._metric_lookup.measures_for_metric(
# Using alias instead of element name in reference, where did we lose the name?
metric_reference=metric_spec.as_reference,
column_association_resolver=self._column_association_resolver,
)
# TODO: update to singular after other PR merges
if input_measures:
input_measure = input_measures[0]
if input_measure.fill_nulls_with is not None:
select_expression = SqlAggregateFunctionExpression(
sql_function=SqlFunction.COALESCE,
sql_function_args=[
select_expression,
SqlStringExpression(str(input_measure.fill_nulls_with)),
],
)

select_columns.append(
SqlSelectColumn(
expr=select_expression,
Expand Down
2 changes: 1 addition & 1 deletion metricflow/specs/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ def from_reference(reference: MetricReference) -> MetricSpec:

@property
def alias_spec(self) -> MetricSpec:
"""Returns a MetricSpec represneting the alias state."""
"""Returns a MetricSpec representing the alias state."""
return MetricSpec(
element_name=self.alias or self.element_name,
constraint=self.constraint,
Expand Down

0 comments on commit dd3e2ed

Please sign in to comment.