ICsvTopicConfigurator, which is shared by all CSV topics, local and cloud. ILocalCsvTopicConfigurator reads from a local directory.
For the general topic and channel concepts, see the data loading overview.
How to load CSV files from a directory
- Call
IDataLoadConfigurator.channels().addChannel(channelName, tableName)to declare the channel that loads rows into the target table. - Call
IDataLoadConfigurator.topics().addTopic()withILocalCsvTopicConfigurator.classto declare a local CSV topic. - Call
path()to point the topic at a directory, andfilePattern()to select files. The pattern accepts aglob:or aregex:prefix. Use a recursive pattern such asglob:**/*.csvto match files in subdirectories. - Call
attachChannel(channelName)on the topic to feed the channel.
/data/sales into the Sales table:
How are headers mapped to table fields?
The loader reads each file’s header row first, then routes column values to the table fields by name. As a result:- Files inside the same topic can list their columns in a different order.
- Extra columns in a file are ignored.
- A file can contain only a subset of the expected columns.
How to configure CSV column parsers
CSV topics do not automatically infer column parsers from the target table’s schema. Define them explicitly. Columns left without a parser are parsed asString.
The simplest approach is to define parsers from a database table in one call. Every column whose name matches a field of the table is parsed with that field’s type:
parsersFromTable(tableName): define parsers for every column that matches a field of the given table. This overwrites any parser previously configured for those columns.columnParser(column, parserKey): set the parser for a single column, using a registeredIParserplugin key.columnParser(column, Function): set an ad-hoc parser for a single column without registering a plugin. The function turns the raw CSV cell into the parsed value.
columnParser after parsersFromTable.
Parsers are applied after column renaming. A parser column key must therefore be the post-rename name. Configure addColumnRenames before parsersFromTable.
How to tune CSV parsing
ILocalCsvTopicConfigurator exposes the usual CSV parser options:
separator(char): field delimiter.charset(Charset): file encoding.processQuotes(boolean): Excel-style quote handling.fileColumnNames(List<String>): provide column names for files that have no header row.
CSV global settings
ICsvTopicConfigurator declares CSV-specific SettingKey constants that apply to every CSV topic, local and cloud:
PARSER_THREADSDEFAULT_CHARSETDEFAULT_SEPARATORENABLE_PARSING_REPORTBUFFER_SIZE
Related pages
- Load data: general topic, channel, and field calculator concepts.