Skip to content

fix(query): align full outer USING nullability#19616

Open
sundy-li wants to merge 2 commits intodatabendlabs:mainfrom
sundy-li:fix/issue-19568-result-projection-nullable-int64
Open

fix(query): align full outer USING nullability#19616
sundy-li wants to merge 2 commits intodatabendlabs:mainfrom
sundy-li:fix/issue-19568-result-projection-nullable-int64

Conversation

@sundy-li
Copy link
Member

@sundy-li sundy-li commented Mar 25, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

  • Mark the visible USING/NATURAL join key as nullable for FULL OUTER JOIN so the planned result schema matches the hash-join output schema.
  • Replace the debug-only projection schema assertion with an internal error that reports the column name, index, and mismatched types.
  • Add a service regression test that checks the planned and executed schema for a FULL OUTER JOIN ... USING query.

Changes

  1. Updated resolve_using() in the join binder to preserve nullable result metadata for visible FULL OUTER JOIN keys.
  2. Updated build_result_projection() to return ErrorCode::Internal instead of panicking on schema mismatches.
  3. Added a regression test covering nullable INT64 output from FULL OUTER JOIN ... USING.

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Pair with the reviewer to explain why

Attempted:

  • cargo test -p databend-query --test it sql::schema::test_full_outer_join_using_reports_nullable_result_schema -- --exact

Blocked in this environment by missing toolchain dependencies:

  • clang/mold linker configuration from .cargo/config.toml
  • protoc required by databend-meta-types and databend-meta-proto build scripts

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Fixes #19568


This change is Reviewable

@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Mar 25, 2026
@sundy-li sundy-li added the agent-reviewable Ready for agent review label Mar 25, 2026
.nth(idx)
.collect::<Vec<_>>();

if matches!(join_op, JoinOperator::FullOuter)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For USING, unqualified name resolution keeps only the one binding whose visibility stays visible (see BindContext::match_column_binding), so this branch is still making x resolve to a single input column. For FULL OUTER JOIN, that is not the merged USING semantics: SELECT x FROM (SELECT 1 AS x) a FULL OUTER JOIN (SELECT 2 AS x) b USING (x) should surface 1, 2, but the surviving left-side binding yields 1, NULL on the right-only row. This patch aligns the schema with the current nullable left-column behavior instead of fixing the merged-key behavior. The fix needs to produce a coalesced visible USING expression (or equivalent) and the regression test should assert row values, not only the inferred type.

@sundy-li sundy-li added agent-approved Approved by agent agent-changed Changed by agent and removed agent-reviewable Ready for agent review agent-approved Approved by agent labels Mar 25, 2026
@sundy-li sundy-li added agent-reviewable Ready for agent review and removed agent-changed Changed by agent labels Mar 26, 2026
@github-actions
Copy link
Contributor

🤖 CI Job Analysis

Workflow: 23586788527

📊 Summary

  • Total Jobs: 86
  • Failed Jobs: 17
  • Retryable: 0
  • Code Issues: 17

NO RETRY NEEDED

All failures appear to be code/test issues requiring manual fixes.

🔍 Job Details

  • linux / test_unit: Not retryable (Code/Test)
  • linux / sqllogic / standalone_minio (query, hybrid, parquet): Not retryable (Code/Test)
  • linux / sqllogic / standalone_minio (query, http, parquet): Not retryable (Code/Test)
  • linux / sqllogic / standalone_minio (query, http, native): Not retryable (Code/Test)
  • linux / sqllogic / standalone_minio (query, hybrid, native): Not retryable (Code/Test)
  • linux / sqllogic / cluster (crdb, 2c, 2, http): Not retryable (Code/Test)
  • linux / sqllogic / cluster (duckdb, 4c, http): Not retryable (Code/Test)
  • linux / sqllogic / cluster (query, 4c, hybrid): Not retryable (Code/Test)
  • linux / sqllogic / cluster (crdb, 2c, 2, hybrid): Not retryable (Code/Test)
  • linux / sqllogic / standalone (query, 4c, http): Not retryable (Code/Test)
  • linux / sqllogic / cluster (query, 4c, http): Not retryable (Code/Test)
  • linux / sqllogic / standalone (query, 4c, hybrid): Not retryable (Code/Test)
  • linux / sqllogic / standalone (duckdb, 4c, http): Not retryable (Code/Test)
  • linux / sqllogic / cluster (duckdb, 4c, hybrid): Not retryable (Code/Test)
  • linux / sqllogic / standalone (crdb, 2c, hybrid): Not retryable (Code/Test)
  • linux / sqllogic / standalone (crdb, 2c, http): Not retryable (Code/Test)
  • linux / sqllogic / standalone (duckdb, 4c, hybrid): Not retryable (Code/Test)

🤖 About

Automated analysis using job annotations to distinguish infrastructure issues (auto-retried) from code/test issues (manual fixes needed).

.add_derived_column(join_key_name.clone(), (*left_column.data_type).clone());
let coalesced_scalar = ScalarExpr::FunctionCall(FunctionCall {
span: None,
func_name: "coalesce".to_string(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FunctionCall { func_name: "coalesce" } is not executable in this planner path. CI is failing with UnknownFunction: function coalesce does not exist, and the sqllogic failures point directly at NATURAL/FULL OUTER JOIN queries after this rewrite. Please build this expression through the normal type-check / function-resolution path (or use the internal scalar form that execution already understands) instead of hard-coding a raw FunctionCall here.

@sundy-li sundy-li added agent-approved Approved by agent and removed agent-reviewable Ready for agent review labels Mar 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved Approved by agent pr-bugfix this PR patches a bug in codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Result projection schema mismatch — Nullable(Int64) vs Int64

1 participant