@PublicEvolving public interface BatchTableEnvironment extends TableEnvironment
TableEnvironment
for a Java batch ExecutionEnvironment
that works
with DataSet
s.
A TableEnvironment can be used to:
DataSet
to a Table
DataSet
in the TableEnvironment
's catalogTable
in the TableEnvironment
's catalogTable
Table
Table
into a DataSet
Table
Modifier and Type | Method and Description |
---|---|
BatchTableDescriptor |
connect(ConnectorDescriptor connectorDescriptor)
Creates a table source and/or table sink from a descriptor.
|
static BatchTableEnvironment |
create(ExecutionEnvironment executionEnvironment)
|
static BatchTableEnvironment |
create(ExecutionEnvironment executionEnvironment,
TableConfig tableConfig)
|
<T> Table |
fromDataSet(DataSet<T> dataSet)
|
<T> Table |
fromDataSet(DataSet<T> dataSet,
String fields)
|
void |
insertInto(Table table,
BatchQueryConfig queryConfig,
String sinkPath,
String... sinkPathContinued)
|
<T> void |
registerDataSet(String name,
DataSet<T> dataSet)
Registers the given
DataSet as table in the
TableEnvironment 's catalog. |
<T> void |
registerDataSet(String name,
DataSet<T> dataSet,
String fields)
Registers the given
DataSet 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> void |
registerFunction(String name,
TableFunction<T> tableFunction)
Registers a
TableFunction under a unique name in the TableEnvironment's catalog. |
void |
sqlUpdate(String stmt,
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> DataSet<T> |
toDataSet(Table table,
Class<T> clazz)
|
<T> DataSet<T> |
toDataSet(Table table,
Class<T> clazz,
BatchQueryConfig queryConfig)
|
<T> DataSet<T> |
toDataSet(Table table,
TypeInformation<T> typeInfo)
|
<T> DataSet<T> |
toDataSet(Table table,
TypeInformation<T> typeInfo,
BatchQueryConfig queryConfig)
|
create, execute, 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
<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.ACC
- The type of aggregate accumulator.name
- The name under which the function is registered.aggregateFunction
- The AggregateFunction to register.<T> void registerDataSet(String name, DataSet<T> dataSet)
DataSet
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 theDataSet
.<T> void registerDataSet(String name, DataSet<T> dataSet, String fields)
DataSet
as table with specified field names in the
TableEnvironment
's catalog.
Registered tables can be referenced in SQL queries.
Example:
DataSet<Tuple2<String, Long>> set = ...
tableEnv.registerDataSet("myTable", set, "a, b");
<T> DataSet<T> toDataSet(Table table, TypeInformation<T> typeInfo)
Table
into a DataSet
of a specified type.
The fields of the Table
are mapped to DataSet
fields as follows:
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> DataSet<T> toDataSet(Table table, Class<T> clazz, BatchQueryConfig queryConfig)
<T> DataSet<T> toDataSet(Table table, TypeInformation<T> typeInfo, BatchQueryConfig queryConfig)
Table
into a DataSet
of a specified type.
The fields of the Table
are mapped to DataSet
fields as follows:
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, 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.void insertInto(Table table, BatchQueryConfig 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 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.BatchTableDescriptor 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 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 TableEnvironment
connectorDescriptor
- connector descriptor describing the external systemstatic BatchTableEnvironment create(ExecutionEnvironment executionEnvironment)
TableEnvironment
for a Java batch ExecutionEnvironment
that works
with DataSet
s.
A TableEnvironment can be used to:
DataSet
to a Table
DataSet
in the TableEnvironment
's catalogTable
in the TableEnvironment
's catalogTable
Table
Table
into a DataSet
Table
executionEnvironment
- The Java batch ExecutionEnvironment
of the TableEnvironment.static BatchTableEnvironment create(ExecutionEnvironment executionEnvironment, TableConfig tableConfig)
TableEnvironment
for a Java batch ExecutionEnvironment
that works
with DataSet
s.
A TableEnvironment can be used to:
DataSet
to a Table
DataSet
in the TableEnvironment
's catalogTable
in the TableEnvironment
's catalogTable
Table
Table
into a DataSet
Table
executionEnvironment
- The Java batch ExecutionEnvironment
of the TableEnvironment.tableConfig
- The configuration of the TableEnvironment.Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.