FrankChen021 opened a new pull request, #5284: URL: https://github.com/apache/calcite/pull/5284
## Jira Link [CALCITE-7805](https://issues.apache.org/jira/browse/CALCITE-7805) ## Changes Proposed String `RexLiteral` digest generation currently 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. Add `NlsString.asSql` overloads that append the escaped SQL representation to a caller-provided `StringBuilder`, and make the existing string-returning method delegate to the same implementation. `RexLiteral` uses the direct-write overload, keeping ANSI dialect selection, charset-prefix handling, and any future collation-suffix behavior encapsulated in `NlsString`. The new test covers the builder API directly, including appending to existing content, a charset prefix, and quote escaping. Existing `RexBuilderTest.testStringLiteral` coverage verifies that `RexLiteral` output remains unchanged. This branch is based directly on `main` at `38413ece6` and is independent of the other allocation optimizations. ## Isolated Benchmark Druid's `InPlanningBenchmark.queryStringInSqlPlanOnly` was run against a Calcite 1.42.0 + PR #5263 baseline and the same baseline with only this PR's production changes applied. The original Druid `DruidRexExecutor` was used in both variants, excluding Druid's separate literal-array optimization. | String literals | Allocation before | Allocation after | Allocation saved | Change | Time before | Time after | |---:|---:|---:|---:|---:|---:|---:| | 100,000 | 1,454.93 MiB/op | 1,419.20 MiB/op | 35.73 MiB/op | -2.46% | 747.87 ms/op | 774.54 ms/op | | 1,000,000 | 14,617.18 MiB/op | 14,425.79 MiB/op | 191.39 MiB/op | -1.31% | 7.632 s/op | 8.030 s/op | PR #7 reduced allocation for both sizes. The timing confidence intervals overlap, so these results do not establish a latency improvement or regression. Allocation is total allocated bytes per planning operation, not retained or peak heap. Benchmark parameters: `inSubQueryThreshold=2147483647`, `rowsPerSegment=500000`; 2 JMH forks, each with 2 one-second warmup iterations and 5 one-second measured iterations; GC profiler; Temurin 25.0.4.1. ## Validation - `./gradlew :core:test --tests org.apache.calcite.rex.RexBuilderTest.testStringLiteral --tests org.apache.calcite.util.UtilTest.testNlsStringAsSqlStringBuilder` - `./gradlew :core:autostyleJavaCheck :core:checkstyleMain :core:checkstyleTest` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
