Hello Aman Sinha, Wellington Cabrera, Joe McDonnell, Steve Carlin, Michael
Smith, Impala Public Jenkins,
I'd like you to reexamine a change. Please visit
https://gerrit.cloudera.org/25432
to look at the new patch set (#3).
Change subject: IMPALA-15399: Fix NULL result type for NULL operands in Calcite
......................................................................
IMPALA-15399: Fix NULL result type for NULL operands in Calcite
With the Calcite planner, some expressions on NULL operands return
the NULL type instead of the type the original planner returns:
- NULL * NULL (also +, -, / and %) returns NULL instead of DOUBLE.
- FALSE || NULL and NULL || NULL return NULL instead of BOOLEAN.
For arithmetic, ImpalaTypeSystemImpl.deriveArithmeticType calls
TypesUtil.getArithmeticResultType, which returns NULL when both
operands are NULL. ArithmeticExpr in the original planner defaults
that case to DOUBLE, so the backend never sees NULL_TYPE. This patch
adds the same DOUBLE default to deriveArithmeticType. Function
resolution then picks the DOUBLE version of the operator and casts
the NULL operands to DOUBLE.
For ||, ImpalaConcatOrOperator correctly infers BOOLEAN when both
operands are BOOLEAN or NULL, and ImpalaConvertletTable converts the
call to OR(FALSE, null:NULL), typed BOOLEAN. However, unlike the
standard OR operator, || does not infer operand types, so the NULL
literal keeps the NULL type. CoerceNodes.processRexNodes then calls
RexUtil.pullFactors and RexUtil.toCnf. These drop FALSE and duplicate
operands from the OR, and when only one operand is left they return
it as is. The expression then becomes the NULL literal and its type
changes from BOOLEAN to NULL.
CoerceOperandShuttle now casts the NULL typed operands of AND and OR
calls to the type of the call (BOOLEAN). This runs before pullFactors
and toCnf, so a collapsed expression keeps the BOOLEAN type. The
CONCAT path is unchanged.
Testing:
- Added a test to QueryTest/calcite.test that checks the result types
of NULL * NULL, NULL + NULL, NULL / NULL, NULL % NULL,
FALSE || NULL and NULL || NULL.
- Ran test_calcite_planner.py::test_calcite_frontend.
- Ran CalcitePlannerTest.
- Ran expr-test ArithmeticExprs, CompoundPredicates and
CompoundVerticalBarExpr locally, with expr-test forced to use the
Calcite planner. The NULL operand type failures are gone.
Change-Id: If8ac369da47fd63988569780c2315caebdab957c
Assisted-by: Claude Opus (Claude Code)
---
M
java/calcite-planner/src/main/java/org/apache/impala/calcite/coercenodes/CoerceOperandShuttle.java
M
java/calcite-planner/src/main/java/org/apache/impala/calcite/type/ImpalaTypeSystemImpl.java
M testdata/workloads/functional-query/queries/QueryTest/calcite.test
3 files changed, 42 insertions(+), 0 deletions(-)
git pull ssh://gerrit.cloudera.org:29418/Impala-ASF refs/changes/32/25432/3
--
To view, visit https://gerrit.cloudera.org/25432
To unsubscribe, visit https://gerrit.cloudera.org/settings
Gerrit-Project: Impala-ASF
Gerrit-Branch: master
Gerrit-MessageType: newpatchset
Gerrit-Change-Id: If8ac369da47fd63988569780c2315caebdab957c
Gerrit-Change-Number: 25432
Gerrit-PatchSet: 3
Gerrit-Owner: Wellington Cabrera <[email protected]>
Gerrit-Reviewer: Aman Sinha <[email protected]>
Gerrit-Reviewer: Impala Public Jenkins <[email protected]>
Gerrit-Reviewer: Joe McDonnell <[email protected]>
Gerrit-Reviewer: Michael Smith <[email protected]>
Gerrit-Reviewer: Steve Carlin <[email protected]>
Gerrit-Reviewer: Wellington Cabrera (968)