Fix metric expr dimensions + Druid dialect; refactor build_v3 shared architecture #1666
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes dimension replacement in derived metric expressions and outputs metric combiners in Druid dialect. It also refactors the build_v3 SQL generation to use a cleaner shared architecture.
Fix: Auto-detect dimensions from metric expressions
Metrics with expressions that referenced dimensions (e.g.,
LAG(...) OVER (ORDER BY week)) failed to generate correct SQL because the dimension in the ORDER BY clause wasn't being replaced with its alias.This change adds
add_dimensions_from_metric_expressions()to scan combiner ASTs for dimension references and add them toctx.dimensionsbefore SQL generation.Fix: Output metric_combiners in Druid dialect
The
metric_expressionstored in materialization config was output in Spark dialect, but since it is being materialized to Druid, most tools consuming it will need it to be in the Druid dialect.This change updates
combiners.pyto userender_for_dialect(...)when generating metric_combiners.Refactor: Clean shared architecture for SQL generation
Before this change,
build_measures_sqlandbuild_metrics_sqlhad duplicated setup code. The cube path and non-cube path were parallel implementations.With this change, here is the new setup:
Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan