Class CsvFormatReader
java.lang.Object
org.elasticsearch.xpack.esql.datasource.csv.CsvFormatReader
- All Implemented Interfaces:
Closeable,AutoCloseable,FormatReader,SegmentableFormatReader
CSV/TSV format reader for external datasources.
File format
- First non-comment line: schema —
column:typepairs separated by the delimiter - Subsequent lines: data rows
- Empty/missing values →
null - Lines starting with the comment prefix (default
//) are skipped
Supported types
integer (int, i), long (l),
double (d), keyword (k, string, s),
text (txt), boolean (bool),
datetime (date, dt), ip, null (n).
Configurable options
All options are set via theWITH clause and parsed by withConfig(java.util.Map).
| ES/ESQL key | Default | Description |
|---|---|---|
delimiter | , | Field separator character |
quote | " | Quoting character |
escape | \ | Escape character inside quoted fields |
comment | // | Line comment prefix |
null_value | (empty) | String representation of null |
encoding | UTF-8 | Character encoding |
datetime_format | ISO-8601 / epoch | Custom datetime pattern |
max_field_size | 10 MB | OOM protection; max bytes per field |
multi_value_syntax | brackets | Multi-value field syntax |
schema_sample_size | 20,000 | Number of rows to sample for type inference |
Bracket multi-value syntax
Whenmulti_value_syntax is brackets, array-like values support:
[a,b,c]— unquoted elements["a","b","c"]— quoted elements (quotes stripped)[a,"b,c"]— mixed; commas inside quotes are literal
With comma delimiter, a cell like [hello,world] is treated as one column:
commas inside [...] are not column delimiters.
Error handling
Controlled byErrorPolicy and its ErrorPolicy.Mode:
| ES/ESQL key | Behaviour |
|---|---|
fail_fast | Abort on first error (default) |
skip_row | Drop the entire bad row |
null_field | Null-fill unparseable fields, keep the row |
Examples
EXTERNAL "s3://bucket/data.tsv" WITH {"delimiter": "\t", "error_mode": "skip_row", "max_errors": 100}
EXTERNAL "s3://bucket/employees.csv" WITH {"multi_value_syntax": "brackets"}
EXTERNAL "s3://bucket/data.csv" WITH {"multi_value_syntax": "brackets", "error_mode": "skip_row"}
Works with any StorageProvider
(HTTP, S3, local filesystem).
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.elasticsearch.xpack.esql.datasources.spi.FormatReader
FormatReader.SchemaResolution -
Field Summary
Fields inherited from interface org.elasticsearch.xpack.esql.datasources.spi.FormatReader
NO_LIMIT -
Constructor Summary
ConstructorsConstructorDescriptionCsvFormatReader(BlockFactory blockFactory) CsvFormatReader(BlockFactory blockFactory, String format, List<String> extensions) CsvFormatReader(BlockFactory blockFactory, CsvFormatOptions options, String format, List<String> extensions) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()longfindNextRecordBoundary(InputStream stream) metadata(StorageObject object) read(StorageObject object, FormatReadContext context) withConfig(Map<String, Object> config) withOptions(CsvFormatOptions newOptions) withSchema(List<Attribute> schema) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.elasticsearch.xpack.esql.datasources.spi.FormatReader
aggregatePushdownSupport, defaultErrorPolicy, defaultSchemaResolution, filterPushdownSupport, read, readAsync, schema, supportsNativeAsync, withPushedFilterMethods inherited from interface org.elasticsearch.xpack.esql.datasources.spi.SegmentableFormatReader
minimumSegmentSize
-
Constructor Details
-
CsvFormatReader
-
CsvFormatReader
-
CsvFormatReader
public CsvFormatReader(BlockFactory blockFactory, CsvFormatOptions options, String format, List<String> extensions)
-
-
Method Details
-
withOptions
-
withSchema
- Specified by:
withSchemain interfaceFormatReader
-
withConfig
- Specified by:
withConfigin interfaceFormatReader
-
metadata
- Specified by:
metadatain interfaceFormatReader- Throws:
IOException
-
read
public CloseableIterator<Page> read(StorageObject object, FormatReadContext context) throws IOException - Specified by:
readin interfaceFormatReader- Throws:
IOException
-
findNextRecordBoundary
- Specified by:
findNextRecordBoundaryin interfaceSegmentableFormatReader- Throws:
IOException
-
formatName
- Specified by:
formatNamein interfaceFormatReader
-
fileExtensions
- Specified by:
fileExtensionsin interfaceFormatReader
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-