public class CsvTableSource extends Object implements StreamTableSource<Row>, BatchTableSource<Row>, LookupableTableSource<Row>, ProjectableTableSource<Row>
StreamTableSource
and BatchTableSource
for simple CSV files with a
(logically) unlimited number of fields.Modifier and Type | Class and Description |
---|---|
static class |
CsvTableSource.Builder
A builder for creating CsvTableSource instances.
|
static class |
CsvTableSource.CsvLookupFunction
LookupFunction to support lookup in CsvTableSource.
|
Constructor and Description |
---|
CsvTableSource(String path,
String[] fieldNames,
TypeInformation<?>[] fieldTypes)
A
InputFormatTableSource and LookupableTableSource for simple CSV files with
a (logically) unlimited number of fields. |
CsvTableSource(String path,
String[] fieldNames,
TypeInformation<?>[] fieldTypes,
int[] selectedFields,
String fieldDelim,
String lineDelim,
Character quoteCharacter,
boolean ignoreFirstLine,
String ignoreComments,
boolean lenient)
A
InputFormatTableSource and LookupableTableSource for simple CSV files with
a (logically) unlimited number of fields. |
CsvTableSource(String path,
String[] fieldNames,
TypeInformation<?>[] fieldTypes,
String fieldDelim,
String lineDelim,
Character quoteCharacter,
boolean ignoreFirstLine,
String ignoreComments,
boolean lenient)
A
InputFormatTableSource and LookupableTableSource for simple CSV files with
a (logically) unlimited number of fields. |
Modifier and Type | Method and Description |
---|---|
static CsvTableSource.Builder |
builder()
Return a new builder that builds a CsvTableSource.
|
boolean |
equals(Object o) |
String |
explainSource()
Describes the table source.
|
AsyncTableFunction<Row> |
getAsyncLookupFunction(String[] lookupKeys)
Gets the
AsyncTableFunction which supports async lookup one key at a time. |
DataSet<Row> |
getDataSet(ExecutionEnvironment execEnv)
Returns the data of the table as a
DataSet . |
DataStream<Row> |
getDataStream(StreamExecutionEnvironment execEnv)
Returns the data of the table as a
DataStream . |
TableFunction<Row> |
getLookupFunction(String[] lookupKeys)
Gets the
TableFunction which supports lookup one key at a time. |
TypeInformation<Row> |
getReturnType() |
TableSchema |
getTableSchema()
Returns the schema of the produced table.
|
int |
hashCode() |
boolean |
isAsyncEnabled()
Returns true if async lookup is enabled.
|
boolean |
isBounded()
Returns true if this is a bounded source, false if this is an unbounded source.
|
CsvTableSource |
projectFields(int[] fields)
Creates a copy of the
TableSource that projects its output to the given field indexes. |
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
getProducedDataType
public CsvTableSource(String path, String[] fieldNames, TypeInformation<?>[] fieldTypes)
InputFormatTableSource
and LookupableTableSource
for simple CSV files with
a (logically) unlimited number of fields.path
- The path to the CSV file.fieldNames
- The names of the table fields.fieldTypes
- The types of the table fields.public CsvTableSource(String path, String[] fieldNames, TypeInformation<?>[] fieldTypes, String fieldDelim, String lineDelim, Character quoteCharacter, boolean ignoreFirstLine, String ignoreComments, boolean lenient)
InputFormatTableSource
and LookupableTableSource
for simple CSV files with
a (logically) unlimited number of fields.path
- The path to the CSV file.fieldNames
- The names of the table fields.fieldTypes
- The types of the table fields.fieldDelim
- The field delimiter, "," by default.lineDelim
- The row delimiter, "\n" by default.quoteCharacter
- An optional quote character for String values, null by default.ignoreFirstLine
- Flag to ignore the first line, false by default.ignoreComments
- An optional prefix to indicate comments, null by default.lenient
- Flag to skip records with parse error instead to fail, false by
default.public CsvTableSource(String path, String[] fieldNames, TypeInformation<?>[] fieldTypes, int[] selectedFields, String fieldDelim, String lineDelim, Character quoteCharacter, boolean ignoreFirstLine, String ignoreComments, boolean lenient)
InputFormatTableSource
and LookupableTableSource
for simple CSV files with
a (logically) unlimited number of fields.path
- The path to the CSV file.fieldNames
- The names of the table fields.fieldTypes
- The types of the table fields.selectedFields
- The fields which will be read and returned by the table source. If
None, all fields are returned.fieldDelim
- The field delimiter, "," by default.lineDelim
- The row delimiter, "\n" by default.quoteCharacter
- An optional quote character for String values, null by default.ignoreFirstLine
- Flag to ignore the first line, false by default.ignoreComments
- An optional prefix to indicate comments, null by default.lenient
- Flag to skip records with parse error instead to fail, false by
default.public static CsvTableSource.Builder builder()
CsvTableSource source = new CsvTableSource.builder() .path("/path/to/your/file.csv") .field("myfield", Types.STRING) .field("myfield2", Types.INT) .build();
public TypeInformation<Row> getReturnType()
getReturnType
in interface TableSource<Row>
public TableSchema getTableSchema()
TableSource
getTableSchema
in interface TableSource<Row>
TableSchema
of the produced table.public CsvTableSource projectFields(int[] fields)
ProjectableTableSource
TableSource
that projects its output to the given field indexes.
The field indexes relate to the physical poduced data type (TableSource.getProducedDataType()
)
and not to the table schema (TableSource.getTableSchema()
of the TableSource
.
The table schema (TableSource.getTableSchema()
of the TableSource
copy must not be
modified by this method, but only the produced data type (TableSource.getProducedDataType()
)
and the produced DataSet
(BatchTableSource#getDataSet(
) or DataStream
(StreamTableSource#getDataStream
).
If the TableSource
implements the DefinedFieldMapping
interface, it might
be necessary to adjust the mapping as well.
IMPORTANT: This method must return a true copy and must not modify the original table source object.
projectFields
in interface ProjectableTableSource<Row>
fields
- The indexes of the fields to return.TableSource
that projects its output.public boolean isBounded()
StreamTableSource
isBounded
in interface StreamTableSource<Row>
public DataStream<Row> getDataStream(StreamExecutionEnvironment execEnv)
StreamTableSource
DataStream
.
NOTE: This method is for internal use only for defining a TableSource
.
Do not use it in Table API programs.
getDataStream
in interface StreamTableSource<Row>
public DataSet<Row> getDataSet(ExecutionEnvironment execEnv)
BatchTableSource
DataSet
.
NOTE: This method is for internal use only for defining a TableSource
.
Do not use it in Table API programs.
getDataSet
in interface BatchTableSource<Row>
public TableFunction<Row> getLookupFunction(String[] lookupKeys)
LookupableTableSource
TableFunction
which supports lookup one key at a time.getLookupFunction
in interface LookupableTableSource<Row>
lookupKeys
- the chosen field names as lookup keys, it is in the defined orderpublic AsyncTableFunction<Row> getAsyncLookupFunction(String[] lookupKeys)
LookupableTableSource
AsyncTableFunction
which supports async lookup one key at a time.getAsyncLookupFunction
in interface LookupableTableSource<Row>
lookupKeys
- the chosen field names as lookup keys, it is in the defined orderpublic boolean isAsyncEnabled()
LookupableTableSource
The lookup function returned by LookupableTableSource.getAsyncLookupFunction(String[])
will be
used if returns true. Otherwise, the lookup function returned by
LookupableTableSource.getLookupFunction(String[])
will be used.
isAsyncEnabled
in interface LookupableTableSource<Row>
public String explainSource()
TableSource
explainSource
in interface TableSource<Row>
TableSource
.Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.