public abstract class StreamTableEnvironment extends TableEnvironment
A TableEnvironment can be used to:
- convert DataStream
to a Table
- register a DataStream
as a table in the catalog
- register a Table
in the catalog
- scan a registered table to obtain a Table
- specify a SQL query on registered tables to obtain a Table
- convert a Table
into a DataStream
Constructor and Description |
---|
StreamTableEnvironment(StreamExecutionEnvironment execEnv,
TableConfig config) |
Modifier and Type | Method and Description |
---|---|
protected void |
checkValidTableName(String name)
Checks if the chosen table name is valid.
|
protected String |
createUniqueTableName()
Returns a unique table name according to the internal naming pattern.
|
StreamExecutionEnvironment |
execEnv() |
String |
explain(Table table)
Returns the AST of the specified Table API and SQL queries and the execution plan to compute
the result of the given
Table . |
protected org.apache.calcite.tools.RuleSet |
getBuiltInRuleSet()
Returns the built-in rules that are defined by the environment.
|
protected <A> scala.Tuple2<String[],int[]> |
getFieldInfo(TypeInformation<A> inputType)
Returns field names and field positions for a given
TypeInformation . |
protected <A> scala.Tuple2<String[],int[]> |
getFieldInfo(TypeInformation<A> inputType,
Expression[] exprs)
Returns field names and field positions for a given
TypeInformation and Array of
Expression . |
Table |
ingest(String tableName)
Ingests a registered table and returns the resulting
Table . |
org.apache.calcite.rel.RelNode |
optimize(org.apache.calcite.rel.RelNode relNode)
Generates the optimized
RelNode tree from the original relational node tree. |
protected <T> void |
registerDataStreamInternal(String name,
DataStream<T> dataStream)
Registers a
DataStream as a table under a given name in the TableEnvironment 's
catalog. |
protected <T> void |
registerDataStreamInternal(String name,
DataStream<T> dataStream,
Expression[] fields)
Registers a
DataStream as a table under a given name with field names as specified by
field expressions in the TableEnvironment 's catalog. |
void |
registerTableSource(String name,
StreamTableSource<?> tableSource)
Registers an external
StreamTableSource in this TableEnvironment 's catalog. |
Table |
sql(String query)
Evaluates a SQL query on registered tables and retrieves the result as a
Table . |
protected <A> DataStream<A> |
translate(org.apache.calcite.rel.RelNode logicalPlan,
TypeInformation<A> tpe)
Translates a logical
RelNode into a DataStream . |
protected <A> DataStream<A> |
translate(Table table,
TypeInformation<A> tpe)
Translates a
Table into a DataStream . |
<T> void |
writeToSink(Table table,
TableSink<T> sink)
Writes a
Table to a TableSink . |
config, createUniqueAttributeName, getConfig, getFieldIndices, getFieldIndices, getFieldNames, getFieldNames, getFieldTypes, getFrameworkConfig, getFunctionCatalog, getPlanner, getRelBuilder, getRowType, getRuleSet, getSqlOperatorTable, getSqlParserConfig, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTypeFactory, isRegistered, registerFunction, registerTable, registerTableFunctionInternal, registerTableInternal, relBuilder, replaceRegisteredTable, validateType
public StreamTableEnvironment(StreamExecutionEnvironment execEnv, TableConfig config)
public StreamExecutionEnvironment execEnv()
protected void checkValidTableName(String name)
checkValidTableName
in class TableEnvironment
name
- The table name to check.protected String createUniqueTableName()
protected <A> scala.Tuple2<String[],int[]> getFieldInfo(TypeInformation<A> inputType)
TypeInformation
.
Field names are automatically extracted for
CompositeType
.
The method fails if inputType is not a
CompositeType
.
getFieldInfo
in class TableEnvironment
inputType
- The TypeInformation extract the field names and positions from.protected <A> scala.Tuple2<String[],int[]> getFieldInfo(TypeInformation<A> inputType, Expression[] exprs)
TypeInformation
and Array
of
Expression
.
getFieldInfo
in class TableEnvironment
inputType
- The TypeInformation
against which the Expression
s are evaluated.exprs
- The expressions that define the field names.public Table ingest(String tableName)
Table
.
The table to ingest must be registered in the TableEnvironment
's catalog.
tableName
- The name of the table to ingest.ValidationException
- if no table is registered under the given name.public void registerTableSource(String name, StreamTableSource<?> tableSource)
StreamTableSource
in this TableEnvironment
's catalog.
Registered tables can be referenced in SQL queries.
name
- The name under which the StreamTableSource
is registered.tableSource
- The StreamTableSource
to register.public Table sql(String query)
Table
.
All tables referenced by the query must be registered in the TableEnvironment.
sql
in class TableEnvironment
query
- The SQL query to evaluate.public <T> void writeToSink(Table table, TableSink<T> sink)
Table
to a TableSink
.
Internally, the Table
is translated into a DataStream
and handed over to the
TableSink
to write it.
writeToSink
in class TableEnvironment
table
- The Table
to write.sink
- The TableSink
to write the Table
to.protected <T> void registerDataStreamInternal(String name, DataStream<T> dataStream)
DataStream
as a table under a given name in the TableEnvironment
's
catalog.
name
- The name under which the table is registered in the catalog.dataStream
- The DataStream
to register as table in the catalog.protected <T> void registerDataStreamInternal(String name, DataStream<T> dataStream, Expression[] fields)
DataStream
as a table under a given name with field names as specified by
field expressions in the TableEnvironment
's catalog.
name
- The name under which the table is registered in the catalog.dataStream
- The DataStream
to register as table in the catalog.fields
- The field expressions to define the field names of the table.protected org.apache.calcite.tools.RuleSet getBuiltInRuleSet()
getBuiltInRuleSet
in class TableEnvironment
public org.apache.calcite.rel.RelNode optimize(org.apache.calcite.rel.RelNode relNode)
RelNode
tree from the original relational node tree.
relNode
- The root node of the relational expression tree.RelNode
treeprotected <A> DataStream<A> translate(Table table, TypeInformation<A> tpe)
Table
into a DataStream
.
The transformation involves optimizing the relational expression tree as defined by
Table API calls and / or SQL queries and generating corresponding DataStream
operators.
table
- The root node of the relational expression tree.tpe
- The TypeInformation
of the resulting DataStream
.DataStream
that corresponds to the translated Table
.protected <A> DataStream<A> translate(org.apache.calcite.rel.RelNode logicalPlan, TypeInformation<A> tpe)
RelNode
into a DataStream
.
logicalPlan
- The root node of the relational expression tree.tpe
- The TypeInformation
of the resulting DataStream
.DataStream
that corresponds to the translated Table
.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.