Skip to content

Fix nullable AND results in tree-model CASE - #18875

Open
ColinLeeo wants to merge 1 commit into
apache:masterfrom
ColinLeeo:fix/tree-case-nullable-and
Open

ColinLeeo wants to merge 1 commit into
apache:masterfrom
ColinLeeo:fix/tree-case-nullable-and

Conversation

@ColinLeeo

Copy link
Copy Markdown
Collaborator

Tree-model CASE can take the wrong branch when a later WHEN contains nullable AND. For example, when s1 is NULL and s2 is 1, CASE WHEN s1 > 100 THEN 1 WHEN s1 > 0 AND s2 > 0 THEN 2 ELSE 3 END returns 2 instead of 3.

LogicAndColumnTransformer.evaluateWithSelection() builds the correct three-valued AND result but caches the right operand. Cache the built result instead. This is a one-line production change and requires no cache-lifecycle or selection API changes.

Regression coverage includes all nine NULL/false/true operand combinations with full and partial selection masks, plus the CASE SQL example with NULL, true, false, and earlier-branch rows.

Closes #18864.

Validation:

  • Maven reactor verify from master 8effe5d6ce, selecting only LogicBinaryColumnTransformerTest (5 tests) and IoTDBCaseWhenThenIT#testNullableAndInLaterCaseBranch (1 test, rebuilt 1C1D nodes): passed.
  • Class-isolated comparison using the same unit-test runtime and master implementation: both newly added unit tests fail before the production change; all 5 pass after it.
  • Spotless, Checkstyle, and license checks: passed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved review issues remain, and validation passed.

0 open findings

What changed in this PR

Fixes nullable three-valued AND evaluation in tree-model CASE expressions by caching the computed result.

Changes:

  • Corrects LogicAndColumnTransformer caching.
  • Adds nullable AND unit coverage.
  • Adds a CASE integration regression test.
File Description
iotdb-core/​datanode/​src/​test/​java/​org/​apache/​iotdb/​db/​queryengine/​transformation/​dag/​column/​binary/​LogicBinaryColumnTransformerTest.java Tests nullable AND combinations and selection masks.
iotdb-core/​calc-commons/​src/​main/​java/​org/​apache/​iotdb/​calc/​transformation/​dag/​column/​binary/​LogicAndColumnTransformer.java Caches the computed AND result.
integration-test/​src/​test/​java/​org/​apache/​iotdb/​db/​it/​query/​IoTDBCaseWhenThenIT.java Adds SQL-level regression coverage.

🧠 Review effort: Lite


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Tree-model CASE selects a branch when nullable AND should be NULL

3 participants