Skip to content

feat: Support Spark expression seconds_of_time#3618

Open
0lai0 wants to merge 6 commits intoapache:mainfrom
0lai0:expression_second_of_time
Open

feat: Support Spark expression seconds_of_time#3618
0lai0 wants to merge 6 commits intoapache:mainfrom
0lai0:expression_second_of_time

Conversation

@0lai0
Copy link
Contributor

@0lai0 0lai0 commented Mar 2, 2026

Which issue does this PR close?

Closes #3129

Rationale for this change

Comet previously did not support the Spark SecondsOfTime expression, so queries using second(time_expr) could fall back to JVM execution instead of running natively.

What changes are included in this PR?

This change adds a Serde handler for SecondsOfTime that reuses the existing Second protobuf and Rust implementation, ensuring consistent behavior while avoiding new native code paths.

How are these changes tested?

Added a Scala unit test SecondsOfTime expression support in CometExpressionSuite
./mvnw test -Dsuites="org.apache.comet.CometSqlFileTestSuite hour,org.apache.comet.CometExpressionSuite second" -Dtest=none
./mvnw clean compile -DskipTests

@martin-g martin-g changed the title eat: Support Spark expression second_of_time feat: Support Spark expression second_of_time Mar 2, 2026
@martin-g martin-g changed the title feat: Support Spark expression second_of_time feat: Support Spark expression seconds_of_time Mar 2, 2026
}
}

def secondOfTimeToProto(
Copy link
Member

Choose a reason for hiding this comment

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

This method should probably be moved to datetime.scala instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback. I'll make changes based on your comment.

// Right child is the encoding expression.
stringDecode(expr, s.charset, s.bin, inputs, binding)

case _ if expr.getClass.getSimpleName == "SecondOfTime" =>
Copy link
Member

Choose a reason for hiding this comment

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

  1. Using the simpleName could return true for a totally unrelated class
  2. It seems you have not tested your suggested changes because the name of the class is SecondsOfTime (https://github.com/apache/spark/blob/b38e8eaece84e80687ab1f707859c1e5ee7e4c9f/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/timeExpressions.scala#L354)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for review. Sorry to miss 's', I will fix it in next commit.

val timeZoneId = {
val exprClass = expr.getClass
try {
val timeZoneIdMethod = exprClass.getMethod("timeZoneId")
Copy link
Member

Choose a reason for hiding this comment

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

Could you please point me to the def timeZoneId() method or timeZoneId field in SecondsOfTime in Spark. I fail to find them in any of the parent classes/traits.

In addition maybe it would be good to add a cache and execute the reflection just once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I originally implemented this reflection to handle potential future scenarios where Spark might add a timeZoneId to SecondsOfTime. However, since this field doesn't exist in any currently supported Spark versions, it is effectively dead code. To reduce maintenance overhead, I’ll remove the reflection logic and explicitly default it to 'UTC', consistent with other datetime expressions.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Support Spark expression: seconds_of_time

2 participants