apache / apache/datafusion

CSV import doesn't support date parsing

Open
#13,633 3 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
9.3k
Forks
2.4k
Avg merge
3d 7h
Merged PRs (30d)
344

Description

### Describe the bug

While working on [#13576](https://github.com/apache/datafusion/pull/13576/files#diff-ec9107a0ab3a6acc573a935893a568ff798339bbfde06ee3aeb3ed39cd2f483aR367), I noticed we allow to pass `format.date_format` when reading CSV but ignore that

### To Reproduce

```sql
CREATE EXTERNAL TABLE dates (
date date
) STORED AS CSV
LOCATION 'dates.csv'
OPTIONS ('format.has_header' 'true', 'format.date_format' '%d/%m/%Y');

SELECT * FROM dates;
0 row(s) fetched.
Elapsed 0.014 seconds.

Arrow error: Parser error: Error while parsing value 03/12/2024 for column 0 at line 1
```
[dates.csv](https://github.com/user-attachments/files/17999374/dates.csv)

### Expected behavior

```sql
select to_date('03/12/2024', '%d/%m/%Y');
```
This^ works, so I `date_format` should be supported too?

### Additional context

I believe we currently don't pass the format string when reading csv (because there's no functionality in arrow), only when writing:

https://github.com/apache/arrow-rs/blob/9047d99f6bf87582532ee6ed0acb3f2d5f889f11/arrow-csv/src/reader/mod.rs#L909

Contributor guide

Open the contributing guide

Research direction

Start with the CSV-reading path described in the issue and inspect the linked arrow-csv reader implementation, especially around the referenced reader code. Reproduce the CREATE EXTERNAL TABLE example with dates.csv and the date_format option, then verify that importing the CSV parses 03/12/2024 according to %d/%m/%Y without the parser error.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.