fix: widen narrow numeric literals in zonemap pruner#559
Merged
fangbo merged 1 commit intoMay 26, 2026
Conversation
Lance JNI normalizes every integer width in ZoneStats.min/max to Long and every float width to Double, while Spark V2 Literal.value() keeps the Catalyst type (Integer for int32, Short for smallint, Byte for tinyint, Float for float32, Integer epoch days for date). The boxes disagree, and Integer.compareTo(Object) rejects the Long with a ClassCastException — the existing conservative catch swallows it and silently drops pruning instead of crashing the query. Widen Byte/Short/Integer to Long and Float to Double inside normalizeLiteral. Both conversions are lossless and order-preserving. Also fixes the IN-list path, which routes each element through the same normalizer. Closes lance-format#557.
Contributor
Author
|
cc @fangbo FYI |
Collaborator
|
+1, Thanks for fixing it ! |
Contributor
Author
|
Thank you @fangbo |
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.
Closes #557.
ZonemapFragmentPrunerthrowsClassCastException: Long cannot be cast to Integerwhenever aWHERE int32_col = Nquery hits a column with a zonemap index. The two sides oftarget.compareTo(min)use different Java boxes:scalar_value_to_javainlance-jni/utils.rs) materializesZoneStats.min/maxwith every integer width asLongand every float width asDouble.Literal.value()keeps the Catalyst type —IntegerforIntegerType,ShortforShortType,ByteforByteType,FloatforFloatType,Integerepoch days forDateType.Integer.compareTo(Object)then rejects theLong. Same mismatch affectstinyint,smallint,float, anddatepredicates, plus the IN-list path. The existingcatch (ClassCastException)inzoneMatchesComparisondoes fire on the reported workload but means we silently drop pruning instead of getting it.Fix
Widen the narrow boxes inside
normalizeLiteralto match the JNI wire types:Byte/Short/Integer→Long,Float→Double. Both conversions are lossless and order-preserving;analyzeInalready routes each list element through the same normalizer so it gets the fix for free.Tests
Seven new cases in
ZonemapFragmentPrunerTest— one per affected literal type (Integer / Short / Byte / Float / Date) plus IN-list coverage (homogeneous and mixed-width). Verified by revertingnormalizeLiterallocally and watching all seven fail through the conservative-catch fallback.Out of scope (surfaced during review)
Pre-existing JNI gaps, not regressions from this PR — noting for follow-up:
ScalarValue::Decimal*and other unhandled types box tonullfor bothminandmax. The pruner then treats those zones as all-null and excludes them — risk of silent under-pruning on decimal predicates.Date64and the fourTimestamp*variants are all flattened toLongwithout a unit tag, so columns written with non-Date32/ non-microsecond units cannot be safely pruned against Spark's days/micros literals.Test plan