apache / apache/datafusion

Support timestamp formats on CsvReadOptions or Schema

オープン
#17,548 コメント 1 件 リアクション 3 件 担当者 0 名 GitHub で見る
enhancement
主要言語
Rust
スター
9.3k
フォーク
2.4k
平均マージ
3日 11時間
マージ済み PR(30日)
362

説明

### Is your feature request related to a problem or challenge?

In Apache Spark it is possible to define what the expected timestamp format will be.

See `timestampFormat` and `timestampNTZFormat ` [csv options](https://spark.apache.org/docs/latest/sql-data-sources-csv.html)

This works for both user supplied and inferred schemas.

In datafusion similar functionality is only available when parsing CSV via [SQL DDL options](https://datafusion.apache.org/user-guide/sql/format_options.html)

Currently with datafusion that is not possible even for user supplied schemas. Parsing a CSV that has timestamps with non standard formats will result in an error. Example
CSV contains a column `created_at` with the following value `2025-06-23-05.07.34.214000`

Schema definition for the timestamp column:
```
Field::new("created_at", DataType::Timestamp(TimeUnit::Microsecond, None), true),
```
Attempting to parse CSV file
```
Error: ArrowError(ParseError("Error parsing column 11 at line 1: Parser error: Error parsing timestamp from '2025-06-23-05.07.34.214000': invalid timestamp separator"), None)
```

### Describe the solution you'd like

Users should be able to supply a [custom timestamp format](https://docs.rs/chrono/0.4.42/chrono/format/strftime/index.html#specifiers)

### Describe alternatives you've considered

Extend `CsvReadOptions` and allow users to supply a custom timestamp format. This would be similar to the Apache Spark approach. This format would be used to parse timestamps during schema inference or with user supplied schemas.

And, optionally, extend `DataType::Timestamp` to include a user defined timestamp. This would be more flexible as it would allow per column timestamp formats.

### Additional context

- Currenty the only workaround is to define non custom timetamps as being strings and convert them afterwards with extra code.
- It is possible to supply a timestamp format already when parsing with [SQL DDL](https://datafusion.apache.org/user-guide/sql/format_options.html)

コントリビューションガイド

コントリビューションガイドを開く

調査の方向性

CsvReadOptions と CSV のタイムスタンプ解析パスから始め、既存の SQL DDL フォーマットオプションと比較します。カスタムフォーマットをスキーマ推論とユーザー指定のスキーマにどのように適用すべきかを判断し、DataType::Timestamp に変更が必要かどうかも確認します。両方のパスで非標準のタイムスタンプ値を正常に解析できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
data-engineering
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。