sdf-jkl opened a new issue, #27271:
URL: https://github.com/apache/datafusion/issues/27271
### Is your feature request related to a problem or challenge?
DataFusion maps SQL `TIME` to `Time64(Nanosecond)` and rejects an explicit
precision, while `TIMESTAMP(p)` has worked since #13231:
```sql
SELECT arrow_typeof(CAST('12:34:56' AS TIME));
-- Time64(ns)
SELECT CAST('12:34:56' AS TIME(6));
-- This feature is not implemented: Unsupported SQL type TIME(6)
CREATE TABLE t (c TIME(6));
-- This feature is not implemented: Unsupported SQL type TIME(6)
SELECT arrow_typeof(CAST('2024-01-01 12:34:56' AS TIMESTAMP(6)));
-- Timestamp(µs)
```
So SQL cannot name a millisecond or microsecond time, though both are
common: PostgreSQL's `TIME` is microseconds, and Parquet `TIME(MILLIS)` and
`TIME(MICROS)` columns read as `Time32(Millisecond)` and `Time64(Microsecond)`.
### Describe the solution you'd like
Accept `TIME(p)` for the precisions that have an Arrow unit, as
[`TIMESTAMP(p)`
does](https://github.com/apache/datafusion/blob/14b3edd9a350b983fae6d2f194df1a3ae343ba15/datafusion/sql/src/planner.rs#L766-L798):
| SQL | Arrow type |
|---|---|
| `TIME(0)` | `Time32(Second)` |
| `TIME(3)` | `Time32(Millisecond)` |
| `TIME(6)` | `Time64(Microsecond)` |
| `TIME(9)` | `Time64(Nanosecond)` |
[`TIME` without a
precision](https://github.com/apache/datafusion/blob/14b3edd9a350b983fae6d2f194df1a3ae343ba15/datafusion/sql/src/planner.rs#L809-L813)
stays `Time64(Nanosecond)`. Other precisions and `TIME WITH TIME ZONE` stay
unsupported.
### Describe alternatives you've considered
`arrow_cast(value, 'Time64(Microsecond)')` works in expressions, but not
where SQL expects a type name, such as a `CREATE TABLE` column.
### Additional context
- Discussion #13230 asked for both `timestamp` and `time` precision. #13231
added `timestamp(p)` only.
- #3010 chose `Time64(Nanosecond)` because a microsecond `TIME` already
needs `Time64`, so nanoseconds cost no extra memory. This proposal keeps it as
the default.
- Downstream,
[datafusion-variant](https://github.com/datafusion-contrib/datafusion-variant)
uses SQL type names for Variant shredding layouts. The Parquet Variant `time`
type is microseconds only, so `TIME` can't be used as a layout, and no SQL
spelling can.
- The SQL unparser doesn't convert `Time32` or `Time64` at all
([`expr.rs`](https://github.com/apache/datafusion/blob/14b3edd9a350b983fae6d2f194df1a3ae343ba15/datafusion/sql/src/unparser/expr.rs#L1865-L1870)),
so unparsing is out of scope here.
### Willingness to contribute
I plan to contribute to this feature independently
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]