@PublicEvolving
public interface StreamTableEnvironment
extends org.apache.flink.table.api.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.
Tables 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 |
|---|---|
org.apache.flink.table.descriptors.StreamTableDescriptor |
connect(org.apache.flink.table.descriptors.ConnectorDescriptor connectorDescriptor)
Deprecated.
The SQL
CREATE TABLE DDL is richer than this part of the API. This method
might be refactored in the next versions. Please use executeSql(ddl) to register a table instead. |
static StreamTableEnvironment |
create(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment executionEnvironment)
Creates a table environment that is the entry point and central context for creating Table
and SQL API programs that integrate with the Java-specific
DataStream API. |
static StreamTableEnvironment |
create(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment executionEnvironment,
org.apache.flink.table.api.EnvironmentSettings settings)
Creates a table environment that is the entry point and central context for creating Table
and SQL API programs that integrate with the Java-specific
DataStream API. |
static StreamTableEnvironment |
create(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment executionEnvironment,
org.apache.flink.table.api.TableConfig tableConfig)
Deprecated.
Use
create(StreamExecutionEnvironment) and TableEnvironment.getConfig() for
manipulating TableConfig. |
<T> void |
createTemporaryView(String path,
org.apache.flink.streaming.api.datastream.DataStream<T> dataStream)
Creates a view from the given
DataStream in a given path. |
<T> void |
createTemporaryView(String path,
org.apache.flink.streaming.api.datastream.DataStream<T> dataStream,
org.apache.flink.table.expressions.Expression... fields)
Creates a view from the given
DataStream in a given path with specified field names. |
<T> void |
createTemporaryView(String path,
org.apache.flink.streaming.api.datastream.DataStream<T> dataStream,
String fields)
Deprecated.
|
org.apache.flink.api.common.JobExecutionResult |
execute(String jobName)
Triggers the program execution.
|
<T> org.apache.flink.table.api.Table |
fromDataStream(org.apache.flink.streaming.api.datastream.DataStream<T> dataStream)
Converts the given
DataStream into a Table. |
<T> org.apache.flink.table.api.Table |
fromDataStream(org.apache.flink.streaming.api.datastream.DataStream<T> dataStream,
org.apache.flink.table.expressions.Expression... fields)
Converts the given
DataStream into a Table with specified field names. |
<T> org.apache.flink.table.api.Table |
fromDataStream(org.apache.flink.streaming.api.datastream.DataStream<T> dataStream,
String fields)
Deprecated.
|
<T> void |
registerDataStream(String name,
org.apache.flink.streaming.api.datastream.DataStream<T> dataStream)
Deprecated.
|
<T> void |
registerDataStream(String name,
org.apache.flink.streaming.api.datastream.DataStream<T> dataStream,
String fields)
Deprecated.
|
<T,ACC> void |
registerFunction(String name,
org.apache.flink.table.functions.AggregateFunction<T,ACC> aggregateFunction)
Deprecated.
Use
TableEnvironment.createTemporarySystemFunction(String, UserDefinedFunction) instead.
Please note that the new method also uses the new type system and reflective extraction
logic. It might be necessary to update the function implementation as well. See the
documentation of AggregateFunction for more information on the new function
design. |
<T,ACC> void |
registerFunction(String name,
org.apache.flink.table.functions.TableAggregateFunction<T,ACC> tableAggregateFunction)
Deprecated.
Use
TableEnvironment.createTemporarySystemFunction(String, UserDefinedFunction) instead.
Please note that the new method also uses the new type system and reflective extraction
logic. It might be necessary to update the function implementation as well. See the
documentation of TableAggregateFunction for more information on the new function
design. |
<T> void |
registerFunction(String name,
org.apache.flink.table.functions.TableFunction<T> tableFunction)
Deprecated.
Use
TableEnvironment.createTemporarySystemFunction(String, UserDefinedFunction) instead.
Please note that the new method also uses the new type system and reflective extraction
logic. It might be necessary to update the function implementation as well. See the
documentation of TableFunction for more information on the new function design. |
<T> org.apache.flink.streaming.api.datastream.DataStream<T> |
toAppendStream(org.apache.flink.table.api.Table table,
Class<T> clazz)
Converts the given
Table into an append DataStream of a specified type. |
<T> org.apache.flink.streaming.api.datastream.DataStream<T> |
toAppendStream(org.apache.flink.table.api.Table table,
org.apache.flink.api.common.typeinfo.TypeInformation<T> typeInfo)
Converts the given
Table into an append DataStream of a specified type. |
<T> org.apache.flink.streaming.api.datastream.DataStream<org.apache.flink.api.java.tuple.Tuple2<Boolean,T>> |
toRetractStream(org.apache.flink.table.api.Table table,
Class<T> clazz)
Converts the given
Table into a DataStream of add and retract messages. |
<T> org.apache.flink.streaming.api.datastream.DataStream<org.apache.flink.api.java.tuple.Tuple2<Boolean,T>> |
toRetractStream(org.apache.flink.table.api.Table table,
org.apache.flink.api.common.typeinfo.TypeInformation<T> typeInfo)
Converts the given
Table into a DataStream of add and retract messages. |
create, createFunction, createFunction, createStatementSet, createTemporaryFunction, createTemporaryFunction, createTemporarySystemFunction, createTemporarySystemFunction, createTemporaryView, dropFunction, dropTemporaryFunction, dropTemporarySystemFunction, dropTemporaryTable, dropTemporaryView, executeSql, explain, explain, explain, explainSql, from, fromTableSource, fromValues, fromValues, fromValues, fromValues, fromValues, fromValues, getCatalog, getCompletionHints, getConfig, getCurrentCatalog, getCurrentDatabase, insertInto, insertInto, listCatalogs, listDatabases, listFunctions, listModules, listTables, listTemporaryTables, listTemporaryViews, listUserDefinedFunctions, listViews, loadModule, registerCatalog, registerFunction, registerTable, scan, sqlQuery, sqlUpdate, unloadModule, useCatalog, useDatabasestatic StreamTableEnvironment create(org.apache.flink.streaming.api.environment.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.
Tables 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(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment executionEnvironment, org.apache.flink.table.api.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.
Tables 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(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment executionEnvironment, org.apache.flink.table.api.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.
Tables 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.@Deprecated <T> void registerFunction(String name, org.apache.flink.table.functions.TableFunction<T> tableFunction)
TableEnvironment.createTemporarySystemFunction(String, UserDefinedFunction) instead.
Please note that the new method also uses the new type system and reflective extraction
logic. It might be necessary to update the function implementation as well. See the
documentation of TableFunction for more information on the new function design.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.@Deprecated <T,ACC> void registerFunction(String name, org.apache.flink.table.functions.AggregateFunction<T,ACC> aggregateFunction)
TableEnvironment.createTemporarySystemFunction(String, UserDefinedFunction) instead.
Please note that the new method also uses the new type system and reflective extraction
logic. It might be necessary to update the function implementation as well. See the
documentation of AggregateFunction for more information on the new function
design.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.ACC - The type of aggregate accumulator.name - The name under which the function is registered.aggregateFunction - The AggregateFunction to register.@Deprecated <T,ACC> void registerFunction(String name, org.apache.flink.table.functions.TableAggregateFunction<T,ACC> tableAggregateFunction)
TableEnvironment.createTemporarySystemFunction(String, UserDefinedFunction) instead.
Please note that the new method also uses the new type system and reflective extraction
logic. It might be necessary to update the function implementation as well. See the
documentation of TableAggregateFunction for more information on the new function
design.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.ACC - The type of aggregate accumulator.name - The name under which the function is registered.tableAggregateFunction - The TableAggregateFunction to register.<T> org.apache.flink.table.api.Table fromDataStream(org.apache.flink.streaming.api.datastream.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.@Deprecated <T> org.apache.flink.table.api.Table fromDataStream(org.apache.flink.streaming.api.datastream.DataStream<T> dataStream, String fields)
fromDataStream(DataStream, Expression...)DataStream into a Table with specified field names.
There are two modes for mapping original fields to the fields of the Table:
1. Reference input fields by name: All fields in the schema definition are referenced by name (and possibly renamed using an alias (as). Moreover, we can define proctime and rowtime attributes at arbitrary positions using arbitrary names (except those that exist in the result schema). In this mode, fields can be reordered and projected out. This mode can be used for any input type, including POJOs.
Example:
DataStream<Tuple2<String, Long>> stream = ...
// reorder the fields, rename the original 'f0' field to 'name' and add event-time
// attribute named 'rowtime'
Table table = tableEnv.fromDataStream(stream, "f1, rowtime.rowtime, f0 as 'name'");
2. Reference input fields by position: In this mode, fields are simply renamed. Event-time
attributes can replace the field on their position in the input data (if it is of correct
type) or be appended at the end. Proctime attributes must be appended at the end. This mode
can only be used if the input type has a defined field order (tuple, case class, Row) and
none of the fields references a field of the input type.
Example:
DataStream<Tuple2<String, Long>> stream = ...
// rename the original fields to 'a' and 'b' and extract the internally attached timestamp into an event-time
// attribute named 'rowtime'
Table table = tableEnv.fromDataStream(stream, "a, b, rowtime.rowtime");
T - The type of the DataStream.dataStream - The DataStream to be converted.fields - The fields expressions to map original fields of the DataStream to the fields
of the Table.Table.<T> org.apache.flink.table.api.Table fromDataStream(org.apache.flink.streaming.api.datastream.DataStream<T> dataStream,
org.apache.flink.table.expressions.Expression... fields)
DataStream into a Table with specified field names.
There are two modes for mapping original fields to the fields of the Table:
1. Reference input fields by name: All fields in the schema definition are referenced by name (and possibly renamed using an alias (as). Moreover, we can define proctime and rowtime attributes at arbitrary positions using arbitrary names (except those that exist in the result schema). In this mode, fields can be reordered and projected out. This mode can be used for any input type, including POJOs.
Example:
DataStream<Tuple2<String, Long>> stream = ...
Table table = tableEnv.fromDataStream(
stream,
$("f1"), // reorder and use the original field
$("rowtime").rowtime(), // extract the internally attached timestamp into an event-time
// attribute named 'rowtime'
$("f0").as("name") // reorder and give the original field a better name
);
2. Reference input fields by position: In this mode, fields are simply renamed. Event-time
attributes can replace the field on their position in the input data (if it is of correct
type) or be appended at the end. Proctime attributes must be appended at the end. This mode
can only be used if the input type has a defined field order (tuple, case class, Row) and
none of the fields references a field of the input type.
Example:
DataStream<Tuple2<String, Long>> stream = ...
Table table = tableEnv.fromDataStream(
stream,
$("a"), // rename the first field to 'a'
$("b"), // rename the second field to 'b'
$("rowtime").rowtime() // extract the internally attached timestamp into an event-time
// attribute named 'rowtime'
);
T - The type of the DataStream.dataStream - The DataStream to be converted.fields - The fields expressions to map original fields of the DataStream to the fields
of the Table.Table.@Deprecated <T> void registerDataStream(String name, org.apache.flink.streaming.api.datastream.DataStream<T> dataStream)
createTemporaryView(String, DataStream)DataStream. Registered views can be referenced in SQL
queries.
The field names of the Table are automatically derived from the type of the DataStream.
The view is registered in the namespace of the current catalog and database. To register
the view in a different catalog use createTemporaryView(String, DataStream).
Temporary objects can shadow permanent ones. If a permanent object in a given path exists, it will be inaccessible in the current session. To make the permanent object available again you can drop the corresponding temporary object.
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 createTemporaryView(String path, org.apache.flink.streaming.api.datastream.DataStream<T> dataStream)
DataStream in a given path. Registered views can be
referenced in SQL queries.
The field names of the Table are automatically derived from the type of the DataStream.
Temporary objects can shadow permanent ones. If a permanent object in a given path exists, it will be inaccessible in the current session. To make the permanent object available again you can drop the corresponding temporary object.
T - The type of the DataStream.path - The path under which the DataStream is created. See also the TableEnvironment class description for the format of the path.dataStream - The DataStream out of which to create the view.@Deprecated <T> void registerDataStream(String name, org.apache.flink.streaming.api.datastream.DataStream<T> dataStream, String fields)
createTemporaryView(String, DataStream, Expression...)DataStream in a given path with specified field names.
Registered views can be referenced in SQL queries.
There are two modes for mapping original fields to the fields of the View:
1. Reference input fields by name: All fields in the schema definition are referenced by name (and possibly renamed using an alias (as). Moreover, we can define proctime and rowtime attributes at arbitrary positions using arbitrary names (except those that exist in the result schema). In this mode, fields can be reordered and projected out. This mode can be used for any input type, including POJOs.
Example:
DataStream<Tuple2<String, Long>> stream = ...
// reorder the fields, rename the original 'f0' field to 'name' and add event-time
// attribute named 'rowtime'
tableEnv.registerDataStream("myTable", stream, "f1, rowtime.rowtime, f0 as 'name'");
2. Reference input fields by position: In this mode, fields are simply renamed. Event-time
attributes can replace the field on their position in the input data (if it is of correct
type) or be appended at the end. Proctime attributes must be appended at the end. This mode
can only be used if the input type has a defined field order (tuple, case class, Row) and
none of the fields references a field of the input type.
Example:
DataStream<Tuple2<String, Long>> stream = ...
// rename the original fields to 'a' and 'b' and extract the internally attached timestamp into an event-time
// attribute named 'rowtime'
tableEnv.registerDataStream("myTable", stream, "a, b, rowtime.rowtime");
The view is registered in the namespace of the current catalog and database. To register
the view in a different catalog use createTemporaryView(String, DataStream).
Temporary objects can shadow permanent ones. If a permanent object in a given path exists, it will be inaccessible in the current session. To make the permanent object available again you can drop the corresponding temporary object.
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 fields expressions to map original fields of the DataStream to the fields
of the View.@Deprecated <T> void createTemporaryView(String path, org.apache.flink.streaming.api.datastream.DataStream<T> dataStream, String fields)
createTemporaryView(String, DataStream, Expression...)DataStream in a given path with specified field names.
Registered views can be referenced in SQL queries.
There are two modes for mapping original fields to the fields of the View:
1. Reference input fields by name: All fields in the schema definition are referenced by name (and possibly renamed using an alias (as). Moreover, we can define proctime and rowtime attributes at arbitrary positions using arbitrary names (except those that exist in the result schema). In this mode, fields can be reordered and projected out. This mode can be used for any input type, including POJOs.
Example:
DataStream<Tuple2<String, Long>> stream = ...
// reorder the fields, rename the original 'f0' field to 'name' and add event-time
// attribute named 'rowtime'
tableEnv.createTemporaryView("cat.db.myTable", stream, "f1, rowtime.rowtime, f0 as 'name'");
2. Reference input fields by position: In this mode, fields are simply renamed. Event-time
attributes can replace the field on their position in the input data (if it is of correct
type) or be appended at the end. Proctime attributes must be appended at the end. This mode
can only be used if the input type has a defined field order (tuple, case class, Row) and
none of the fields references a field of the input type.
Example:
DataStream<Tuple2<String, Long>> stream = ...
// rename the original fields to 'a' and 'b' and extract the internally attached timestamp into an event-time
// attribute named 'rowtime'
tableEnv.createTemporaryView("cat.db.myTable", stream, "a, b, rowtime.rowtime");
Temporary objects can shadow permanent ones. If a permanent object in a given path exists, it will be inaccessible in the current session. To make the permanent object available again you can drop the corresponding temporary object.
T - The type of the DataStream.path - The path under which the DataStream is created. See also the TableEnvironment class description for the format of the path.dataStream - The DataStream out of which to create the view.fields - The fields expressions to map original fields of the DataStream to the fields
of the View.<T> void createTemporaryView(String path, org.apache.flink.streaming.api.datastream.DataStream<T> dataStream, org.apache.flink.table.expressions.Expression... fields)
DataStream in a given path with specified field names.
Registered views can be referenced in SQL queries.
There are two modes for mapping original fields to the fields of the View:
1. Reference input fields by name: All fields in the schema definition are referenced by name (and possibly renamed using an alias (as). Moreover, we can define proctime and rowtime attributes at arbitrary positions using arbitrary names (except those that exist in the result schema). In this mode, fields can be reordered and projected out. This mode can be used for any input type, including POJOs.
Example:
DataStream<Tuple2<String, Long>> stream = ...
tableEnv.createTemporaryView(
"cat.db.myTable",
stream,
$("f1"), // reorder and use the original field
$("rowtime").rowtime(), // extract the internally attached timestamp into an event-time
// attribute named 'rowtime'
$("f0").as("name") // reorder and give the original field a better name
);
2. Reference input fields by position: In this mode, fields are simply renamed. Event-time
attributes can replace the field on their position in the input data (if it is of correct
type) or be appended at the end. Proctime attributes must be appended at the end. This mode
can only be used if the input type has a defined field order (tuple, case class, Row) and
none of the fields references a field of the input type.
Example:
DataStream<Tuple2<String, Long>> stream = ...
tableEnv.createTemporaryView(
"cat.db.myTable",
stream,
$("a"), // rename the first field to 'a'
$("b"), // rename the second field to 'b'
$("rowtime").rowtime() // adds an event-time attribute named 'rowtime'
);
Temporary objects can shadow permanent ones. If a permanent object in a given path exists, it will be inaccessible in the current session. To make the permanent object available again you can drop the corresponding temporary object.
T - The type of the DataStream.path - The path under which the DataStream is created. See also the TableEnvironment class description for the format of the path.dataStream - The DataStream out of which to create the view.fields - The fields expressions to map original fields of the DataStream to the fields
of the View.<T> org.apache.flink.streaming.api.datastream.DataStream<T> toAppendStream(org.apache.flink.table.api.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> org.apache.flink.streaming.api.datastream.DataStream<T> toAppendStream(org.apache.flink.table.api.Table table,
org.apache.flink.api.common.typeinfo.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> org.apache.flink.streaming.api.datastream.DataStream<org.apache.flink.api.java.tuple.Tuple2<Boolean,T>> toRetractStream(org.apache.flink.table.api.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> org.apache.flink.streaming.api.datastream.DataStream<org.apache.flink.api.java.tuple.Tuple2<Boolean,T>> toRetractStream(org.apache.flink.table.api.Table table, org.apache.flink.api.common.typeinfo.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.@Deprecated org.apache.flink.table.descriptors.StreamTableDescriptor connect(org.apache.flink.table.descriptors.ConnectorDescriptor connectorDescriptor)
CREATE TABLE DDL is richer than this part of the API. This method
might be refactored in the next versions. Please use executeSql(ddl) to register a table instead.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("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()
.createTemporaryTable("MyTable")
connect in interface org.apache.flink.table.api.TableEnvironmentconnectorDescriptor - connector descriptor describing the external systemorg.apache.flink.api.common.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.
execute in interface org.apache.flink.table.api.TableEnvironmentjobName - Desired name of the jobException - which occurs during job execution.Copyright © 2014–2021 The Apache Software Foundation. All rights reserved.