Fix build_v3 Druid cube compatibility, dialect auto-detection, and pre-agg fan-out#1908
Merged
shangyian merged 11 commits intoDataJunction:mainfrom Mar 24, 2026
Merged
Conversation
✅ Deploy Preview for thriving-cassata-78ae72 canceled.
|
shangyian
commented
Mar 20, 2026
| # Handle LIMITED aggregability (COUNT DISTINCT). | ||
| # If the grain group was pre-aggregated (is_pre_aggregated=True), the wrapper CTE | ||
| # already computed COUNT(DISTINCT grain_key) and stored it as a named column. | ||
| # Emit SUM(pre_agg_col) — a no-op re-aggregation since the wrapper produces |
Collaborator
Author
There was a problem hiding this comment.
We have to aggregate to the right grain before we combine these metrics to remove chances of double counting.
…e state, and materialization type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 several related issues in v3 SQL generation.
Legacy Druid cube column names
When a cube was materialized using the legacy
DruidMaterializationJob(pre-DruidCubeMaterializationJob), physical column names in the Druid table use the amenable_name format (e.g. with_DOT_) rather than the short column name.build_synthetic_grain_groupnow readsmaterialization.config["combiners"][*]["columns"]to build a short name to physical column name lookup and applies it to bothSELECTprojections andWHEREclause references.Dialect-based table references
Druid SQL syntax does not support schema-qualified table names, so
build_synthetic_grain_groupnow emitsschema.tablefor Druid andcatalog.schema.tablefor all other dialects.Dialect defaults
Previously,
dialect=Nonewas silently normalized to SPARK before the cube-path check, causingdialect=Nonerequests to skip the materialized cube path entirely. The resolver now picks the fastest available engine tier: Druid (if a matching cube exists), then Trino, then Spark. This is documented in_ENGINE_TIER_PREFERENCE.Pre-agg wrapper CTEs
Adds
_build_pre_agg_wrapper_cteto prevent fan-out when a LIMITED aggregability metric is combined with a pre-aggregated grain group, wrapping the pre-agg source in a CTE that aggregates it to the right grain before joining.Test Plan
make checkpassesmake testshows 100% unit test coverageDeployment Plan