apache / apache/datafusion

Support timestamp formats on CsvReadOptions or Schema

Abierto
#17,548 1 comentario 3 reacciones 0 asignados Ver en GitHub
enhancement
Lenguaje dominante
Rust
Estrellas
9.3k
Forks
2.4k
Merge medio
3 d 11 h
PR fusionados (30 d)
362

Descripción

### 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)

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza en CsvReadOptions y en la ruta de análisis de marcas de tiempo CSV, y luego compara las opciones de formato SQL DDL existentes. Determina cómo debería aplicarse un formato personalizado a la inferencia del esquema y a los esquemas proporcionados por el usuario, incluido si DataType::Timestamp necesita cambios; se considera terminado cuando los valores de marca de tiempo no estándar se analizan correctamente a través de ambas rutas.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rust
Área
data-engineering
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.