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
param: execEnv The StreamExecutionEnvironment
which is wrapped in this
StreamTableEnvironment
.
param: config The TableConfig
of this StreamTableEnvironment
.
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 |
getBuiltInDecoRuleSet()
Returns the built-in decoration rules that are defined by the environment.
|
protected org.apache.calcite.tools.RuleSet |
getBuiltInNormRuleSet()
Returns the built-in normalization rules that are defined by the environment.
|
protected org.apache.calcite.tools.RuleSet |
getBuiltInPhysicalOptRuleSet()
Returns the built-in optimization rules that are defined by the environment.
|
protected <IN,OUT> MapFunction<IN,OUT> |
getConversionMapper(TypeInformation<IN> physicalTypeInfo,
RowSchema schema,
TypeInformation<OUT> requestedTypeInfo,
String functionName)
Creates a final converter that maps the internal row type to external type.
|
protected org.apache.calcite.tools.RuleSet |
getDecoRuleSet()
Returns the decoration rule set for this environment
including a custom RuleSet configuration.
|
protected scala.Option<String[]> |
getUniqueKeyFields(org.apache.calcite.rel.RelNode plan)
Extracts the unique keys of the table produced by the plan.
|
protected boolean |
isAppendOnly(org.apache.calcite.rel.RelNode plan)
Validates that the plan produces only append changes.
|
org.apache.calcite.rel.RelNode |
optimize(org.apache.calcite.rel.RelNode relNode,
boolean updatesAsRetraction)
Generates the optimized
RelNode tree from the original relational node tree. |
StreamQueryConfig |
queryConfig() |
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,
TableSource<?> tableSource)
Registers an external
StreamTableSource in this TableEnvironment 's catalog. |
protected <A> DataStream<A> |
translate(org.apache.calcite.rel.RelNode logicalPlan,
org.apache.calcite.rel.type.RelDataType logicalType,
StreamQueryConfig queryConfig,
boolean withChangeFlag,
TypeInformation<A> tpe)
Translates a logical
RelNode into a DataStream . |
protected <A> DataStream<A> |
translate(Table table,
StreamQueryConfig queryConfig,
boolean updatesAsRetraction,
boolean withChangeFlag,
TypeInformation<A> tpe)
Translates a
Table into a DataStream . |
protected DataStream<CRow> |
translateToCRow(org.apache.calcite.rel.RelNode logicalPlan,
StreamQueryConfig queryConfig)
Translates a logical
RelNode plan into a DataStream of type CRow . |
<T> void |
writeToSink(Table table,
TableSink<T> sink,
QueryConfig queryConfig)
Writes a
Table to a TableSink . |
attrNameCntr, config, createUniqueAttributeName, DEFAULT_PROCTIME_ATTRIBUTE, DEFAULT_ROWTIME_ATTRIBUTE, functionCatalog, generateRowConverterFunction, getBuiltInLogicalOptRuleSet, getConfig, getFieldIndices, getFieldIndices, getFieldInfo, getFieldInfo, getFieldNames, getFieldNames, getFieldTypes, getFrameworkConfig, getFunctionCatalog, getLogicalOptRuleSet, getNormRuleSet, getPhysicalOptRuleSet, getPlanner, getRegisteredExternalCatalog, getRelBuilder, getRowType, getSqlOperatorTable, getSqlParserConfig, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTableEnvironment, getTypeFactory, isRegistered, registerAggregateFunctionInternal, registerExternalCatalog, registerFunction, registerTable, registerTableFunctionInternal, registerTableInternal, relBuilder, replaceRegisteredTable, runHepPlanner, runVolcanoPlanner, scan, scan, sql, validateType
public StreamTableEnvironment(StreamExecutionEnvironment execEnv, TableConfig config)
public StreamExecutionEnvironment execEnv()
public StreamQueryConfig queryConfig()
protected void checkValidTableName(String name)
checkValidTableName
in class TableEnvironment
name
- The table name to check.protected String createUniqueTableName()
public void registerTableSource(String name, TableSource<?> tableSource)
StreamTableSource
in this TableEnvironment
's catalog.
Registered tables can be referenced in SQL queries.
registerTableSource
in class TableEnvironment
name
- The name under which the TableSource
is registered.tableSource
- The TableSource
to register.public <T> void writeToSink(Table table, TableSink<T> sink, QueryConfig queryConfig)
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.queryConfig
- The configuration for the query to generate.protected <IN,OUT> MapFunction<IN,OUT> getConversionMapper(TypeInformation<IN> physicalTypeInfo, RowSchema schema, TypeInformation<OUT> requestedTypeInfo, String functionName)
physicalTypeInfo
- the input of the sinkschema
- the input schema with correct field names (esp. for POJO field mapping)requestedTypeInfo
- the output type of the sinkfunctionName
- name of the map function. Must not be unique but has to be a
valid Java class identifier.protected boolean isAppendOnly(org.apache.calcite.rel.RelNode plan)
protected scala.Option<String[]> getUniqueKeyFields(org.apache.calcite.rel.RelNode plan)
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 getDecoRuleSet()
protected org.apache.calcite.tools.RuleSet getBuiltInNormRuleSet()
getBuiltInNormRuleSet
in class TableEnvironment
protected org.apache.calcite.tools.RuleSet getBuiltInPhysicalOptRuleSet()
getBuiltInPhysicalOptRuleSet
in class TableEnvironment
protected org.apache.calcite.tools.RuleSet getBuiltInDecoRuleSet()
public org.apache.calcite.rel.RelNode optimize(org.apache.calcite.rel.RelNode relNode, boolean updatesAsRetraction)
RelNode
tree from the original relational node tree.
relNode
- The root node of the relational expression tree.updatesAsRetraction
- True if the sink requests updates as retraction messages.RelNode
treeprotected <A> DataStream<A> translate(Table table, StreamQueryConfig queryConfig, boolean updatesAsRetraction, boolean withChangeFlag, 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.queryConfig
- The configuration for the query to generate.updatesAsRetraction
- Set to true to encode updates as retraction messages.withChangeFlag
- Set to true to emit records with change flags.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, org.apache.calcite.rel.type.RelDataType logicalType, StreamQueryConfig queryConfig, boolean withChangeFlag, TypeInformation<A> tpe)
RelNode
into a DataStream
.
logicalPlan
- The root node of the relational expression tree.logicalType
- The row type of the result. Since the logicalPlan can lose the
field naming during optimization we pass the row type separately.queryConfig
- The configuration for the query to generate.withChangeFlag
- Set to true to emit records with change flags.tpe
- The TypeInformation
of the resulting DataStream
.DataStream
that corresponds to the translated Table
.protected DataStream<CRow> translateToCRow(org.apache.calcite.rel.RelNode logicalPlan, StreamQueryConfig queryConfig)
RelNode
plan into a DataStream
of type CRow
.
logicalPlan
- The logical plan to translate.queryConfig
- The configuration for the query to generate.DataStream
of type CRow
.Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.