You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[CALCITE-7810] Write Rex string literal digests directly - #5284
String RexLiteral digest generation asks NlsString to build a complete SQL string and then copies that temporary string into the destination builder. Large literal ARRAYs repeat this allocation for every element.
In Druid's string-IN planning benchmark, writing directly to the destination reduced allocation by 2.46% at 100,000 literals and 1.31% at 1,000,000 literals. Timing confidence intervals overlapped, so no latency improvement is claimed.
What
Add NlsString.asSql overloads that append the escaped SQL representation to a caller-provided StringBuilder. The existing string-returning method delegates to the same implementation, and RexLiteral uses the direct-write overload.
ANSI dialect selection, charset prefixes, quote escaping, and collation suffix handling remain encapsulated in NlsString.
Verification
UtilTest.testNlsStringAsSqlStringBuilder covers appending to existing content, charset prefixes, and quote escaping.
Druid InPlanningBenchmark.queryStringInSqlPlanOnly with -prof gc
Druid benchmark results
String literals
Allocation before
Allocation after
Reduction
100,000
1,454.93 MiB/op
1,419.20 MiB/op
35.73 MiB/op (2.46%)
1,000,000
14,617.18 MiB/op
14,425.79 MiB/op
191.39 MiB/op (1.31%)
Configuration: inSubQueryThreshold=2147483647, rowsPerSegment=500000, 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 ubenchmark is not yet included.
Scope
This change affects string RexLiteral digest construction only; it does not change the produced SQL representation.
Why are you submitting multiple PRs using the same Jira ticket number? Please consult the contributor's guide first.
I would like to point out that based on the document, I don't see any statement that a JIRA ticket number can only be used by one PR. If I miss sth, you're welcome to point out.
@FrankChen021 thanks for the contribution.
In this case, I'd say it's recommendable to create sub-tasks under the main Jira ticket, and attach each PR to each one of the sub-tasks.
FrankChen021
changed the title
[CALCITE-7805] Write Rex string literal digests directly
[CALCITE-7810] Write Rex string literal digests directly
Sep 22, 2026
@FrankChen021 thanks for the contribution. In this case, I'd say it's recommendable to create sub-tasks under the main Jira ticket, and attach each PR to each one of the sub-tasks.
This sounds good to me.
Updated as you suggested. Thanks.
The reason will be displayed to describe this comment to others. Learn more.
-1 slop
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
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-7810.
Why
String
RexLiteraldigest generation asksNlsStringto build a complete SQL string and then copies that temporary string into the destination builder. Large literal ARRAYs repeat this allocation for every element.In Druid's string-IN planning benchmark, writing directly to the destination reduced allocation by 2.46% at 100,000 literals and 1.31% at 1,000,000 literals. Timing confidence intervals overlapped, so no latency improvement is claimed.
What
Add
NlsString.asSqloverloads that append the escaped SQL representation to a caller-providedStringBuilder. The existing string-returning method delegates to the same implementation, andRexLiteraluses the direct-write overload.ANSI dialect selection, charset prefixes, quote escaping, and collation suffix handling remain encapsulated in
NlsString.Verification
UtilTest.testNlsStringAsSqlStringBuildercovers appending to existing content, charset prefixes, and quote escaping.RexBuilderTest.testStringLiteralverifies unchangedRexLiteraloutput../gradlew :core:test --tests org.apache.calcite.rex.RexBuilderTest.testStringLiteral --tests org.apache.calcite.util.UtilTest.testNlsStringAsSqlStringBuilder./gradlew :core:autostyleJavaCheck :core:checkstyleMain :core:checkstyleTestInPlanningBenchmark.queryStringInSqlPlanOnlywith-prof gcDruid benchmark results
Configuration:
inSubQueryThreshold=2147483647,rowsPerSegment=500000, 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 affects string
RexLiteraldigest construction only; it does not change the produced SQL representation.