Package org.pipecraft.pipes.sync.inter
Class CSVMapperPipe<T>
- java.lang.Object
-
- org.pipecraft.pipes.sync.inter.CSVMapperPipe<T>
-
- Type Parameters:
T- The type of the object we wish to bind the CSV lines to
- All Implemented Interfaces:
Closeable,AutoCloseable,BasePipe,Pipe<T>
public class CSVMapperPipe<T> extends Object implements Pipe<T>
An intermediate pipe that parses strings in CSV format, and binds each line to an object- Author:
- Eyal Schneider
-
-
Constructor Summary
Constructors Constructor Description CSVMapperPipe(Pipe<String> input, boolean hasHeader, String[] columnNames, FailableFunction<Map<String,String>,T,PipeException> rowConverter)Constructor Constructs a mapper with the default delimiter (',').CSVMapperPipe(Pipe<String> input, char delimiter, boolean hasHeader, String[] columnNames, FailableFunction<Map<String,String>,T,PipeException> rowConverter)ConstructorCSVMapperPipe(Pipe<String> input, FailableFunction<Map<String,String>,T,PipeException> rowConverter)Constructor Constructs a mapper with the default delimiter (','), expecting a header, and using the header column names for the row converter.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()String[]getColumnNames()floatgetProgress()Tnext()Tpeek()voidstart()Performs pre-processing prior to item flow throw the pipe.
-
-
-
Constructor Detail
-
CSVMapperPipe
public CSVMapperPipe(Pipe<String> input, char delimiter, boolean hasHeader, String[] columnNames, FailableFunction<Map<String,String>,T,PipeException> rowConverter)
Constructor- Parameters:
input- The input pipedelimiter- The delimiter character to usehasHeader- When true, the first item from the input pipe will be processed as a headercolumnNames- Describes the columns in the input CSV, according to their expected order. These names will be the column names passed to the row converter. Note that even when hasHeader=true, this parameter can be passed in order to internally "rename" column names. This guarantees that we only see expected names in the row converter. When null, we rely completely on the header, and column names will be accordingly. Null isn't allowed when hasHeader=false.rowConverter- Converts a tokenized row into the target row object. May throw aPipeExceptionin case of a row which can't be handled.
-
CSVMapperPipe
public CSVMapperPipe(Pipe<String> input, boolean hasHeader, String[] columnNames, FailableFunction<Map<String,String>,T,PipeException> rowConverter)
Constructor Constructs a mapper with the default delimiter (',').- Parameters:
input- The input pipehasHeader- When true, the first item from the input pipe will be processed as a headercolumnNames- Describes the columns in the input CSV, according to their expected order. These names will be the column names passed to the row converter. Note that even when hasHeader=true, this parameter can be passed in order to internally "rename" column names. This guarantees that we only see expected names in the row converter. When null, we rely completely on the header, and column names will be accordingly. Null isn't allowed when hasHeader=false.rowConverter- Converts a tokenized row into the target row object. May throw aPipeExceptionin case of a row which can't be handled.
-
CSVMapperPipe
public CSVMapperPipe(Pipe<String> input, FailableFunction<Map<String,String>,T,PipeException> rowConverter)
Constructor Constructs a mapper with the default delimiter (','), expecting a header, and using the header column names for the row converter.- Parameters:
input- The input piperowConverter- Converts a tokenized row into the target row object. May throw aPipeExceptionin case of a row which can't be handled.
-
-
Method Detail
-
start
public void start() throws PipeException, InterruptedExceptionDescription copied from interface:BasePipePerforms pre-processing prior to item flow throw the pipe. Implementations must call the same method for all their input pipes before accessing their items. This is typically done here.- Specified by:
startin interfaceBasePipe- Throws:
PipeException- In case of pipe errors in this pipe or somewhere up-stream.InterruptedException- In case that the operation has been interrupted by another thread.
-
next
public T next() throws PipeException, InterruptedException
- Specified by:
nextin interfacePipe<T>- Returns:
- The next item in this pipe output, or null if the output end has been reached. May be a blocking operation.
- Throws:
PipeException- In case of pipe errors in this pipe or somewhere up-stream while trying to prepare next item to return.InterruptedException- In case that the operation has been interrupted by another thread.
-
getColumnNames
public String[] getColumnNames()
- Returns:
- The ordered list of column names provided by this pipe. The names are either taken from the header row, or from the column names list as provided to the constructor. Note that these names are the names passed to the row converter along with the corresponding column values.
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
peek
public T peek()
-
getProgress
public float getProgress()
- Specified by:
getProgressin interfaceBasePipe- Returns:
- The pipe flow progress, as a floating number between 0.0 and 1.0. Important implementation rules: 1) Calling this method before start() call is complete isn't allowed and has an undefined behavior. 2) Implementation should do best effort to provide an estimate of the progress this pipe has made (0.0 - 1.0) 3) When the pipe is fully consumed, getProgress() should return 1.0. 4) Results must be monotonous, i.e. results of consecutive calls may never be decreasing. 5) Thread safety: progress may be maintained by some thread/s but monitoring by other threads. Implementations must be thread safe.
-
-