public abstract class TableEnvironment extends Object
param: config The configuration of the TableEnvironment
Constructor and Description |
---|
TableEnvironment(TableConfig config) |
Modifier and Type | Method and Description |
---|---|
AtomicInteger |
attrNameCntr() |
protected abstract void |
checkValidTableName(String name)
Checks if the chosen table name is valid.
|
TableConfig |
config() |
String |
createUniqueAttributeName()
Returns a unique temporary attribute name.
|
static String |
DEFAULT_PROCTIME_ATTRIBUTE() |
static String |
DEFAULT_ROWTIME_ATTRIBUTE() |
FunctionCatalog |
functionCatalog() |
protected <OUT> GeneratedFunction<MapFunction<Row,OUT>,OUT> |
generateRowConverterFunction(TypeInformation<Row> inputTypeInfo,
RowSchema schema,
TypeInformation<OUT> requestedTypeInfo,
String functionName) |
protected org.apache.calcite.tools.RuleSet |
getBuiltInLogicalOptRuleSet()
Returns the built-in logical optimization rules that are defined by the environment.
|
protected abstract org.apache.calcite.tools.RuleSet |
getBuiltInNormRuleSet()
Returns the built-in normalization rules that are defined by the environment.
|
protected abstract org.apache.calcite.tools.RuleSet |
getBuiltInPhysicalOptRuleSet()
Returns the built-in physical optimization rules that are defined by the environment.
|
TableConfig |
getConfig()
Returns the table config to define the runtime behavior of the Table API.
|
static <A> int[] |
getFieldIndices(TableSource<A> tableSource)
Returns field indices for a given
TableSource . |
static int[] |
getFieldIndices(TypeInformation<?> inputType)
Returns field indexes for a given
TypeInformation . |
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 . |
static <A> String[] |
getFieldNames(TableSource<A> tableSource)
Returns field names for a given
TableSource . |
static <A> String[] |
getFieldNames(TypeInformation<A> inputType)
Returns field names for a given
TypeInformation . |
static TypeInformation<?>[] |
getFieldTypes(TypeInformation<?> inputType)
Returns field types for a given
TypeInformation . |
org.apache.calcite.tools.FrameworkConfig |
getFrameworkConfig()
Returns the Calcite
FrameworkConfig of this TableEnvironment. |
FunctionCatalog |
getFunctionCatalog() |
protected org.apache.calcite.tools.RuleSet |
getLogicalOptRuleSet()
Returns the logical optimization rule set for this environment
including a custom RuleSet configuration.
|
protected org.apache.calcite.tools.RuleSet |
getNormRuleSet()
Returns the normalization rule set for this environment
including a custom RuleSet configuration.
|
protected org.apache.calcite.tools.RuleSet |
getPhysicalOptRuleSet()
Returns the physical optimization rule set for this environment
including a custom RuleSet configuration.
|
org.apache.calcite.plan.RelOptPlanner |
getPlanner()
Returns the Calcite
RelOptPlanner of this TableEnvironment. |
ExternalCatalog |
getRegisteredExternalCatalog(String name)
Gets a registered
ExternalCatalog by name. |
FlinkRelBuilder |
getRelBuilder()
Returns the
FlinkRelBuilder of this TableEnvironment. |
protected org.apache.calcite.rel.type.RelDataType |
getRowType(String name) |
protected org.apache.calcite.sql.SqlOperatorTable |
getSqlOperatorTable()
Returns the operator table for this environment including a custom Calcite configuration.
|
protected org.apache.calcite.sql.parser.SqlParser.Config |
getSqlParserConfig()
Returns the SQL parser config for this environment including a custom Calcite configuration.
|
static BatchTableEnvironment |
getTableEnvironment(ExecutionEnvironment executionEnvironment)
Returns a
JavaBatchTableEnv for a Java JavaBatchExecEnv . |
static BatchTableEnvironment |
getTableEnvironment(ExecutionEnvironment executionEnvironment)
Returns a
ScalaBatchTableEnv for a Scala ScalaBatchExecEnv . |
static BatchTableEnvironment |
getTableEnvironment(ExecutionEnvironment executionEnvironment,
TableConfig tableConfig)
|
static BatchTableEnvironment |
getTableEnvironment(ExecutionEnvironment executionEnvironment,
TableConfig tableConfig)
|
static StreamTableEnvironment |
getTableEnvironment(StreamExecutionEnvironment executionEnvironment)
Returns a
JavaStreamTableEnv for a Java JavaStreamExecEnv . |
static StreamTableEnvironment |
getTableEnvironment(StreamExecutionEnvironment executionEnvironment)
Returns a
ScalaStreamTableEnv for a Scala stream ScalaStreamExecEnv . |
static StreamTableEnvironment |
getTableEnvironment(StreamExecutionEnvironment executionEnvironment,
TableConfig tableConfig)
|
static StreamTableEnvironment |
getTableEnvironment(StreamExecutionEnvironment executionEnvironment,
TableConfig tableConfig)
Returns a
ScalaStreamTableEnv for a Scala stream ScalaStreamExecEnv . |
FlinkTypeFactory |
getTypeFactory()
Returns the
FlinkTypeFactory of this TableEnvironment. |
protected boolean |
isRegistered(String name)
Checks if a table is registered under the given name.
|
<T,ACC> void |
registerAggregateFunctionInternal(String name,
AggregateFunction<T,ACC> function,
TypeInformation<T> evidence$2)
Registers an
AggregateFunction under a unique name. |
void |
registerExternalCatalog(String name,
ExternalCatalog externalCatalog)
Registers an
ExternalCatalog under a unique name in the TableEnvironment's schema. |
void |
registerFunction(String name,
ScalarFunction function)
Registers a
ScalarFunction under a unique name. |
void |
registerTable(String name,
Table table)
Registers a
Table under a unique name in the TableEnvironment's catalog. |
<T> void |
registerTableFunctionInternal(String name,
TableFunction<T> function,
TypeInformation<T> evidence$1)
Registers a
TableFunction under a unique name. |
protected void |
registerTableInternal(String name,
org.apache.calcite.schema.impl.AbstractTable table)
Registers a Calcite
AbstractTable in the TableEnvironment's catalog. |
abstract void |
registerTableSource(String name,
TableSource<?> tableSource)
Registers an external
TableSource in this TableEnvironment 's catalog. |
protected FlinkRelBuilder |
relBuilder() |
protected void |
replaceRegisteredTable(String name,
org.apache.calcite.schema.impl.AbstractTable table)
Replaces a registered Table with another Table under the same name.
|
protected org.apache.calcite.rel.RelNode |
runHepPlanner(org.apache.calcite.plan.hep.HepMatchOrder hepMatchOrder,
org.apache.calcite.tools.RuleSet ruleSet,
org.apache.calcite.rel.RelNode input,
org.apache.calcite.plan.RelTraitSet targetTraits)
run HEP planner
|
protected org.apache.calcite.rel.RelNode |
runVolcanoPlanner(org.apache.calcite.tools.RuleSet ruleSet,
org.apache.calcite.rel.RelNode input,
org.apache.calcite.plan.RelTraitSet targetTraits)
run VOLCANO planner
|
Table |
scan(scala.collection.Seq<String> tablePath)
Scans a registered table and returns the resulting
Table . |
Table |
scan(String... tablePath)
Scans a registered table and returns the resulting
Table . |
Table |
sql(String query)
Evaluates a SQL query on registered tables and retrieves the result as a
Table . |
static void |
validateType(TypeInformation<?> typeInfo)
Validate if class represented by the typeInfo is static and globally accessible
|
abstract <T> void |
writeToSink(Table table,
TableSink<T> sink,
QueryConfig conf)
Writes a
Table to a TableSink . |
public TableEnvironment(TableConfig config)
public static String DEFAULT_ROWTIME_ATTRIBUTE()
public static String DEFAULT_PROCTIME_ATTRIBUTE()
public static BatchTableEnvironment getTableEnvironment(ExecutionEnvironment executionEnvironment)
JavaBatchTableEnv
for a Java JavaBatchExecEnv
.
executionEnvironment
- The Java batch ExecutionEnvironment.public static BatchTableEnvironment getTableEnvironment(ExecutionEnvironment executionEnvironment, TableConfig tableConfig)
executionEnvironment
- The Java batch ExecutionEnvironment.tableConfig
- The TableConfig for the new TableEnvironment.public static BatchTableEnvironment getTableEnvironment(ExecutionEnvironment executionEnvironment)
ScalaBatchTableEnv
for a Scala ScalaBatchExecEnv
.
executionEnvironment
- The Scala batch ExecutionEnvironment.public static BatchTableEnvironment getTableEnvironment(ExecutionEnvironment executionEnvironment, TableConfig tableConfig)
executionEnvironment
- The Scala batch ExecutionEnvironment.tableConfig
- The TableConfig for the new TableEnvironment.public static StreamTableEnvironment getTableEnvironment(StreamExecutionEnvironment executionEnvironment)
JavaStreamTableEnv
for a Java JavaStreamExecEnv
.
executionEnvironment
- The Java StreamExecutionEnvironment.public static StreamTableEnvironment getTableEnvironment(StreamExecutionEnvironment executionEnvironment, TableConfig tableConfig)
executionEnvironment
- The Java StreamExecutionEnvironment.tableConfig
- The TableConfig for the new TableEnvironment.public static StreamTableEnvironment getTableEnvironment(StreamExecutionEnvironment executionEnvironment)
ScalaStreamTableEnv
for a Scala stream ScalaStreamExecEnv
.
executionEnvironment
- The Scala StreamExecutionEnvironment.public static StreamTableEnvironment getTableEnvironment(StreamExecutionEnvironment executionEnvironment, TableConfig tableConfig)
ScalaStreamTableEnv
for a Scala stream ScalaStreamExecEnv
.
executionEnvironment
- The Scala StreamExecutionEnvironment.tableConfig
- The TableConfig for the new TableEnvironment.public static <A> String[] getFieldNames(TypeInformation<A> inputType)
TypeInformation
.
inputType
- The TypeInformation extract the field names.public static void validateType(TypeInformation<?> typeInfo)
typeInfo
- type to checkTableException
- if type does not meet these criteriapublic static int[] getFieldIndices(TypeInformation<?> inputType)
TypeInformation
.
inputType
- The TypeInformation extract the field positions from.public static TypeInformation<?>[] getFieldTypes(TypeInformation<?> inputType)
TypeInformation
.
inputType
- The TypeInformation to extract field types from.public static <A> String[] getFieldNames(TableSource<A> tableSource)
TableSource
.
tableSource
- The TableSource to extract field names from.public static <A> int[] getFieldIndices(TableSource<A> tableSource)
TableSource
.
tableSource
- The TableSource to extract field indices from.public Table scan(String... tablePath)
Table
.
A table to scan must be registered in the TableEnvironment. It can be either directly
registered as DataStream, DataSet, or Table or as member of an ExternalCatalog
.
Examples:
- Scanning a directly registered table
val tab: Table = tableEnv.scan("tableName")
- Scanning a table from a registered catalog
val tab: Table = tableEnv.scan("catalogName", "dbName", "tableName")
tablePath
- The path of the table to scan.Table
.TableException
- if no table is found using the given table path.public TableConfig config()
public FunctionCatalog functionCatalog()
protected FlinkRelBuilder relBuilder()
public AtomicInteger attrNameCntr()
public TableConfig getConfig()
protected org.apache.calcite.sql.SqlOperatorTable getSqlOperatorTable()
protected org.apache.calcite.tools.RuleSet getNormRuleSet()
protected org.apache.calcite.tools.RuleSet getLogicalOptRuleSet()
protected org.apache.calcite.tools.RuleSet getPhysicalOptRuleSet()
protected org.apache.calcite.sql.parser.SqlParser.Config getSqlParserConfig()
protected abstract org.apache.calcite.tools.RuleSet getBuiltInNormRuleSet()
protected org.apache.calcite.tools.RuleSet getBuiltInLogicalOptRuleSet()
protected abstract org.apache.calcite.tools.RuleSet getBuiltInPhysicalOptRuleSet()
protected org.apache.calcite.rel.RelNode runHepPlanner(org.apache.calcite.plan.hep.HepMatchOrder hepMatchOrder, org.apache.calcite.tools.RuleSet ruleSet, org.apache.calcite.rel.RelNode input, org.apache.calcite.plan.RelTraitSet targetTraits)
hepMatchOrder
- (undocumented)ruleSet
- (undocumented)input
- (undocumented)targetTraits
- (undocumented)protected org.apache.calcite.rel.RelNode runVolcanoPlanner(org.apache.calcite.tools.RuleSet ruleSet, org.apache.calcite.rel.RelNode input, org.apache.calcite.plan.RelTraitSet targetTraits)
ruleSet
- (undocumented)input
- (undocumented)targetTraits
- (undocumented)public void registerExternalCatalog(String name, ExternalCatalog externalCatalog)
ExternalCatalog
under a unique name in the TableEnvironment's schema.
All tables registered in the ExternalCatalog
can be accessed.
name
- The name under which the externalCatalog will be registeredexternalCatalog
- The externalCatalog to registerpublic ExternalCatalog getRegisteredExternalCatalog(String name)
ExternalCatalog
by name.
name
- The name to look up the ExternalCatalog
ExternalCatalog
public void registerFunction(String name, ScalarFunction function)
ScalarFunction
under a unique name. Replaces already existing
user-defined functions under this name.name
- (undocumented)function
- (undocumented)public <T> void registerTableFunctionInternal(String name, TableFunction<T> function, TypeInformation<T> evidence$1)
TableFunction
under a unique name. Replaces already existing
user-defined functions under this name.name
- (undocumented)function
- (undocumented)evidence$1
- (undocumented)public <T,ACC> void registerAggregateFunctionInternal(String name, AggregateFunction<T,ACC> function, TypeInformation<T> evidence$2)
AggregateFunction
under a unique name. Replaces already existing
user-defined functions under this name.name
- (undocumented)function
- (undocumented)evidence$2
- (undocumented)public void registerTable(String name, Table table)
Table
under a unique name in the TableEnvironment's catalog.
Registered tables can be referenced in SQL queries.
name
- The name under which the table will be registered.table
- The table to register.public abstract void registerTableSource(String name, TableSource<?> tableSource)
TableSource
in this TableEnvironment
's catalog.
Registered tables can be referenced in SQL queries.
name
- The name under which the TableSource
is registered.tableSource
- The TableSource
to register.protected void replaceRegisteredTable(String name, org.apache.calcite.schema.impl.AbstractTable table)
DataStreamTable
with a TranslatableTable
.
name
- Name of the table to replace.table
- The table that replaces the previous table.public Table scan(scala.collection.Seq<String> tablePath) throws TableException
Table
.
A table to scan must be registered in the TableEnvironment. It can be either directly
registered as DataStream, DataSet, or Table or as member of an ExternalCatalog
.
Examples:
- Scanning a directly registered table
val tab: Table = tableEnv.scan("tableName")
- Scanning a table from a registered catalog
val tab: Table = tableEnv.scan("catalogName", "dbName", "tableName")
tablePath
- The path of the table to scan.Table
.TableException
- if no table is found using the given table path.public Table sql(String query)
Table
.
All tables referenced by the query must be registered in the TableEnvironment. But
Table.toString
will automatically register an unique table name and return the
table name. So it allows to call SQL directly on tables like this:
val table: Table = ...
// the table is not registered to the table environment
tEnv.sql(s"SELECT * FROM $table")
query
- The SQL query to evaluate.public abstract <T> void writeToSink(Table table, TableSink<T> sink, QueryConfig conf)
Table
to a TableSink
.
protected void registerTableInternal(String name, org.apache.calcite.schema.impl.AbstractTable table) throws TableException
AbstractTable
in the TableEnvironment's catalog.
name
- The name under which the table will be registered.table
- The table to register in the catalogTableException
- if another table is registered under the provided name.protected abstract void checkValidTableName(String name)
name
- The table name to check.protected boolean isRegistered(String name)
name
- The table name to check.protected org.apache.calcite.rel.type.RelDataType getRowType(String name)
public String createUniqueAttributeName()
public FlinkRelBuilder getRelBuilder()
FlinkRelBuilder
of this TableEnvironment.public org.apache.calcite.plan.RelOptPlanner getPlanner()
RelOptPlanner
of this TableEnvironment.public FlinkTypeFactory getTypeFactory()
FlinkTypeFactory
of this TableEnvironment.public FunctionCatalog getFunctionCatalog()
public org.apache.calcite.tools.FrameworkConfig getFrameworkConfig()
FrameworkConfig
of this TableEnvironment.protected <A> scala.Tuple2<String[],int[]> getFieldInfo(TypeInformation<A> inputType)
TypeInformation
.
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
. It does not handle time attributes but considers them in indices.
inputType
- The TypeInformation
against which the Expression
s are evaluated.exprs
- The expressions that define the field names.protected <OUT> GeneratedFunction<MapFunction<Row,OUT>,OUT> generateRowConverterFunction(TypeInformation<Row> inputTypeInfo, RowSchema schema, TypeInformation<OUT> requestedTypeInfo, String functionName)
Copyright © 2014–2018 The Apache Software Foundation. All rights reserved.