IDataLoadConfigurer interface.
A data load configuration declares three kinds of objects:
- Channels define how rows land in a target table.
- Topics define where the data comes from, for example a directory of CSV files.
- Field calculators are optional and derive new fields from the source columns.
Prerequisites
Loading data requires:What is the IDataLoadConfigurer interface?
Data loading is configured through a Spring bean that implements theIDataLoadConfigurer interface.
The configure() method receives an IDataLoadConfigurator. Use it to declare topics, channels, and field calculators. See the Javadoc for the complete list of available methods.
What are topics and channels?
A channel defines how rows load into a specific target table. It carries the field calculators, column renames, tuple publisher, and unload condition for that table. Channels are created on the configurator, and each one has a unique name. A topic describes a data source, for example a directory of CSV files together with the parser options needed to read them. A topic feeds one or more channels throughattachChannel(channelName). The same channel can be attached to several topics. Within a single topic, two attached channels cannot target the same table.
The following example puts both objects together. The topic reads CSV files from a directory and feeds their rows to the SalesChannel, which loads them into the Sales table:
How to rename columns
UseaddColumnRenames() to map header names onto the expected field names. Renames declared on the topic apply to every channel. Renames declared on a channel apply on top of them.
How to compute a derived field with a field calculator
A field calculator produces a field whose value is computed from other source columns. To create one, implementIFieldCalculator:
getFieldName(): name of the computed field.getType(): type of the computed value.getUnderlyingFieldNames(): names of the source columns the calculator depends on.compute(): writes the computed value.onMissingFields(): optional. Decides what to do when an underlying column is missing. The default throws.
- On the table, through
configurator.addCalculator(tableName, calculator). Every channel that targets that table inherits the calculator. - On a single channel, by chaining off
configurator.channels().addChannel(...)at creation time, or throughconfigurator.channels().channel(channelName).addCalculator(calculator)afterward.
How to handle missing source fields
OverrideonMissingFields() on the calculator to either tolerate missing source columns or fail fast when a column is required. Tolerating missing columns helps when files in the same topic carry different subsets of columns.
How to load one topic into several tables
Declare one channel per target table on the configurator, then callattachChannel() on the topic for each one. The topic fans its rows out to every attached channel.
How to override topic settings
IDataLoadConfigurator.globalSettings() overrides the defaults used by topics. Each setting is declared as a SettingKey constant on the topic configurator interface it applies to. A setting only affects topics whose configurator implements that interface.
For example, ICsvTopicConfigurator declares PARSER_THREADS, DEFAULT_CHARSET, and DEFAULT_SEPARATOR. These apply to every CSV topic, such as local and cloud, and are ignored by topics of other types.
The following example raises the number of CSV parser threads from the default of 4 to 8:
Related pages
- Load CSV files: file selection, column parsers, and parsing options for the CSV topic.
- Load rows from a SQL query: JDBC connections, column aliasing, and query parameters.
- Load tuples from a supplier: rows built in code, including tuples derived from a datastore query.
- Data operation triggers: run custom logic inside the load transaction, for example to maintain a data-availability table.