You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "andygrove (via GitHub)" <gi...@apache.org> on 2026/01/14 19:47:19 UTC
[I] [Feature] Support Spark expression: to_time [datafusion-comet]
andygrove opened a new issue, #3120:
URL: https://github.com/apache/datafusion-comet/issues/3120
## What is the problem the feature request solves?
> **Note:** This issue was generated with AI assistance. The specification details have been extracted from Spark documentation and may need verification.
Comet does not currently support the Spark `to_time` function, causing queries using this function to fall back to Spark's JVM execution instead of running natively on DataFusion.
The `ToTime` expression converts a string representation of time into a `TimeType` value. It supports both default parsing and custom format-based parsing using optional format strings, and serves as a runtime replaceable expression that delegates actual parsing to a specialized `ToTimeParser` class.
Supporting this expression would allow more Spark workloads to benefit from Comet's native acceleration.
## Describe the potential solution
### Spark Specification
**Syntax:**
```sql
to_time(str)
to_time(str, format)
```
```scala
// DataFrame API usage
ToTime(stringExpr)
ToTime(stringExpr, formatExpr)
```
**Arguments:**
| Argument | Type | Description |
|----------|------|-------------|
| `str` | String | The input string containing the time value to be parsed |
| `format` | String (Optional) | Optional format pattern specifying how to parse the input string |
**Return Type:** `TimeType` - A Spark SQL time data type representing time values.
**Supported Data Types:**
- **Input**: `StringTypeWithCollation` (supports trim collation for both string argument and optional format argument)
- **Output**: `TimeType`
**Edge Cases:**
- **Null input string**: Returns null result
- **Null format**: When format expression evaluates to null, returns null literal
- **Invalid format**: Handled by underlying `ToTimeParser` implementation
- **Unparseable time strings**: Behavior depends on `ToTimeParser` implementation
- **Non-foldable format**: Falls back to runtime format evaluation for dynamic format expressions
**Examples:**
```sql
-- Parse time with default format
SELECT to_time('12:10:05');
-- Parse time with custom format
SELECT to_time('10:05 AM', 'HH:mm a');
-- Handle null inputs
SELECT to_time(NULL);
```
```scala
// DataFrame API usage
import org.apache.spark.sql.functions._
// Default parsing
df.select(expr("to_time(time_string)"))
// With format
df.select(expr("to_time(time_string, 'HH:mm:ss')"))
// Direct expression usage
val timeExpr = ToTime(col("time_column").expr)
val timeWithFormatExpr = ToTime(col("time_column").expr, lit("HH:mm").expr)
```
### Implementation Approach
See the [Comet guide on adding new expressions](https://datafusion.apache.org/comet/contributor-guide/adding_a_new_expression.html) for detailed instructions.
1. **Scala Serde**: Add expression handler in `spark/src/main/scala/org/apache/comet/serde/`
2. **Register**: Add to appropriate map in `QueryPlanSerde.scala`
3. **Protobuf**: Add message type in `native/proto/src/proto/expr.proto` if needed
4. **Rust**: Implement in `native/spark-expr/src/` (check if DataFusion has built-in support first)
## Additional context
**Difficulty:** Medium
**Spark Expression Class:** `org.apache.spark.sql.catalyst.expressions.ToTime`
**Related:**
- Time-related expressions and functions
- `TimeType` data type documentation
- Date/time parsing expressions
- `RuntimeReplaceable` expression pattern
---
*This issue was auto-generated from Spark reference documentation.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] [Feature] Support Spark expression: to_time [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove closed issue #3120: [Feature] Support Spark expression: to_time
URL: https://github.com/apache/datafusion-comet/issues/3120
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] [Feature] Support Spark expression: to_time [datafusion-comet]
Posted by "andygrove (via GitHub)" <gi...@apache.org>.
andygrove commented on issue #3120:
URL: https://github.com/apache/datafusion-comet/issues/3120#issuecomment-5113039746
`ToTime` is a `RuntimeReplaceable` expression. The `ReplaceExpressions` rule (Finish Analysis batch) substitutes it with its `replacement` before physical planning, so the class never appears in a physical plan and Comet's expression serde never sees it. Registering a `CometExpressionSerde` for it would be dead code.
Its replacement is a `StaticInvoke` into the `DateTimeUtils` time parser, so this function is never gated on a serde for `ToTime`. Native support for `to_time` would have to come from supporting that replacement, which is a different piece of work than this issue describes.
Closing as not actionable as specified. If the fallback matters in practice, a fresh issue should track the replacement path.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org