Home | Table of Contents | MultiLevelReader | CloverETL 4.6.1
--- | --- | ---
Prev | Readers | Next

## MultiLevelReader

# Not available in Community Designer

Short Description
Ports
Metadata
MultiLevelReader Attributes
Details
Best Practices
See also

### Short Description

MultiLevelReader reads data from flat files with a heterogeneous structure.

Component | Data source | Input ports | Output ports | Each to all outputs | Different to different outputs | Transformation | Transf. req. | Java | CTL | Auto-propagated metadata
--- | --- | --- | --- | --- | --- | --- | --- | --- | --- | ---
MultiLevelReader | flat file | 1 | 1-n |  |  |  |  |  |  |

### Icon

### Ports

Port type | Number | Required | Description | Metadata
--- | --- | --- | --- | ---
Input | 0 |  | For port reading. See Reading from Input Port. | One field (`byte`, `cbyte`, `string`).
Output | 0 |  | For correct data records | Any(Out0)
1-N |  | For correct data records | Any(Out1-OutN)

### Metadata

MultiLevelReader does not propagate metadata.

MultiLevelReader has no metadata template.

Metadata on all output ports can use Autofilling Functions.

`source_timestamp` and `source_size` functions work only when reading from a file directly (if the file is an archive or it is stored in a remote location, timestamp will be empty and size will be 0).

### MultiLevelReader Attributes

Attribute | Req | Description | Possible values
--- | --- | --- | ---
Basic
File URL | yes | Attribute specifying what data source(s) will be read (flat file, input port, dictionary). See Supported File URL Formats for Readers. |
Charset |  | Encoding of records that are read. The default encoding depends on DEFAULT_CHARSET_DECODER in defaultProperties. | UTF-8 | <other encodings>
Data policy |  | Determines what should be done when an error occurs. See Data Policy for more information. | Strict (default) | Lenient
Selector code | [1] | Transformation of rows of input data file to data records written in the graph in Java. |
Selector URL | [1] | Name of external file, including path, defining the transformation of rows of input data file to data records written in Java. |
Selector class | [1] | Name of external class defining the transformation of rows of input data file to data records. | PrefixMultiLevelSelector (default) | other class
Selector properties |  | List of the `key=value` expressions separated by semicolon when the whole is surrounded by flower brackets. Each value is the number of the port through which data records should be sent out. Each key is a serie of characters from the beginning of the row contained in the flat file that enable differentiate groups of records. |
Advanced
Number of skipped records |  | Number of records to be skipped continuously throughout all source files. See Selecting Input Records. | 0-N
Max number of records |  | Maximum number of records to be read continuously throughout all source files. See Selecting Input Records. | 0-N
Number of skipped records per source |  | Number of records to be skipped from each source file. See Selecting Input Records. | Same as in Metadata (default) | 0-N
Max number of records per source |  | Maximum number of records to be read from each source file. See Selecting Input Records. | 0-N
[1] If you do not define any of these three attributes, the default Selector class (`PrefixMultiLevelSelector`) will be used. `PrefixMultiLevelSelector` class implements `MultiLevelSelector` interface. The interface methods can be found below.

See Java Interfaces for MultiLevelReader for more information.

See also Defining Transformations for detailed information about transformations.

### Details

MultiLevelReader reads information from flat files with a heterogeneous and complicated structure (local or remote which are delimited, fixed-length, or mixed). It can also read data from compressed flat files, input port, or dictionary.

Unlike FlatFileReader or the two deprecated readers (DelimitedDataReader and FixLenDataReader), MultiLevelReader can read data from flat files whose structure contains different structures including both delimited and fixed length data records even with different numbers of fields and different data types. It can separate different types of data records and send them through different connected output ports. Input files can also contain non-record data.

Component also uses the Data policy option. See Data Policy for more detailed information.

Consider using newer ComplexDataReader component if you find some limitation of this component.

#### Selector Properties

You also need to set some series of parameters that should be used (Selector properties). They map individual types of data records to output ports. All of the properties must have the form of a list of the `key=value` expressions separated by semicolon. The whole sequence is in curly brackets. To specify these Selector properties, you can use the dialog that opens after clicking the button in this attribute row. By clicking the Plus button in this dialog, you can add new key-value pairs. Then you only need to change both the default name and the default value. Each value must be the number of the port through which data records should be sent out. Each key is a series of characters from the beginning of the row contained in the flat file that enable differentiate groups of records.

### Java Interfaces for MultiLevelReader

Following are the methods of the `MultiLevelSelector` interface:

- `int choose(CharBuffer data, DataRecord[] lastParsedRecords)`

  A method that peeks into `CharBuffer` and reads characters until it can either determine metadata of the record which it reads, and thus return an index to metadata pool specified in `init()` method, or runs out of data returning `MultiLevelSelector.MORE_DATA`.

- `void finished()`

  Called at the end of selector processing after all input data records were processed.

- `void init(DataRecordMetadata[] metadata, Properties properties)`

  Initializes this selector.

- `int lookAheadCharacters()`

  Returns the number of characters needed to decide (next) record type. Usually it can be any fixed number of characters, but dynamic lookahead size, depending on previous record type, is supported and encouraged whenever possible.

- `int nextRecordOffset()`

  Each call to `choose()` can instrument the parent to skip certain number of characters before attempting to parse a record according to metadata returned in `choose()` method.

- `void postProcess(int metadataIndex, DataRecord[] records)`

  In this method the selector can modify the parsed record before it is sent to corresponding output port.

- `int recoverToNextRecord(CharBuffer data)`

  This method instruments the selector to find the offset of next record which is possibly parseable.

- `void reset()`

  Resets this selector completely. This method is called once, before each run of the graph.

- `void resetRecord()`

  Resets the internal state of the selector (if any). This method is called each time a new choice needs to be made.

You can use Public Clover API in this component too.

### Best Practices

We recommend users to explicitly specify Charset.

### Compatibility

MultilevelReader is available since CloverETL 2.2.

### See also

ComplexDataReader
Common Properties of Components
Specific Attribute Types
Common Properties of Readers
Readers Comparison

Prev | Up | Next
MongoDBReader | Home | Table of Contents | ParallelReader