fix(schema-compiler): Use isNotDistinctFrom() for ClickHouse Tesseract multi-fact joins#10494
Open
rclapp wants to merge 4 commits intocube-js:masterfrom
Open
fix(schema-compiler): Use isNotDistinctFrom() for ClickHouse Tesseract multi-fact joins#10494rclapp wants to merge 4 commits intocube-js:masterfrom
rclapp wants to merge 4 commits intocube-js:masterfrom
Conversation
…t multi-fact joins ClickHouse does not support OR/IS NULL patterns in JOIN ON clauses, which causes Tesseract multi-fact queries to fail. Add support for a function-style is_not_distinct_from expression template and register ClickHouse's isNotDistinctFrom() function as the implementation. Fixes cube-js#10493 Co-Authored-By: Claude Opus 4.6 <[email protected]>
… fallback paths Tests all three code paths in join_by_dimension_conditions: - Binary operator (Postgres/BigQuery/Snowflake: IS NOT DISTINCT FROM) - Expression template (ClickHouse: isNotDistinctFrom() function) - OR (IS NULL AND IS NULL) fallback - Binary operator takes precedence when both templates exist - No null check produces simple equality Co-Authored-By: Claude Opus 4.6 <[email protected]>
Remove 4 stale snapshot files that are no longer referenced by any test, causing CI to fail with "unreferenced snapshots" error. Co-Authored-By: Claude Opus 4.6 <[email protected]>
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
Cannot determine join keys in JOIN ON expressionerrorexpressions/is_not_distinct_fromtemplate as a fallback when the binary operatoroperators/is_not_distinct_fromis not availableisNotDistinctFrom(left, right)function via the new expression templateFixes #10493
Context
When
CUBEJS_TESSERACT_SQL_PLANNER=trueis enabled, multi-fact queries (measures from multiple cubes) generate null-safe JOIN conditions usingOR (IS NULL AND IS NULL):ClickHouse rejects this — it requires simple equality or function calls in
JOIN ONclauses.Other dialects (Postgres, BigQuery, Snowflake) use the
IS NOT DISTINCT FROMbinary operator, but ClickHouse's equivalent is the functionisNotDistinctFrom(a, b)— not a binary operator. The existingoperators/is_not_distinct_fromtemplate only supports binary operator syntax via theexpressions/binarytemplate ({{ left }} {{ op }} {{ right }}).Changes
Rust (
rust/cubesqlplanner/cubesqlplanner/src/planner/sql_templates/plan.rs):supports_is_not_distinct_from_expr()check forexpressions/is_not_distinct_fromtemplatejoin_by_dimension_conditions(), added fallback path: check binary operator first, then expression template, then existingOR (IS NULL AND IS NULL)fallbackTypeScript (
packages/cubejs-schema-compiler/src/adapter/ClickHouseQuery.ts):expressions.is_not_distinct_from = 'isNotDistinctFrom({{ left }}, {{ right }})'insqlTemplates()This is minimally invasive — existing dialects continue using the
operators/is_not_distinct_frombinary operator path unchanged.Check List
Test results
Rust (
cargo test): 373 passed, 0 failed (368 existing + 5 new)Rust (
cargo fmt --check): No formatting issuesNew unit tests (
plan::tests::test_join_condition_*):test_join_condition_no_null_check— simple equality without null handlingtest_join_condition_null_check_fallback_or_is_null— OR/IS NULL fallback (no templates)test_join_condition_null_check_binary_operator— Postgres/BigQuery/Snowflake pathtest_join_condition_null_check_expression_template— ClickHouseisNotDistinctFrom()pathtest_join_condition_binary_operator_takes_precedence_over_expression— priority orderingManual validation: Took the exact SQL Tesseract generates for 2-fact and 4-fact multi-fact queries, replaced the
OR (IS NULL AND IS NULL)join conditions withisNotDistinctFrom(), and verified all queries execute correctly against ClickHouse.🤖 Generated with Claude Code