@PublicEvolving public interface StreamTableEnvironment extends TableEnvironment
DataStream
API.
It is unified for bounded and unbounded data processing.
A stream table environment is responsible for:
DataStream
into Table
and vice-versa.Table
s and other meta objects from a catalog.Note: If you don't intend to use the DataStream
API, TableEnvironment
is meant
for pure table programs.
Modifier and Type | Method and Description |
---|---|
StreamTableDescriptor |
connect(ConnectorDescriptor connectorDescriptor)
Creates a table source and/or table sink from a descriptor.
|
static StreamTableEnvironment |
create(StreamExecutionEnvironment executionEnvironment)
Creates a table environment that is the entry point and central context for creating Table & SQL
API programs that integrate with the Java-specific
DataStream API. |
static StreamTableEnvironment |
create(StreamExecutionEnvironment executionEnvironment,
EnvironmentSettings settings)
Creates a table environment that is the entry point and central context for creating Table & SQL
API programs that integrate with the Java-specific
DataStream API. |
static StreamTableEnvironment |
create(StreamExecutionEnvironment executionEnvironment,
TableConfig tableConfig)
Deprecated.
Use
create(StreamExecutionEnvironment) and TableEnvironment.getConfig()
for manipulating TableConfig . |
JobExecutionResult |
execute(String jobName)
Triggers the program execution.
|
<T> Table |
fromDataStream(DataStream<T> dataStream)
Converts the given
DataStream into a Table . |
<T> Table |
fromDataStream(DataStream<T> dataStream,
String fields)
Converts the given
DataStream into a Table with specified field names. |
void |
insertInto(Table table,
StreamQueryConfig queryConfig,
String sinkPath,
String... sinkPathContinued)
|
<T> void |
registerDataStream(String name,
DataStream<T> dataStream)
Registers the given
DataStream as table in the TableEnvironment 's catalog. |
<T> void |
registerDataStream(String name,
DataStream<T> dataStream,
String fields)
Registers the given
DataStream as table with specified field names in the
TableEnvironment 's catalog. |
<T,ACC> void |
registerFunction(String name,
AggregateFunction<T,ACC> aggregateFunction)
Registers an
AggregateFunction under a unique name in the TableEnvironment's catalog. |
<T,ACC> void |
registerFunction(String name,
TableAggregateFunction<T,ACC> tableAggregateFunction)
Registers an
TableAggregateFunction under a unique name in the TableEnvironment's
catalog. |
<T> void |
registerFunction(String name,
TableFunction<T> tableFunction)
Registers a
TableFunction under a unique name in the TableEnvironment's catalog. |
void |
sqlUpdate(String stmt,
StreamQueryConfig config)
Evaluates a SQL statement such as INSERT, UPDATE or DELETE; or a DDL statement;
NOTE: Currently only SQL INSERT statements are supported.
|
<T> DataStream<T> |
toAppendStream(Table table,
Class<T> clazz)
Converts the given
Table into an append DataStream of a specified type. |
<T> DataStream<T> |
toAppendStream(Table table,
Class<T> clazz,
StreamQueryConfig queryConfig)
Converts the given
Table into an append DataStream of a specified type. |
<T> DataStream<T> |
toAppendStream(Table table,
TypeInformation<T> typeInfo)
Converts the given
Table into an append DataStream of a specified type. |
<T> DataStream<T> |
toAppendStream(Table table,
TypeInformation<T> typeInfo,
StreamQueryConfig queryConfig)
Converts the given
Table into an append DataStream of a specified type. |
<T> DataStream<Tuple2<Boolean,T>> |
toRetractStream(Table table,
Class<T> clazz)
Converts the given
Table into a DataStream of add and retract messages. |
<T> DataStream<Tuple2<Boolean,T>> |
toRetractStream(Table table,
Class<T> clazz,
StreamQueryConfig queryConfig)
Converts the given
Table into a DataStream of add and retract messages. |
<T> DataStream<Tuple2<Boolean,T>> |
toRetractStream(Table table,
TypeInformation<T> typeInfo)
Converts the given
Table into a DataStream of add and retract messages. |
<T> DataStream<Tuple2<Boolean,T>> |
toRetractStream(Table table,
TypeInformation<T> typeInfo,
StreamQueryConfig queryConfig)
Converts the given
Table into a DataStream of add and retract messages. |
create, explain, explain, explain, fromTableSource, getCatalog, getCompletionHints, getConfig, getCurrentCatalog, getCurrentDatabase, getRegisteredExternalCatalog, insertInto, listCatalogs, listDatabases, listTables, listUserDefinedFunctions, registerCatalog, registerExternalCatalog, registerFunction, registerTable, registerTableSink, registerTableSink, registerTableSource, scan, sqlQuery, sqlUpdate, useCatalog, useDatabase
static StreamTableEnvironment create(StreamExecutionEnvironment executionEnvironment)
DataStream
API.
It is unified for bounded and unbounded data processing.
A stream table environment is responsible for:
DataStream
into Table
and vice-versa.Table
s and other meta objects from a catalog.Note: If you don't intend to use the DataStream
API, TableEnvironment
is meant
for pure table programs.
executionEnvironment
- The Java StreamExecutionEnvironment
of the TableEnvironment
.static StreamTableEnvironment create(StreamExecutionEnvironment executionEnvironment, EnvironmentSettings settings)
DataStream
API.
It is unified for bounded and unbounded data processing.
A stream table environment is responsible for:
DataStream
into Table
and vice-versa.Table
s and other meta objects from a catalog.Note: If you don't intend to use the DataStream
API, TableEnvironment
is meant
for pure table programs.
executionEnvironment
- The Java StreamExecutionEnvironment
of the TableEnvironment
.settings
- The environment settings used to instantiate the TableEnvironment
.@Deprecated static StreamTableEnvironment create(StreamExecutionEnvironment executionEnvironment, TableConfig tableConfig)
create(StreamExecutionEnvironment)
and TableEnvironment.getConfig()
for manipulating TableConfig
.DataStream
API.
It is unified for bounded and unbounded data processing.
A stream table environment is responsible for:
DataStream
into Table
and vice-versa.Table
s and other meta objects from a catalog.Note: If you don't intend to use the DataStream
API, TableEnvironment
is meant
for pure table programs.
executionEnvironment
- The Java StreamExecutionEnvironment
of the TableEnvironment
.tableConfig
- The configuration of the TableEnvironment
.<T> void registerFunction(String name, TableFunction<T> tableFunction)
TableFunction
under a unique name in the TableEnvironment's catalog.
Registered functions can be referenced in Table API and SQL queries.T
- The type of the output row.name
- The name under which the function is registered.tableFunction
- The TableFunction to register.<T,ACC> void registerFunction(String name, AggregateFunction<T,ACC> aggregateFunction)
AggregateFunction
under a unique name in the TableEnvironment's catalog.
Registered functions can be referenced in Table API and SQL queries.T
- The type of the output value.name
- The name under which the function is registered.aggregateFunction
- The AggregateFunction to register.<T,ACC> void registerFunction(String name, TableAggregateFunction<T,ACC> tableAggregateFunction)
TableAggregateFunction
under a unique name in the TableEnvironment's
catalog. Registered functions can only be referenced in Table API.T
- The type of the output value.name
- The name under which the function is registered.tableAggregateFunction
- The TableAggregateFunction to register.<T> Table fromDataStream(DataStream<T> dataStream)
DataStream
into a Table
.
The field names of the Table
are automatically derived from the type of the
DataStream
.T
- The type of the DataStream
.dataStream
- The DataStream
to be converted.Table
.<T> Table fromDataStream(DataStream<T> dataStream, String fields)
DataStream
into a Table
with specified field names.
Example:
DataStream<Tuple2<String, Long>> stream = ...
Table tab = tableEnv.fromDataStream(stream, "a, b");
T
- The type of the DataStream
.dataStream
- The DataStream
to be converted.fields
- The field names of the resulting Table
.Table
.<T> void registerDataStream(String name, DataStream<T> dataStream)
DataStream
as table in the TableEnvironment
's catalog.
Registered tables can be referenced in SQL queries.
The field names of the Table
are automatically derived
from the type of the DataStream
.T
- The type of the DataStream
to register.name
- The name under which the DataStream
is registered in the catalog.dataStream
- The DataStream
to register.<T> void registerDataStream(String name, DataStream<T> dataStream, String fields)
DataStream
as table with specified field names in the
TableEnvironment
's catalog.
Registered tables can be referenced in SQL queries.
Example:
DataStream<Tuple2<String, Long>> set = ...
tableEnv.registerDataStream("myTable", set, "a, b")
T
- The type of the DataStream
to register.name
- The name under which the DataStream
is registered in the catalog.dataStream
- The DataStream
to register.fields
- The field names of the registered table.<T> DataStream<T> toAppendStream(Table table, Class<T> clazz)
Table
into an append DataStream
of a specified type.
The Table
must only have insert (append) changes. If the Table
is also modified
by update or delete changes, the conversion will fail.
The fields of the Table
are mapped to DataStream
fields as follows:
Row
and Tuple
types: Fields are mapped by position, field types must match.DataStream
types: Fields are mapped by field name, field types must match.T
- The type of the resulting DataStream
.table
- The Table
to convert.clazz
- The class of the type of the resulting DataStream
.DataStream
.<T> DataStream<T> toAppendStream(Table table, TypeInformation<T> typeInfo)
Table
into an append DataStream
of a specified type.
The Table
must only have insert (append) changes. If the Table
is also modified
by update or delete changes, the conversion will fail.
The fields of the Table
are mapped to DataStream
fields as follows:
Row
and Tuple
types: Fields are mapped by position, field types must match.DataStream
types: Fields are mapped by field name, field types must match.T
- The type of the resulting DataStream
.table
- The Table
to convert.typeInfo
- The TypeInformation
that specifies the type of the DataStream
.DataStream
.<T> DataStream<T> toAppendStream(Table table, Class<T> clazz, StreamQueryConfig queryConfig)
Table
into an append DataStream
of a specified type.
The Table
must only have insert (append) changes. If the Table
is also modified
by update or delete changes, the conversion will fail.
The fields of the Table
are mapped to DataStream
fields as follows:
Row
and Tuple
types: Fields are mapped by position, field types must match.DataStream
types: Fields are mapped by field name, field types must match.T
- The type of the resulting DataStream
.table
- The Table
to convert.clazz
- The class of the type of the resulting DataStream
.queryConfig
- The configuration of the query to generate.DataStream
.<T> DataStream<T> toAppendStream(Table table, TypeInformation<T> typeInfo, StreamQueryConfig queryConfig)
Table
into an append DataStream
of a specified type.
The Table
must only have insert (append) changes. If the Table
is also modified
by update or delete changes, the conversion will fail.
The fields of the Table
are mapped to DataStream
fields as follows:
Row
and Tuple
types: Fields are mapped by position, field types must match.DataStream
types: Fields are mapped by field name, field types must match.T
- The type of the resulting DataStream
.table
- The Table
to convert.typeInfo
- The TypeInformation
that specifies the type of the DataStream
.queryConfig
- The configuration of the query to generate.DataStream
.<T> DataStream<Tuple2<Boolean,T>> toRetractStream(Table table, Class<T> clazz)
Table
into a DataStream
of add and retract messages.
The message will be encoded as Tuple2
. The first field is a Boolean
flag,
the second field holds the record of the specified type T
.
A true Boolean
flag indicates an add message, a false flag indicates a retract message.
The fields of the Table
are mapped to DataStream
fields as follows:
Row
and Tuple
types: Fields are mapped by position, field types must match.DataStream
types: Fields are mapped by field name, field types must match.T
- The type of the requested record type.table
- The Table
to convert.clazz
- The class of the requested record type.DataStream
.<T> DataStream<Tuple2<Boolean,T>> toRetractStream(Table table, TypeInformation<T> typeInfo)
Table
into a DataStream
of add and retract messages.
The message will be encoded as Tuple2
. The first field is a Boolean
flag,
the second field holds the record of the specified type T
.
A true Boolean
flag indicates an add message, a false flag indicates a retract message.
The fields of the Table
are mapped to DataStream
fields as follows:
Row
and Tuple
types: Fields are mapped by position, field types must match.DataStream
types: Fields are mapped by field name, field types must match.T
- The type of the requested record type.table
- The Table
to convert.typeInfo
- The TypeInformation
of the requested record type.DataStream
.<T> DataStream<Tuple2<Boolean,T>> toRetractStream(Table table, Class<T> clazz, StreamQueryConfig queryConfig)
Table
into a DataStream
of add and retract messages.
The message will be encoded as Tuple2
. The first field is a Boolean
flag,
the second field holds the record of the specified type T
.
A true Boolean
flag indicates an add message, a false flag indicates a retract message.
The fields of the Table
are mapped to DataStream
fields as follows:
Row
and Tuple
types: Fields are mapped by position, field types must match.DataStream
types: Fields are mapped by field name, field types must match.T
- The type of the requested record type.table
- The Table
to convert.clazz
- The class of the requested record type.queryConfig
- The configuration of the query to generate.DataStream
.<T> DataStream<Tuple2<Boolean,T>> toRetractStream(Table table, TypeInformation<T> typeInfo, StreamQueryConfig queryConfig)
Table
into a DataStream
of add and retract messages.
The message will be encoded as Tuple2
. The first field is a Boolean
flag,
the second field holds the record of the specified type T
.
A true Boolean
flag indicates an add message, a false flag indicates a retract message.
The fields of the Table
are mapped to DataStream
fields as follows:
Row
and Tuple
types: Fields are mapped by position, field types must match.DataStream
types: Fields are mapped by field name, field types must match.T
- The type of the requested record type.table
- The Table
to convert.typeInfo
- The TypeInformation
of the requested record type.queryConfig
- The configuration of the query to generate.DataStream
.StreamTableDescriptor connect(ConnectorDescriptor connectorDescriptor)
Descriptors allow for declaring the communication to external systems in an implementation-agnostic way. The classpath is scanned for suitable table factories that match the desired configuration.
The following example shows how to read from a Kafka connector using a JSON format and registering a table source "MyTable" in append mode:
tableEnv
.connect(
new Kafka()
.version("0.11")
.topic("clicks")
.property("zookeeper.connect", "localhost")
.property("group.id", "click-group")
.startFromEarliest())
.withFormat(
new Json()
.jsonSchema("{...}")
.failOnMissingField(false))
.withSchema(
new Schema()
.field("user-name", "VARCHAR").from("u_name")
.field("count", "DECIMAL")
.field("proc-time", "TIMESTAMP").proctime())
.inAppendMode()
.registerSource("MyTable")
connect
in interface TableEnvironment
connectorDescriptor
- connector descriptor describing the external systemvoid sqlUpdate(String stmt, StreamQueryConfig config)
All tables referenced by the query must be registered in the TableEnvironment.
A Table
is automatically registered when its Table#toString()
method is
called, for example when it is embedded into a String.
Hence, SQL queries can directly reference a Table
as follows:
// register the configured table sink into which the result is inserted.
tEnv.registerTableSink("sinkTable", configuredSink);
Table sourceTable = ...
String tableName = sourceTable.toString();
// sourceTable is not registered to the table environment
tEnv.sqlUpdate(s"INSERT INTO sinkTable SELECT * FROM tableName", config);
stmt
- The SQL statement to evaluate.config
- The QueryConfig
to use.void insertInto(Table table, StreamQueryConfig queryConfig, String sinkPath, String... sinkPathContinued)
Table
to a TableSink
that was registered under the specified name.
See the documentation of TableEnvironment.useDatabase(String)
or
TableEnvironment.useCatalog(String)
for the rules on the path resolution.
table
- The Table to write to the sink.queryConfig
- The StreamQueryConfig
to use.sinkPath
- The first part of the path of the registered TableSink
to which the Table
is
written. This is to ensure at least the name of the TableSink
is provided.sinkPathContinued
- The remaining part of the path of the registered TableSink
to which the
Table
is written.JobExecutionResult execute(String jobName) throws Exception
The program execution will be logged and displayed with the provided name
It calls the StreamExecutionEnvironment.execute(String)
on the underlying
StreamExecutionEnvironment
. In contrast to the TableEnvironment
this
environment translates queries eagerly. Therefore the values in QueryConfig
parameter are ignored.
execute
in interface TableEnvironment
jobName
- Desired name of the jobException
- which occurs during job execution.Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.