Skip to content

feat: Support Spark expression seconds_of_time#3618

Draft
0lai0 wants to merge 13 commits intoapache:mainfrom
0lai0:expression_second_of_time
Draft

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

Conversation

@0lai0
Copy link
Copy Markdown
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
Comment thread spark/src/main/scala/org/apache/comet/serde/strings.scala Outdated
}
}

def secondOfTimeToProto(
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

Comment thread spark/src/main/scala/org/apache/comet/serde/datetime.scala Outdated
@0lai0 0lai0 requested a review from martin-g March 5, 2026 03:21
Comment thread spark/src/main/spark-3.4/org/apache/comet/shims/CometExprShim.scala Outdated
Comment thread spark/src/main/spark-3.5/org/apache/comet/shims/CometExprShim.scala Outdated
Comment thread spark/src/main/spark-4.0/org/apache/comet/shims/CometExprShim.scala Outdated
0lai0 and others added 3 commits March 5, 2026 15:33
…scala

Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
…scala

Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
…scala

Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
@0lai0
Copy link
Copy Markdown
Contributor Author

0lai0 commented Mar 5, 2026

Thanks @martin-g for pointing that out.

@0lai0 0lai0 marked this pull request as draft March 7, 2026 17:32
@0lai0 0lai0 marked this pull request as ready for review March 7, 2026 18:09
@0lai0
Copy link
Copy Markdown
Contributor Author

0lai0 commented Mar 26, 2026

Hi @andygrove , could you please take a look when your schedule permits? Thanks : )

@andygrove
Copy link
Copy Markdown
Member

@0lai0 could you fix the compilation issue. thx.

@0lai0
Copy link
Copy Markdown
Contributor Author

0lai0 commented Mar 26, 2026

Sure, thank for running CI test. I'll fix it right away.

@andygrove
Copy link
Copy Markdown
Member

SecondsOfTime is new in Spark 4.1.0 as far as I know, and Comet does not support Spark 4.1.0 yet

@0lai0
Copy link
Copy Markdown
Contributor Author

0lai0 commented Mar 26, 2026

Thanks for pointing that out! I wasn't aware that SecondsOfTime is only available in Spark 4.1.0. Since Comet doesn't support Spark 4.1 yet, I'll put this PR on hold until that support is added. Should I close this PR for now, or keep it open as a draft?

@andygrove
Copy link
Copy Markdown
Member

Thanks for pointing that out! I wasn't aware that SecondsOfTime is only available in Spark 4.1.0. Since Comet doesn't support Spark 4.1 yet, I'll put this PR on hold until that support is added. Should I close this PR for now, or keep it open as a draft?

@0lai0 Comet now supports Spark 4.0 (and 4.1)

@andygrove
Copy link
Copy Markdown
Member

@0lai0 I moved to draft. Please mark as ready for review when you have time to work on this again.

@andygrove andygrove marked this pull request as draft May 5, 2026 20:20
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

3 participants