Skip to content

[SPARK-52569][SQL] Fix the class cast exception in SecondsOfTimeWithFraction#51270

Closed
MaxGekk wants to merge 1 commit into
apache:masterfrom
MaxGekk:fix-SecondsOfTimeWithFraction
Closed

[SPARK-52569][SQL] Fix the class cast exception in SecondsOfTimeWithFraction#51270
MaxGekk wants to merge 1 commit into
apache:masterfrom
MaxGekk:fix-SecondsOfTimeWithFraction

Conversation

@MaxGekk
Copy link
Copy Markdown
Member

@MaxGekk MaxGekk commented Jun 24, 2025

What changes were proposed in this pull request?

In the PR, I propose to avoid an assumption in the SecondsOfTimeWithFraction expression: the default constructor is called only on TimeType of child. The constructor can be called before the inputTypes method, and we cannot guarantee that input types are TimeType(n) only. The child expression can be NullType, for instance.

Why are the changes needed?

To avoid the following exception while calling expression's methods:

class org.apache.spark.sql.types.NullType$ cannot be cast to class org.apache.spark.sql.types.TimeType (org.apache.spark.sql.types.NullType$ and org.apache.spark.sql.types.TimeType are in unnamed module of loader 'app')

Does this PR introduce any user-facing change?

No.

How was this patch tested?

By running new check:

$ build/sbt "test:testOnly *TimeExpressionsSuite"

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions github-actions Bot added the SQL label Jun 24, 2025
@MaxGekk MaxGekk changed the title [WIP][SQL] Fix the class cast exception in SecondsOfTimeWithFraction [WIP][SPARK-52569][SQL] Fix the class cast exception in SecondsOfTimeWithFraction Jun 24, 2025
@MaxGekk MaxGekk changed the title [WIP][SPARK-52569][SQL] Fix the class cast exception in SecondsOfTimeWithFraction [SPARK-52569][SQL] Fix the class cast exception in SecondsOfTimeWithFraction Jun 24, 2025
@MaxGekk MaxGekk marked this pull request as ready for review June 24, 2025 19:45
Seq(child, Literal(precision)),
Seq(child.dataType, IntegerType))
}
private val precision: Int = child.dataType.asInstanceOf[TimeType].precision
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This val is initialized before the invoke of inputTypes(), so, asInstanceOf[TimeType] can fail on other types.

@MaxGekk
Copy link
Copy Markdown
Member Author

MaxGekk commented Jun 25, 2025

@LuciferYang @HyukjinKwon Could you review this PR, please.

@MaxGekk
Copy link
Copy Markdown
Member Author

MaxGekk commented Jun 25, 2025

Merging to master. Thank you, @LuciferYang.

@MaxGekk MaxGekk closed this in 503681e Jun 25, 2025
Copy link
Copy Markdown
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, late LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants