Skip to main content
Load data into the database using the 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.
An optional data-operation trigger can also run inside the load transaction to derive extra rows, for example to maintain a data-availability table atomically with the load.

Prerequisites

Loading data requires:

What is the IDataLoadConfigurer interface?

Data loading is configured through a Spring bean that implements the IDataLoadConfigurer 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 through attachChannel(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:
This example uses a CSV topic. For the full CSV reference, covering file selection, parsers, and parsing options, see the CSV topic page.

How to rename columns

Use addColumnRenames() 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, implement IFieldCalculator:
  • 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.
A calculator can be registered at two levels:
  • 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 through configurator.channels().channel(channelName).addCalculator(calculator) afterward.
When a channel-level calculator and a table-level calculator share the same field name, the channel-level one takes precedence.

How to handle missing source fields

Override onMissingFields() 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 call attachChannel() 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: