Repository navigation
Conversation
… codes of SqlTypeName values collide SqlTypeMappingRules.Builder#add used the caller's set as the key of a Guava LoadingCache. SqlTypeAssignmentRule and SqlTypeCoercionRule pass one HashSet that they clear and refill between calls, so every cache entry was keyed by the same mutable object, and a set whose hash code equaled an earlier set's received the earlier set's source types. SqlTypeName is an enum, so a set's hash code is the sum of identity hash codes, which change from one JVM run to the next. The JVM option -XX:+UnlockExperimentalVMOptions -XX:hashCode=2 makes every identity hash code 1 and forces the collision: TIME became assignable from DATE only, CAST(DATE '1243-12-01' AS TIME) passed validation, and user-defined functions resolved to the wrong overload or to none, for example "No match found for function signature timeFun(<TIME>)". Builder#add now copies the set with Sets.immutableEnumSet before using it as a key, and interns equal sets in a plain HashMap: the builder is filled once, in a static initializer, so it needs neither eviction nor thread safety. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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-7893.
Why
SqlTypeMappingRules.Builder#addused the caller's set as the key of a GuavaLoadingCache.SqlTypeAssignmentRuleandSqlTypeCoercionRulepass oneHashSetthat they clear and refill between calls, so every cache entry was keyed by the same mutable object. A set whose hash code equaled an earlier set's received the earlier set's source types.SqlTypeNameis an enum, so the hash code of a set is a sum of identity hash codes, and whether two sets collide changes from one JVM run to the next.With
-XX:+UnlockExperimentalVMOptions -XX:hashCode=2, which makes every identity hash code 1, TIME becomes assignable from DATE only:CAST(DATE '1243-12-01' AS TIME)passes validation, and user-defined functions resolve to the wrong overload or to none (No match found for function signature timeFun(<TIME>)). 41 tests in:core:testfail that way (CI run from the CALCITE-7892 trial).What
Builder#addcopies the set withSets.immutableEnumSetbefore using it as a key and interns equal sets in a plainHashMap. The builder is filled once, in a static initializer, so it needs neither eviction nor thread safety. The validation path reads the sameMap<SqlTypeName, ImmutableSet<SqlTypeName>>withImmutableEnumSetvalues as before.Verification
SqlTypeUtilTest#testTypeMappingBuilderKeepsSourceTypesOfReusedSet(new) forces the collision with aHashSetwhosehashCode()is constant. Without the fix it fails withTIME=[DATE]where it expectsTIME=[TIME], and it needs no JVM option. With the fix, all 17089 tests of:core:testpass under-XX:hashCode=2on JDK 21:Adding a
hashCode=2axis to CI is left to CALCITE-7892.🤖 Generated with Claude Code