Class CsvEnumerator<E>
- java.lang.Object
-
- org.apache.calcite.adapter.csv.CsvEnumerator<E>
-
- Type Parameters:
E
- Row type
- All Implemented Interfaces:
java.lang.AutoCloseable
,Enumerator<E>
class CsvEnumerator<E> extends java.lang.Object implements Enumerator<E>
Enumerator that reads from a CSV file.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
CsvEnumerator.ArrayRowConverter
Array row converter.(package private) static class
CsvEnumerator.RowConverter<E>
Row converter.private static class
CsvEnumerator.SingleColumnRowConverter
Single column row converter.
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicBoolean
cancelFlag
private E
current
private java.lang.String[]
filterValues
private au.com.bytecode.opencsv.CSVReader
reader
private CsvEnumerator.RowConverter<E>
rowConverter
private static org.apache.commons.lang3.time.FastDateFormat
TIME_FORMAT_DATE
private static org.apache.commons.lang3.time.FastDateFormat
TIME_FORMAT_TIME
private static org.apache.commons.lang3.time.FastDateFormat
TIME_FORMAT_TIMESTAMP
-
Constructor Summary
Constructors Constructor Description CsvEnumerator(Source source, java.util.concurrent.atomic.AtomicBoolean cancelFlag, boolean stream, java.lang.String[] filterValues, CsvEnumerator.RowConverter<E> rowConverter)
CsvEnumerator(Source source, java.util.concurrent.atomic.AtomicBoolean cancelFlag, java.util.List<CsvFieldType> fieldTypes)
CsvEnumerator(Source source, java.util.concurrent.atomic.AtomicBoolean cancelFlag, java.util.List<CsvFieldType> fieldTypes, int[] fields)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes this enumerable and releases resources.private static CsvEnumerator.RowConverter<?>
converter(java.util.List<CsvFieldType> fieldTypes, int[] fields)
E
current()
Gets the current element in the collection.(package private) static RelDataType
deduceRowType(JavaTypeFactory typeFactory, Source source, java.util.List<CsvFieldType> fieldTypes)
Deduces the names and types of a table's columns by reading the first line of a CSV file.(package private) static RelDataType
deduceRowType(JavaTypeFactory typeFactory, Source source, java.util.List<CsvFieldType> fieldTypes, java.lang.Boolean stream)
Deduces the names and types of a table's columns by reading the first line of a CSV file.(package private) static int[]
identityList(int n)
Returns an array of integers {0, ..., n - 1}.boolean
moveNext()
Advances the enumerator to the next element of the collection.static au.com.bytecode.opencsv.CSVReader
openCsv(Source source)
void
reset()
Sets the enumerator to its initial position, which is before the first element in the collection.
-
-
-
Field Detail
-
reader
private final au.com.bytecode.opencsv.CSVReader reader
-
filterValues
private final java.lang.String[] filterValues
-
cancelFlag
private final java.util.concurrent.atomic.AtomicBoolean cancelFlag
-
rowConverter
private final CsvEnumerator.RowConverter<E> rowConverter
-
current
private E current
-
TIME_FORMAT_DATE
private static final org.apache.commons.lang3.time.FastDateFormat TIME_FORMAT_DATE
-
TIME_FORMAT_TIME
private static final org.apache.commons.lang3.time.FastDateFormat TIME_FORMAT_TIME
-
TIME_FORMAT_TIMESTAMP
private static final org.apache.commons.lang3.time.FastDateFormat TIME_FORMAT_TIMESTAMP
-
-
Constructor Detail
-
CsvEnumerator
CsvEnumerator(Source source, java.util.concurrent.atomic.AtomicBoolean cancelFlag, java.util.List<CsvFieldType> fieldTypes)
-
CsvEnumerator
CsvEnumerator(Source source, java.util.concurrent.atomic.AtomicBoolean cancelFlag, java.util.List<CsvFieldType> fieldTypes, int[] fields)
-
CsvEnumerator
CsvEnumerator(Source source, java.util.concurrent.atomic.AtomicBoolean cancelFlag, boolean stream, java.lang.String[] filterValues, CsvEnumerator.RowConverter<E> rowConverter)
-
-
Method Detail
-
converter
private static CsvEnumerator.RowConverter<?> converter(java.util.List<CsvFieldType> fieldTypes, int[] fields)
-
deduceRowType
static RelDataType deduceRowType(JavaTypeFactory typeFactory, Source source, java.util.List<CsvFieldType> fieldTypes)
Deduces the names and types of a table's columns by reading the first line of a CSV file.
-
deduceRowType
static RelDataType deduceRowType(JavaTypeFactory typeFactory, Source source, java.util.List<CsvFieldType> fieldTypes, java.lang.Boolean stream)
Deduces the names and types of a table's columns by reading the first line of a CSV file.
-
openCsv
public static au.com.bytecode.opencsv.CSVReader openCsv(Source source) throws java.io.IOException
- Throws:
java.io.IOException
-
current
public E current()
Description copied from interface:Enumerator
Gets the current element in the collection.After an enumerator is created or after the
Enumerator.reset()
method is called, theEnumerator.moveNext()
method must be called to advance the enumerator to the first element of the collection before reading the value of thecurrent
property; otherwise,current
is undefined.This method also throws
NoSuchElementException
if the last call tomoveNext
returnedfalse
, which indicates the end of the collection.This method does not move the position of the enumerator, and consecutive calls to
current
return the same object until eithermoveNext
orreset
is called.An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated. The next call to
moveNext
orreset
may, at the discretion of the implementation, throw aConcurrentModificationException
. If the collection is modified betweenmoveNext
andcurrent
,current
returns the element that it is set to, even if the enumerator is already invalidated.- Specified by:
current
in interfaceEnumerator<E>
- Returns:
- Current element
-
moveNext
public boolean moveNext()
Description copied from interface:Enumerator
Advances the enumerator to the next element of the collection.After an enumerator is created or after the
reset
method is called, an enumerator is positioned before the first element of the collection, and the first call to themoveNext
method moves the enumerator over the first element of the collection.If
moveNext
passes the end of the collection, the enumerator is positioned after the last element in the collection andmoveNext
returnsfalse
. When the enumerator is at this position, subsequent calls tomoveNext
also returnfalse
until#reset
is called.An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated. The next call to
moveNext
orEnumerator.reset()
may, at the discretion of the implementation, throw aConcurrentModificationException
.- Specified by:
moveNext
in interfaceEnumerator<E>
- Returns:
true
if the enumerator was successfully advanced to the next element;false
if the enumerator has passed the end of the collection
-
reset
public void reset()
Description copied from interface:Enumerator
Sets the enumerator to its initial position, which is before the first element in the collection.An enumerator remains valid as long as the collection remains unchanged. If changes are made to the collection, such as adding, modifying, or deleting elements, the enumerator is irrecoverably invalidated. The next call to
Enumerator.moveNext()
orreset
may, at the discretion of the implementation, throw aConcurrentModificationException
.This method is optional; it may throw
UnsupportedOperationException
.Notes to Implementers
All calls to Reset must result in the same state for the enumerator. The preferred implementation is to move the enumerator to the beginning of the collection, before the first element. This invalidates the enumerator if the collection has been modified since the enumerator was created, which is consistent with
Enumerator.moveNext()
andEnumerator.current()
.- Specified by:
reset
in interfaceEnumerator<E>
-
close
public void close()
Description copied from interface:Enumerator
Closes this enumerable and releases resources.This method is idempotent. Calling it multiple times has the same effect as calling it once.
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfaceEnumerator<E>
-
identityList
static int[] identityList(int n)
Returns an array of integers {0, ..., n - 1}.
-
-