-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Random improvements to random things in random places #25954
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
fcd72b0 to
d786ef3
Compare
c150ee3 to
592446f
Compare
592446f to
8c3f427
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces several cross-cutting refactorings and enhancements, including a unified numeric literal parser, caching for type signature translations, and cache-backed rule indexing, along with corresponding test and assertion updates.
- Consolidated numeric parsing logic into a new
NumericParserand updatedNumericParameterandLongLiteralto use it. - Added caches in
TypeSignatureTranslatorandRuleIndexfor performance; refactored parsing and lookup loops accordingly. - Updated test code to use more expressive AssertJ assertions and added a new parser test for underscored numeric parameters.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| core/trino-spi/src/main/java/io/trino/spi/block/BlockUtil.java | Removed unused checkValidPositions validation method |
| core/trino-parser/src/test/java/io/trino/sql/parser/TestTypeParser.java | Added a new assertion for foo(1_000, 2_000) ARRAY parsing |
| core/trino-parser/src/main/java/io/trino/sql/tree/NumericParser.java | Introduced NumericParser with underscore and base-prefix support |
| core/trino-parser/src/main/java/io/trino/sql/tree/NumericParameter.java | Stored and exposed parsed numeric value on parameters |
| core/trino-parser/src/main/java/io/trino/sql/tree/LongLiteral.java | Delegated numeric parsing to NumericParser |
| core/trino-parser/src/main/java/io/trino/sql/ReservedIdentifiers.java | Cached reserved identifiers set; switched to Locale.ENGLISH |
| core/trino-main/src/test/java/io/trino/sql/planner/iterative/TestRuleIndex.java | Switched from collect(toSet()) to AssertJ contains... assertions |
| core/trino-main/src/main/java/io/trino/sql/planner/iterative/ExpressionRewriteRuleSet.java | Replaced stream-based rewrite with loop and builder for clarity |
| core/trino-main/src/main/java/io/trino/sql/planner/iterative/RuleIndex.java | Reworked getCandidates to use an EvictableCache |
| core/trino-main/src/main/java/io/trino/sql/planner/iterative/IterativeOptimizer.java | Simplified rule-iteration loop |
| core/trino-main/src/main/java/io/trino/sql/analyzer/TypeSignatureTranslator.java | Added a cache for data-type parsing; improved identifier checks and caching |
Comments suppressed due to low confidence (2)
core/trino-parser/src/main/java/io/trino/sql/ReservedIdentifiers.java:127
- [nitpick] The method name isNotIdentifier is confusing since it returns true for reserved keywords. Consider renaming it to something like isReservedKeyword or isNonIdentifierKeyword for clarity.
private static boolean isNotIdentifier(String name)
core/trino-spi/src/main/java/io/trino/spi/block/BlockUtil.java:60
- [nitpick] The removal of checkValidPositions may break callers if this method was in use. If it’s no longer needed, consider cleaning up references or marking it as deprecated before removal.
static void checkValidPositions(boolean[] positions, int positionCount)
Copilot
AI
Jun 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrapping parseTypeSignature failures in a generic RuntimeException loses the original semanticException and TYPE_MISMATCH error code. Consider throwing a semanticException with the appropriate error code to preserve user-facing diagnostics.
| throw new RuntimeException(e); | |
| throw new TrinoException(TYPE_MISMATCH, e.getMessage(), e); |
core/trino-main/src/test/java/io/trino/sql/planner/iterative/TestRuleIndex.java
Outdated
Show resolved
Hide resolved
d332e0d to
728604f
Compare
|
Fuzzer driven development? |
core/trino-main/src/main/java/io/trino/sql/analyzer/TypeSignatureTranslator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/analyzer/TypeSignatureTranslator.java
Outdated
Show resolved
Hide resolved
core/trino-main/src/main/java/io/trino/sql/planner/iterative/RuleIndex.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
original looks nicer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but resizes the list instead of preallocating it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returns a new builder, expecting the specified number of elements to be added.
If expectedSize is exactly the number of elements added to the builder before ImmutableList.Builder.build is called, the builder is likely to perform better than an unsized builder() would have.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and the toImmutableList() is:
private static final Collector<Object, ?, ImmutableList<Object>> TO_IMMUTABLE_LIST =
Collector.of(
ImmutableList::builder,
ImmutableList.Builder::add,
ImmutableList.Builder::combine,
ImmutableList.Builder::build);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicer != more performant :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Meh - I doubt it matters at all, so I would keep nicer. I will not fight though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have we observed a measurable performance improvement? If not, then readability is more important.
core/trino-main/src/main/java/io/trino/server/InternalAuthenticationManager.java
Outdated
Show resolved
Hide resolved
losipiuk
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
x
NumericParameter with underscores was accepted in the grammar but not parsed correctly which caused expressions like `CAST(a AS CHAR(1_000))` to fail.
728604f to
784cb11
Compare
Description
Additional context and related issues
Release notes
( ) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text: