fix: remove unreachable scala.math.BigDecimal case in toNumber#670
Open
LuciferYang wants to merge 1 commit into
Open
fix: remove unreachable scala.math.BigDecimal case in toNumber#670LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
Scala warned on LanceSearchTableFunctions.scala:341 with
unreachable code
for the `case decimal: scala.math.BigDecimal` branch of `toNumber`.
The branch is genuinely dead: `toNumber` is only ever fed
`Literal.value`, and Spark's Literal never holds a
`scala.math.BigDecimal`. Numeric literals with DecimalType are stored
as `org.apache.spark.sql.types.Decimal` (caught by the previous case);
any `java.math.BigDecimal` from foldable-expression evaluation is a
`java.lang.Number` (caught by the first case). The Scala BigDecimal
case can therefore never match.
Removing the dead case clears the warning across every 2.12 and 2.13
module build without changing runtime behavior.
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
Removes the dead
case decimal: scala.math.BigDecimalbranch inLanceSearchTableFunctions.toNumber. The Scala compiler emitsfor every 2.12 and 2.13 module build, and the warning is real.
Why the case is unreachable
toNumberis only ever fedLiteral.value(vialiteralValue(expr)upstream). Spark'sLiteralnever holds ascala.math.BigDecimal:DecimalTypeare stored asorg.apache.spark.sql.types.Decimal— caught by the previous case,case decimal: org.apache.spark.sql.types.Decimal.java.math.BigDecimalyielded by foldable-expression evaluation is ajava.lang.Number— caught by the first case,case number: Number.So a
scala.math.BigDecimalcan never match, and the pattern is dead code. Removing it doesn't change runtime behavior on any code path that has ever executed.Verification
./mvnw -pl lance-spark-base_2.12,lance-spark-3.4_2.12,lance-spark-3.5_2.12 -am -DskipTests -Dspotless.skip -Dcheckstyle.skip clean compile→ 0 scala warnings (was 3)../mvnw -pl lance-spark-base_2.13,lance-spark-3.4_2.13,lance-spark-3.5_2.13,lance-spark-4.0_2.13,lance-spark-4.1_2.13 -am -DskipTests -Dspotless.skip -Dcheckstyle.skip clean compile→ 0unreachable codewarnings (was 5). The remaining aggregateddeprecations (since 2.13.0)line is unrelated (JavaConverters / IndexedSeq); left for a separate PR per "one PR, one concern."./mvnw -pl lance-spark-3.5_2.12 -am -Dtest="*Search*Test,*SearchTableFunction*" test→Tests run: 8, Failures: 0, Errors: 0, Skipped: 1.make lint→ BUILD SUCCESS.