[CALCITE-7806] Avoid resolving generated CAST calls during array validation - #5280
Open
FrankChen021 wants to merge 1 commit into
Open
FrankChen021 wants to merge 1 commit into
FrankChen021 wants to merge 1 commit into
Conversation
|
mihaibudiu
reviewed
Oct 1, 2026
| SqlCall cast = (SqlCall) castTo(operands.get(i), elementType); | ||
| // This CAST was generated with the built-in operator; validate its | ||
| // operands directly instead of resolving the function again by name. | ||
| cast.getOperator().validateOperands( |
Contributor
There was a problem hiding this comment.
You seem to do strictly more work than before.
This looks correct, but does not seem more efficient.
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.



Fixes CALCITE-7806.
Why
ARRAY and MAP validation creates CAST calls when operands must be adjusted to a common element type. These calls already contain Calcite's built-in CAST operator, but a later
deriveTyperesolves the same operator by name for every generated CAST, allocating temporary operand and argument-type lists along the way.In Druid's string-IN planning benchmark, avoiding that repeated lookup reduced allocation by 19.95% at 100,000 literals and 20.48% at 1,000,000 literals. Timing confidence intervals overlapped, so no latency improvement is claimed.
What
Before this change:
With this change:
This preserves CAST operand validation and return-type inference while avoiding resolution of an operator that is already known.
Verification
SqlValidatorTestverifies that a generated CAST is registered and that a laterderiveTypeperforms no operator-table lookup../gradlew :core:test --tests org.apache.calcite.test.SqlValidatorTest :core:autostyleJavaCheck :core:checkstyleTest(596 completed, 0 failed, 7 skipped)InPlanningBenchmark.queryStringInSqlPlanOnlywith-prof gcDruid benchmark results
Configuration: 2 forks, 2 one-second warmup iterations, and 5 one-second measurement iterations. Allocation is cumulative bytes per operation, not retained or peak heap.
The performance measurement currently comes from Druid; a Calcite-local
ubenchmarkis not yet included.Scope
This change applies only to CAST calls generated while adjusting ARRAY and MAP constructor operands. It does not change CAST semantics or user-written CAST validation.