Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

MaxGekk
Copy link
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
StaticInvoke(
classOf[DateTimeUtils.type],
DecimalType(8, 6),
"getSecondsOfTimeWithFraction",
Seq(child, Literal(precision)),
Seq(child.dataType, IntegerType))
}
private val precision: Int = child.dataType.asInstanceOf[TimeType].precision
Copy link
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
Member Author

MaxGekk commented Jun 25, 2025

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

@MaxGekk
Copy link
Member Author

MaxGekk commented Jun 25, 2025

Merging to master. Thank you, @LuciferYang.

@MaxGekk MaxGekk closed this in 503681e Jun 25, 2025
Copy link
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