[CALCITE-7632] Replace java.util.Stack with java.util.ArrayDeque in Pattern and TopDownRuleDriver#5062
Merged
mihaibudiu merged 1 commit intoJul 1, 2026
Conversation
…attern and TopDownRuleDriver Replace java.util.Stack (which extends Vector and provides unnecessary synchronized access) with java.util.ArrayDeque in: - runtime/Pattern.java: PatternBuilder.stack field - plan/volcano/TopDownRuleDriver.java: tasks field Also remove @SuppressWarnings("JdkObsolete") annotations and TODO comments that requested this change. Stack is officially discouraged by the Java documentation, which recommends using Deque implementations like ArrayDeque instead. ArrayDeque is faster for single-threaded use since it avoids the synchronization overhead inherited from Vector.
|
Contributor
|
I cannot see this issue in the JIRA, does it exist? |
Contributor
|
This looks fine, but I'd like to see the issue addressed before commenting. |
Contributor
Author
|
Hi @mihaibudiu, thanks for reviewing. The JIRA issue has been created: CALCITE-7632 Sorry for the earlier confusion — the issue was not created at the time the PR was opened. |
mihaibudiu
approved these changes
Jul 1, 2026
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.



Summary
Replace
java.util.Stackwithjava.util.ArrayDequein two locations, completing a TODO left in place since 2020.Background
In CALCITE-4314 (commit e537246), Vladimir Sitnikov enabled Error Prone checking for the Calcite codebase. As part of that effort, he identified 2 remaining
java.util.Stackusages as obsolete and added@SuppressWarnings("JdkObsolete")with// TODO: replace with Dequeto suppress warnings. The commit message explicitly stated "It should be replaced with Deque", but the actual refactoring was deferred.CALCITE-4314 was a broad static-analysis enablement issue — the Stack→Deque replacement was too granular to be tracked there specifically. This PR creates a dedicated issue (CALCITE-7632) to properly track and complete that deferred work.
Changes
core/src/main/java/org/apache/calcite/runtime/Pattern.java:Stack<Pattern>→Deque<Pattern>inPatternBuilder.stackfield (used for SQLMATCH_RECOGNIZENFA pattern matching)core/src/main/java/org/apache/calcite/plan/volcano/TopDownRuleDriver.java:Stack<Task>→Deque<Task>in task queue (used for Volcano optimizer top-down Cascades-style optimization)Also removed the corresponding
@SuppressWarnings("JdkObsolete")annotations and// TODO: replace with Dequecomments.Rationale
java.util.StackextendsVector— all methods aresynchronized, adding unnecessary lock overhead in single-threaded contextsArrayDequeis non-synchronized, officially recommended by the Java documentation as a replacement forStackJdkObsoletewarnings without suppressionArrayDequedoubles capacity on resize vsVector's linear growthTesting
BUILD SUCCESSFULjava.util.Stackreferences incore/src/mainRelated