@PublicEvolving
public interface BatchTableEnvironment
extends org.apache.flink.table.api.TableEnvironment
TableEnvironment for a Java batch ExecutionEnvironment that works
with DataSets.
A TableEnvironment can be used to:
DataSet to a TableDataSet in the TableEnvironment's catalogTable in the TableEnvironment's catalogTableTableTable into a DataSetTable| Modifier and Type | Method and Description |
|---|---|
org.apache.flink.table.descriptors.BatchTableDescriptor |
connect(org.apache.flink.table.descriptors.ConnectorDescriptor connectorDescriptor)
Creates a table source and/or table sink from a descriptor.
|
static BatchTableEnvironment |
create(org.apache.flink.api.java.ExecutionEnvironment executionEnvironment)
Returns a
TableEnvironment for a Java batch ExecutionEnvironment that works
with DataSets. |
static BatchTableEnvironment |
create(org.apache.flink.api.java.ExecutionEnvironment executionEnvironment,
org.apache.flink.table.api.TableConfig tableConfig)
Returns a
TableEnvironment for a Java batch ExecutionEnvironment that works
with DataSets. |
<T> void |
createTemporaryView(String path,
org.apache.flink.api.java.DataSet<T> dataSet)
Creates a view from the given
DataSet in a given path. |
<T> void |
createTemporaryView(String path,
org.apache.flink.api.java.DataSet<T> dataSet,
String fields)
Creates a view from the given
DataSet in a given path with specified field names. |
<T> org.apache.flink.table.api.Table |
fromDataSet(org.apache.flink.api.java.DataSet<T> dataSet)
Converts the given
DataSet into a Table. |
<T> org.apache.flink.table.api.Table |
fromDataSet(org.apache.flink.api.java.DataSet<T> dataSet,
String fields)
Converts the given
DataSet into a Table with specified field names. |
void |
insertInto(org.apache.flink.table.api.Table table,
org.apache.flink.table.api.BatchQueryConfig queryConfig,
String sinkPath,
String... sinkPathContinued)
Deprecated.
use
TableEnvironment.insertInto(String, Table) |
<T> void |
registerDataSet(String name,
org.apache.flink.api.java.DataSet<T> dataSet)
Deprecated.
|
<T> void |
registerDataSet(String name,
org.apache.flink.api.java.DataSet<T> dataSet,
String fields)
Deprecated.
|
<T,ACC> void |
registerFunction(String name,
org.apache.flink.table.functions.AggregateFunction<T,ACC> aggregateFunction)
Registers an
AggregateFunction under a unique name in the TableEnvironment's catalog. |
<T> void |
registerFunction(String name,
org.apache.flink.table.functions.TableFunction<T> tableFunction)
Registers a
TableFunction under a unique name in the TableEnvironment's catalog. |
void |
sqlUpdate(String stmt,
org.apache.flink.table.api.BatchQueryConfig config)
Evaluates a SQL statement such as INSERT, UPDATE or DELETE; or a DDL statement;
NOTE: Currently only SQL INSERT statements are supported.
|
<T> org.apache.flink.api.java.DataSet<T> |
toDataSet(org.apache.flink.table.api.Table table,
Class<T> clazz)
Converts the given
Table into a DataSet of a specified type. |
<T> org.apache.flink.api.java.DataSet<T> |
toDataSet(org.apache.flink.table.api.Table table,
Class<T> clazz,
org.apache.flink.table.api.BatchQueryConfig queryConfig)
Converts the given
Table into a DataSet of a specified type. |
<T> org.apache.flink.api.java.DataSet<T> |
toDataSet(org.apache.flink.table.api.Table table,
org.apache.flink.api.common.typeinfo.TypeInformation<T> typeInfo)
Converts the given
Table into a DataSet of a specified type. |
<T> org.apache.flink.api.java.DataSet<T> |
toDataSet(org.apache.flink.table.api.Table table,
org.apache.flink.api.common.typeinfo.TypeInformation<T> typeInfo,
org.apache.flink.table.api.BatchQueryConfig queryConfig)
Converts the given
Table into a DataSet of a specified type. |
create, createTemporaryView, dropTemporaryTable, dropTemporaryView, execute, explain, explain, explain, from, fromTableSource, getCatalog, getCompletionHints, getConfig, getCurrentCatalog, getCurrentDatabase, insertInto, insertInto, listCatalogs, listDatabases, listFunctions, listModules, listTables, listTemporaryTables, listTemporaryViews, listUserDefinedFunctions, loadModule, registerCatalog, registerFunction, registerTable, registerTableSink, registerTableSink, registerTableSource, scan, sqlQuery, sqlUpdate, unloadModule, useCatalog, useDatabase<T> void registerFunction(String name, org.apache.flink.table.functions.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, org.apache.flink.table.functions.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.ACC - The type of aggregate accumulator.name - The name under which the function is registered.aggregateFunction - The AggregateFunction to register.<T> org.apache.flink.table.api.Table fromDataSet(org.apache.flink.api.java.DataSet<T> dataSet)
DataSet into a Table.
The field names of the Table are automatically derived from the type of the
DataSet.
T - The type of the DataSet.dataSet - The DataSet to be converted.Table.<T> org.apache.flink.table.api.Table fromDataSet(org.apache.flink.api.java.DataSet<T> dataSet,
String fields)
DataSet into a Table with specified field names.
Example:
DataSet<Tuple2<String, Long>> set = ...
Table tab = tableEnv.fromDataSet(set, "a, b");
T - The type of the DataSet.dataSet - The DataSet to be converted.fields - The field names of the resulting Table.Table.@Deprecated <T> void registerDataSet(String name, org.apache.flink.api.java.DataSet<T> dataSet)
createTemporaryView(String, DataSet)DataSet.
Registered views can be referenced in SQL queries.
The field names of the Table are automatically derived
from the type of the DataSet.
The view is registered in the namespace of the current catalog and database. To register the view in
a different catalog use createTemporaryView(String, DataSet).
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 DataSet to register.name - The name under which the DataSet is registered in the catalog.dataSet - The DataSet to register.<T> void createTemporaryView(String path, org.apache.flink.api.java.DataSet<T> dataSet)
DataSet 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 DataSet.
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 DataSet.path - The path under which the view is created.
See also the TableEnvironment class description for the format of the path.dataSet - The DataSet out of which to create the view.@Deprecated <T> void registerDataSet(String name, org.apache.flink.api.java.DataSet<T> dataSet, String fields)
createTemporaryView(String, DataSet, String)DataSet in a given path with specified field names.
Registered views can be referenced in SQL queries.
Example:
DataSet<Tuple2<String, Long>> set = ...
tableEnv.registerDataSet("myTable", set, "a, b");
The view is registered in the namespace of the current catalog and database. To register the view in
a different catalog use createTemporaryView(String, DataSet).
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 DataSet to register.name - The name under which the DataSet is registered in the catalog.dataSet - The DataSet to register.fields - The field names of the registered view.<T> void createTemporaryView(String path, org.apache.flink.api.java.DataSet<T> dataSet, String fields)
DataSet in a given path with specified field names.
Registered views can be referenced in SQL queries.
Example:
DataSet<Tuple2<String, Long>> set = ...
tableEnv.createTemporaryView("cat.db.myTable", set, "a, b");
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 DataSet.path - The path under which the view is created.
See also the TableEnvironment class description for the format of the path.dataSet - The DataSet out of which to create the view.fields - The field names of the registered view.<T> org.apache.flink.api.java.DataSet<T> toDataSet(org.apache.flink.table.api.Table table,
Class<T> clazz)
Table into a DataSet of a specified type.
The fields of the Table are mapped to DataSet fields as follows:
Row and Tuple
types: Fields are mapped by position, field types must match.DataSet types: Fields are mapped by field name, field types must match.T - The type of the resulting DataSet.table - The Table to convert.clazz - The class of the type of the resulting DataSet.DataSet.<T> org.apache.flink.api.java.DataSet<T> toDataSet(org.apache.flink.table.api.Table table,
org.apache.flink.api.common.typeinfo.TypeInformation<T> typeInfo)
Table into a DataSet of a specified type.
The fields of the Table are mapped to DataSet fields as follows:
Row and Tuple
types: Fields are mapped by position, field types must match.DataSet types: Fields are mapped by field name, field types must match.T - The type of the resulting DataSet.table - The Table to convert.typeInfo - The TypeInformation that specifies the type of the resulting DataSet.DataSet.<T> org.apache.flink.api.java.DataSet<T> toDataSet(org.apache.flink.table.api.Table table,
Class<T> clazz,
org.apache.flink.table.api.BatchQueryConfig queryConfig)
Table into a DataSet of a specified type.
The fields of the Table are mapped to DataSet fields as follows:
Row and Tuple
types: Fields are mapped by position, field types must match.DataSet types: Fields are mapped by field name, field types must match.T - The type of the resulting DataSet.table - The Table to convert.clazz - The class of the type of the resulting DataSet.queryConfig - The configuration for the query to generate.DataSet.<T> org.apache.flink.api.java.DataSet<T> toDataSet(org.apache.flink.table.api.Table table,
org.apache.flink.api.common.typeinfo.TypeInformation<T> typeInfo,
org.apache.flink.table.api.BatchQueryConfig queryConfig)
Table into a DataSet of a specified type.
The fields of the Table are mapped to DataSet fields as follows:
Row and Tuple
types: Fields are mapped by position, field types must match.DataSet types: Fields are mapped by field name, field types must match.T - The type of the resulting DataSet.table - The Table to convert.typeInfo - The TypeInformation that specifies the type of the resulting DataSet.queryConfig - The configuration for the query to generate.DataSet.void sqlUpdate(String stmt, org.apache.flink.table.api.BatchQueryConfig 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 BatchQueryConfig to use.@Deprecated void insertInto(org.apache.flink.table.api.Table table, org.apache.flink.table.api.BatchQueryConfig queryConfig, String sinkPath, String... sinkPathContinued)
TableEnvironment.insertInto(String, Table)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 BatchQueryConfig 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.org.apache.flink.table.descriptors.BatchTableDescriptor connect(org.apache.flink.table.descriptors.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 connector using a JSON format and registering a table source as "MyTable":
tableEnv
.connect(
new ExternalSystemXYZ()
.version("0.11"))
.withFormat(
new Json()
.jsonSchema("{...}")
.failOnMissingField(false))
.withSchema(
new Schema()
.field("user-name", "VARCHAR").from("u_name")
.field("count", "DECIMAL")
.registerSource("MyTable")
connect in interface org.apache.flink.table.api.TableEnvironmentconnectorDescriptor - connector descriptor describing the external systemstatic BatchTableEnvironment create(org.apache.flink.api.java.ExecutionEnvironment executionEnvironment)
TableEnvironment for a Java batch ExecutionEnvironment that works
with DataSets.
A TableEnvironment can be used to:
DataSet to a TableDataSet in the TableEnvironment's catalogTable in the TableEnvironment's catalogTableTableTable into a DataSetTableexecutionEnvironment - The Java batch ExecutionEnvironment of the TableEnvironment.static BatchTableEnvironment create(org.apache.flink.api.java.ExecutionEnvironment executionEnvironment, org.apache.flink.table.api.TableConfig tableConfig)
TableEnvironment for a Java batch ExecutionEnvironment that works
with DataSets.
A TableEnvironment can be used to:
DataSet to a TableDataSet in the TableEnvironment's catalogTable in the TableEnvironment's catalogTableTableTable into a DataSetTableexecutionEnvironment - The Java batch ExecutionEnvironment of the TableEnvironment.tableConfig - The configuration of the TableEnvironment.Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.