@PublicEvolving public interface Table
Table
.
Use the methods of Table
to transform data. Use TableEnvironment
to convert a
Table
back to a DataSet
or DataStream
.
When using Scala a Table
can also be converted using implicit conversions.
Java Example:
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
BatchTableEnvironment tEnv = BatchTableEnvironment.create(env);
DataSet<Tuple2<String, Integer>> set = ...
tEnv.registerTable("MyTable", set, "a, b");
Table table = tEnv.scan("MyTable").select(...);
...
Table table2 = ...
DataSet<MyType> set2 = tEnv.toDataSet(table2, MyType.class);
Scala Example:
val env = ExecutionEnvironment.getExecutionEnvironment
val tEnv = BatchTableEnvironment.create(env)
val set: DataSet[(String, Int)] = ...
val table = set.toTable(tEnv, 'a, 'b)
...
val table2 = ...
val set2: DataSet[MyType] = table2.toDataSet[MyType]
Operations such as join
, select
, where
and groupBy
either take
arguments in a Scala DSL or as an expression String. Please refer to the documentation for the
expression syntax.
Modifier and Type | Method and Description |
---|---|
Table |
addColumns(Expression... fields)
Adds additional columns.
|
Table |
addColumns(String fields)
Deprecated.
|
Table |
addOrReplaceColumns(Expression... fields)
Adds additional columns.
|
Table |
addOrReplaceColumns(String fields)
Deprecated.
|
AggregatedTable |
aggregate(Expression aggregateFunction)
Performs a global aggregate operation with an aggregate function.
|
AggregatedTable |
aggregate(String aggregateFunction)
Deprecated.
|
Table |
as(Expression... fields)
Deprecated.
|
Table |
as(String field,
String... fields)
Renames the fields of the expression result.
|
TemporalTableFunction |
createTemporalTableFunction(Expression timeAttribute,
Expression primaryKey)
Creates
TemporalTableFunction backed up by this table as a history table. |
TemporalTableFunction |
createTemporalTableFunction(String timeAttribute,
String primaryKey)
Deprecated.
|
Table |
distinct()
Removes duplicate values and returns only distinct (different) values.
|
Table |
dropColumns(Expression... fields)
Drops existing columns.
|
Table |
dropColumns(String fields)
Deprecated.
|
TableResult |
execute()
Collects the contents of the current table local client.
|
TableResult |
executeInsert(String tablePath)
|
TableResult |
executeInsert(String tablePath,
boolean overwrite)
|
String |
explain(ExplainDetail... extraDetails)
Returns the AST of this table and the execution plan to compute the result of this table.
|
Table |
fetch(int fetch)
Limits a sorted result to the first n rows.
|
Table |
filter(Expression predicate)
Filters out elements that don't pass the filter predicate.
|
Table |
filter(String predicate)
Deprecated.
|
FlatAggregateTable |
flatAggregate(Expression tableAggregateFunction)
Perform a global flatAggregate without groupBy.
|
FlatAggregateTable |
flatAggregate(String tableAggregateFunction)
Deprecated.
|
Table |
flatMap(Expression tableFunction)
Performs a flatMap operation with an user-defined table function or built-in table function.
|
Table |
flatMap(String tableFunction)
Deprecated.
|
Table |
fullOuterJoin(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
fullOuterJoin(Table right,
String joinPredicate)
Deprecated.
|
QueryOperation |
getQueryOperation()
Returns underlying logical representation of this table.
|
TableSchema |
getSchema()
Returns the schema of this table.
|
GroupedTable |
groupBy(Expression... fields)
Groups the elements on some grouping keys.
|
GroupedTable |
groupBy(String fields)
Deprecated.
|
void |
insertInto(String tablePath)
Deprecated.
use
executeInsert(String) for single sink, use TableEnvironment.createStatementSet() for multiple sinks. |
Table |
intersect(Table right)
Intersects two
Table s with duplicate records removed. |
Table |
intersectAll(Table right)
Intersects two
Table s. |
Table |
join(Table right)
Joins two
Table s. |
Table |
join(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
join(Table right,
String joinPredicate)
Deprecated.
|
Table |
joinLateral(Expression tableFunctionCall)
Joins this
Table with an user-defined TableFunction . |
Table |
joinLateral(Expression tableFunctionCall,
Expression joinPredicate)
Joins this
Table with an user-defined TableFunction . |
Table |
joinLateral(String tableFunctionCall)
Deprecated.
|
Table |
joinLateral(String tableFunctionCall,
String joinPredicate)
Deprecated.
|
Table |
leftOuterJoin(Table right)
Joins two
Table s. |
Table |
leftOuterJoin(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
leftOuterJoin(Table right,
String joinPredicate)
Deprecated.
|
Table |
leftOuterJoinLateral(Expression tableFunctionCall)
Joins this
Table with an user-defined TableFunction . |
Table |
leftOuterJoinLateral(Expression tableFunctionCall,
Expression joinPredicate)
Joins this
Table with an user-defined TableFunction . |
Table |
leftOuterJoinLateral(String tableFunctionCall)
Deprecated.
|
Table |
leftOuterJoinLateral(String tableFunctionCall,
String joinPredicate)
Deprecated.
|
Table |
map(Expression mapFunction)
Performs a map operation with an user-defined scalar function or built-in scalar function.
|
Table |
map(String mapFunction)
Deprecated.
use
map(Expression) |
Table |
minus(Table right)
Minus of two
Table s with duplicate records removed. |
Table |
minusAll(Table right)
Minus of two
Table s. |
Table |
offset(int offset)
Limits a sorted result from an offset position.
|
Table |
orderBy(Expression... fields)
Sorts the given
Table . |
Table |
orderBy(String fields)
Deprecated.
|
void |
printSchema()
Prints the schema of this table to the console in a tree format.
|
Table |
renameColumns(Expression... fields)
Renames existing columns.
|
Table |
renameColumns(String fields)
Deprecated.
|
Table |
rightOuterJoin(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
rightOuterJoin(Table right,
String joinPredicate)
Deprecated.
|
Table |
select(Expression... fields)
Performs a selection operation.
|
Table |
select(String fields)
Deprecated.
|
Table |
union(Table right)
Unions two
Table s with duplicate records removed. |
Table |
unionAll(Table right)
Unions two
Table s. |
Table |
where(Expression predicate)
Filters out elements that don't pass the filter predicate.
|
Table |
where(String predicate)
Deprecated.
|
GroupWindowedTable |
window(GroupWindow groupWindow)
Groups the records of a table by assigning them to windows defined by a time or row interval.
|
OverWindowedTable |
window(OverWindow... overWindows)
Defines over-windows on the records of a table.
|
TableSchema getSchema()
void printSchema()
QueryOperation getQueryOperation()
@Deprecated Table select(String fields)
select(Expression...)
Example:
tab.select("key, value.avg + ' The average' as average")
Table select(Expression... fields)
Scala Example:
tab.select($("key"), $("value").avg().plus(" The average").as("average"));
Scala Example:
tab.select($"key", $"value".avg + " The average" as "average")
@Deprecated TemporalTableFunction createTemporalTableFunction(String timeAttribute, String primaryKey)
createTemporalTableFunction(Expression, Expression)
TemporalTableFunction
backed up by this table as a history table. Temporal
Tables represent a concept of a table that changes over time and for which Flink keeps track
of those changes. TemporalTableFunction
provides a way how to access those data.
For more information please check Flink's documentation on Temporal Tables.
Currently TemporalTableFunction
s are only supported in streaming.
timeAttribute
- Must points to a time attribute. Provides a way to compare which records
are a newer or older version.primaryKey
- Defines the primary key. With primary key it is possible to update a row or
to delete it.TemporalTableFunction
which is an instance of TableFunction
. It takes
one single argument, the timeAttribute
, for which it returns matching version of
the Table
, from which TemporalTableFunction
was created.TemporalTableFunction createTemporalTableFunction(Expression timeAttribute, Expression primaryKey)
TemporalTableFunction
backed up by this table as a history table. Temporal
Tables represent a concept of a table that changes over time and for which Flink keeps track
of those changes. TemporalTableFunction
provides a way how to access those data.
For more information please check Flink's documentation on Temporal Tables.
Currently TemporalTableFunction
s are only supported in streaming.
timeAttribute
- Must points to a time indicator. Provides a way to compare which records
are a newer or older version.primaryKey
- Defines the primary key. With primary key it is possible to update a row or
to delete it.TemporalTableFunction
which is an instance of TableFunction
. It takes
one single argument, the timeAttribute
, for which it returns matching version of
the Table
, from which TemporalTableFunction
was created.Table as(String field, String... fields)
Example:
tab.as("a", "b")
@Deprecated Table as(Expression... fields)
as(String, String...)
Example:
tab.as($("a"), $("b"))
Scala Example:
tab.as($"a", $"b")
@Deprecated Table filter(String predicate)
filter(Expression)
Example:
tab.filter("name = 'Fred'")
Table filter(Expression predicate)
Example:
tab.filter($("name").isEqual("Fred"));
Scala Example:
tab.filter($"name" === "Fred")
@Deprecated Table where(String predicate)
where(Expression)
Example:
tab.where("name = 'Fred'")
Table where(Expression predicate)
Example:
tab.where($("name").isEqual("Fred"));
Scala Example:
tab.where($"name" === "Fred")
@Deprecated GroupedTable groupBy(String fields)
groupBy(Expression...)
Example:
tab.groupBy("key").select("key, value.avg")
GroupedTable groupBy(Expression... fields)
Scala Example:
tab.groupBy($("key")).select($("key"), $("value").avg());
Scala Example:
tab.groupBy($"key").select($"key", $"value".avg)
Table distinct()
Example:
tab.select($("key"), $("value")).distinct();
Table join(Table right)
Table
s. Similar to a SQL join. The fields of the two joined operations must
not overlap, use as
to rename fields if necessary. You can use where and select
clauses after a join to further specify the behaviour of the join.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.join(right)
.where($("a").isEqual($("b")).and($("c").isGreater(3))
.select($("a"), $("b"), $("d"));
@Deprecated Table join(Table right, String joinPredicate)
join(Table, Expression)
Table
s. Similar to a SQL join. The fields of the two joined operations must
not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.join(right, "a = b")
Table join(Table right, Expression joinPredicate)
Table
s. Similar to a SQL join. The fields of the two joined operations must
not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.join(right, $("a").isEqual($("b")))
.select($("a"), $("b"), $("d"));
Scala Example:
left.join(right, $"a" === $"b")
.select($"a", $"b", $"d")
Table leftOuterJoin(Table right)
Table
s. Similar to a SQL left outer join. The fields of the two joined
operations must not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
and its TableConfig
must have null check enabled (default).
Example:
left.leftOuterJoin(right)
.select($("a"), $("b"), $("d"));
@Deprecated Table leftOuterJoin(Table right, String joinPredicate)
leftOuterJoin(Table, Expression)
Table
s. Similar to a SQL left outer join. The fields of the two joined
operations must not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
and its TableConfig
must have null check enabled (default).
Example:
left.leftOuterJoin(right, "a = b").select("a, b, d")
Table leftOuterJoin(Table right, Expression joinPredicate)
Table
s. Similar to a SQL left outer join. The fields of the two joined
operations must not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
and its TableConfig
must have null check enabled (default).
Example:
left.leftOuterJoin(right, $("a").isEqual($("b")))
.select($("a"), $("b"), $("d"));
Scala Example:
left.leftOuterJoin(right, $"a" === $"b")
.select($"a", $"b", $"d")
@Deprecated Table rightOuterJoin(Table right, String joinPredicate)
rightOuterJoin(Table, Expression)
Table
s. Similar to a SQL right outer join. The fields of the two joined
operations must not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
and its TableConfig
must have null check enabled (default).
Example:
left.rightOuterJoin(right, "a = b").select("a, b, d")
Table rightOuterJoin(Table right, Expression joinPredicate)
Table
s. Similar to a SQL right outer join. The fields of the two joined
operations must not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
and its TableConfig
must have null check enabled (default).
Example:
left.rightOuterJoin(right, $("a").isEqual($("b")))
.select($("a"), $("b"), $("d"));
Scala Example:
left.rightOuterJoin(right, $"a" === $"b")
.select($"a", $"b", $"d")
@Deprecated Table fullOuterJoin(Table right, String joinPredicate)
fullOuterJoin(Table, Expression)
Table
s. Similar to a SQL full outer join. The fields of the two joined
operations must not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
and its TableConfig
must have null check enabled (default).
Example:
left.fullOuterJoin(right, "a = b").select("a, b, d")
Table fullOuterJoin(Table right, Expression joinPredicate)
Table
s. Similar to a SQL full outer join. The fields of the two joined
operations must not overlap, use as
to rename fields if necessary.
Note: Both tables must be bound to the same TableEnvironment
and its TableConfig
must have null check enabled (default).
Example:
left.fullOuterJoin(right, $("a").isEqual($("b")))
.select($("a"), $("b"), $("d"));
Scala Example:
left.fullOuterJoin(right, $"a" === $"b")
.select($"a", $"b", $"d")
@Deprecated Table joinLateral(String tableFunctionCall)
joinLateral(Expression)
Table
with an user-defined TableFunction
. This join is similar to
a SQL inner join with ON TRUE predicate but works with a table function. Each row of the
table is joined with all rows produced by the table function.
Example:
class MySplitUDTF extends TableFunction<String> {
public void eval(String str) {
str.split("#").forEach(this::collect);
}
}
TableFunction<String> split = new MySplitUDTF();
tableEnv.registerFunction("split", split);
table.joinLateral("split(c) as (s)").select("a, b, c, s");
Table joinLateral(Expression tableFunctionCall)
Table
with an user-defined TableFunction
. This join is similar to
a SQL inner join with ON TRUE predicate but works with a table function. Each row of the
table is joined with all rows produced by the table function.
Example:
class MySplitUDTF extends TableFunction<String> {
public void eval(String str) {
str.split("#").forEach(this::collect);
}
}
table.joinLateral(call(MySplitUDTF.class, $("c")).as("s"))
.select($("a"), $("b"), $("c"), $("s"));
Scala Example:
class MySplitUDTF extends TableFunction[String] {
def eval(str: String): Unit = {
str.split("#").foreach(collect)
}
}
val split = new MySplitUDTF()
table.joinLateral(split($"c") as "s")
.select($"a", $"b", $"c", $"s")
@Deprecated Table joinLateral(String tableFunctionCall, String joinPredicate)
joinLateral(Expression, Expression)
Table
with an user-defined TableFunction
. This join is similar to
a SQL inner join but works with a table function. Each row of the table is joined with all
rows produced by the table function.
Example:
class MySplitUDTF extends TableFunction<String> {
public void eval(String str) {
str.split("#").forEach(this::collect);
}
}
TableFunction<String> split = new MySplitUDTF();
tableEnv.registerFunction("split", split);
table.joinLateral("split(c) as (s)", "a = s").select("a, b, c, s");
Table joinLateral(Expression tableFunctionCall, Expression joinPredicate)
Table
with an user-defined TableFunction
. This join is similar to
a SQL inner join but works with a table function. Each row of the table is joined with all
rows produced by the table function.
Example:
class MySplitUDTF extends TableFunction<String> {
public void eval(String str) {
str.split("#").forEach(this::collect);
}
}
table.joinLateral(call(MySplitUDTF.class, $("c")).as("s"), $("a").isEqual($("s")))
.select($("a"), $("b"), $("c"), $("s"));
Scala Example:
class MySplitUDTF extends TableFunction[String] {
def eval(str: String): Unit = {
str.split("#").foreach(collect)
}
}
val split = new MySplitUDTF()
table.joinLateral(split($"c") as "s", $"a" === $"s")
.select($"a", $"b", $"c", $"s")
@Deprecated Table leftOuterJoinLateral(String tableFunctionCall)
leftOuterJoinLateral(Expression)
Table
with an user-defined TableFunction
. This join is similar to
a SQL left outer join with ON TRUE predicate but works with a table function. Each row of the
table is joined with all rows produced by the table function. If the table function does not
produce any row, the outer row is padded with nulls.
Example:
class MySplitUDTF extends TableFunction<String> {
public void eval(String str) {
str.split("#").forEach(this::collect);
}
}
TableFunction<String> split = new MySplitUDTF();
tableEnv.registerFunction("split", split);
table.leftOuterJoinLateral("split(c) as (s)").select("a, b, c, s");
Table leftOuterJoinLateral(Expression tableFunctionCall)
Table
with an user-defined TableFunction
. This join is similar to
a SQL left outer join with ON TRUE predicate but works with a table function. Each row of the
table is joined with all rows produced by the table function. If the table function does not
produce any row, the outer row is padded with nulls.
Example:
class MySplitUDTF extends TableFunction<String> {
public void eval(String str) {
str.split("#").forEach(this::collect);
}
}
table.leftOuterJoinLateral(call(MySplitUDTF.class, $("c")).as("s"))
.select($("a"), $("b"), $("c"), $("s"));
Scala Example:
class MySplitUDTF extends TableFunction[String] {
def eval(str: String): Unit = {
str.split("#").foreach(collect)
}
}
val split = new MySplitUDTF()
table.leftOuterJoinLateral(split($"c") as "s")
.select($"a", $"b", $"c", $"s")
@Deprecated Table leftOuterJoinLateral(String tableFunctionCall, String joinPredicate)
leftOuterJoinLateral(Expression, Expression)
Table
with an user-defined TableFunction
. This join is similar to
a SQL left outer join with ON TRUE predicate but works with a table function. Each row of the
table is joined with all rows produced by the table function. If the table function does not
produce any row, the outer row is padded with nulls.
Example:
class MySplitUDTF extends TableFunction<String> {
public void eval(String str) {
str.split("#").forEach(this::collect);
}
}
TableFunction<String> split = new MySplitUDTF();
tableEnv.registerFunction("split", split);
table.leftOuterJoinLateral("split(c) as (s)", "a = s").select("a, b, c, s");
Table leftOuterJoinLateral(Expression tableFunctionCall, Expression joinPredicate)
Table
with an user-defined TableFunction
. This join is similar to
a SQL left outer join with ON TRUE predicate but works with a table function. Each row of the
table is joined with all rows produced by the table function. If the table function does not
produce any row, the outer row is padded with nulls.
Example:
class MySplitUDTF extends TableFunction<String> {
public void eval(String str) {
str.split("#").forEach(this::collect);
}
}
table.leftOuterJoinLateral(call(MySplitUDTF.class, $("c")).as("s"), $("a").isEqual($("s")))
.select($("a"), $("b"), $("c"), $("s"));
Scala Example:
class MySplitUDTF extends TableFunction[String] {
def eval(str: String): Unit = {
str.split("#").foreach(collect)
}
}
val split = new MySplitUDTF()
table.leftOuterJoinLateral(split($"c") as "s", $"a" === $"s")
.select($"a", $"b", $"c", $"s")
Table minus(Table right)
Table
s with duplicate records removed. Similar to a SQL EXCEPT clause.
Minus returns records from the left table that do not exist in the right table. Duplicate
records in the left table are returned exactly once, i.e., duplicates are removed. Both
tables must have identical field types.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.minus(right);
Table minusAll(Table right)
Table
s. Similar to a SQL EXCEPT ALL. Similar to a SQL EXCEPT ALL clause.
MinusAll returns the records that do not exist in the right table. A record that is present n
times in the left table and m times in the right table is returned (n - m) times, i.e., as
many duplicates as are present in the right table are removed. Both tables must have
identical field types.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.minusAll(right);
Table union(Table right)
Table
s with duplicate records removed. Similar to a SQL UNION. The fields
of the two union operations must fully overlap.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.union(right);
Table unionAll(Table right)
Table
s. Similar to a SQL UNION ALL. The fields of the two union operations
must fully overlap.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.unionAll(right);
Table intersect(Table right)
Table
s with duplicate records removed. Intersect returns records that
exist in both tables. If a record is present in one or both tables more than once, it is
returned just once, i.e., the resulting table has no duplicate records. Similar to a SQL
INTERSECT. The fields of the two intersect operations must fully overlap.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.intersect(right);
Table intersectAll(Table right)
Table
s. IntersectAll returns records that exist in both tables. If a
record is present in both tables more than once, it is returned as many times as it is
present in both tables, i.e., the resulting table might have duplicate records. Similar to an
SQL INTERSECT ALL. The fields of the two intersect operations must fully overlap.
Note: Both tables must be bound to the same TableEnvironment
.
Example:
left.intersectAll(right);
@Deprecated Table orderBy(String fields)
orderBy(Expression...)
Table
. Similar to SQL ORDER BY. The resulting Table is sorted
globally sorted across all parallel partitions.
Example:
tab.orderBy("name.desc")
Table orderBy(Expression... fields)
Table
. Similar to SQL ORDER BY. The resulting Table is globally
sorted across all parallel partitions.
Scala Example:
tab.orderBy($("name").desc());
Scala Example:
tab.orderBy($"name".desc)
Table offset(int offset)
offset(int offset)
can be combined with a subsequent fetch(int
fetch)
call to return n rows after skipping the first o rows.
// skips the first 3 rows and returns all following rows.
tab.orderBy($("name").desc()).offset(3);
// skips the first 10 rows and returns the next 5 rows.
tab.orderBy($("name").desc()).offset(10).fetch(5);
offset
- number of records to skipTable fetch(int fetch)
fetch(int fetch)
can be combined with a preceding offset(int
offset)
call to return n rows after skipping the first o rows.
// returns the first 3 records.
tab.orderBy($("name").desc()).fetch(3);
// skips the first 10 rows and returns the next 5 rows.
tab.orderBy($("name").desc()).offset(10).fetch(5);
fetch
- the number of records to return. Fetch must be >= 0.@Deprecated void insertInto(String tablePath)
executeInsert(String)
for single sink, use TableEnvironment.createStatementSet()
for multiple sinks.Table
to a TableSink
that was registered under the specified path.
For the path resolution algorithm see TableEnvironment.useDatabase(String)
.
A batch Table
can only be written to a org.apache.flink.table.sinks.BatchTableSink
, a streaming Table
requires a org.apache.flink.table.sinks.AppendStreamTableSink
, a org.apache.flink.table.sinks.RetractStreamTableSink
, or an org.apache.flink.table.sinks.UpsertStreamTableSink
.
GroupWindowedTable window(GroupWindow groupWindow)
For streaming tables of infinite size, grouping into windows is required to define finite groups on which group-based aggregates can be computed.
For batch tables of finite size, windowing essentially provides shortcuts for time-based groupBy.
Note: Computing windowed aggregates on a streaming table is only a parallel
operation if additional grouping attributes are added to the groupBy(...)
clause. If
the groupBy(...)
only references a GroupWindow alias, the streamed table will be
processed by a single task, i.e., with parallelism 1.
groupWindow
- groupWindow that specifies how elements are grouped.OverWindowedTable window(OverWindow... overWindows)
An over-window defines for each record an interval of records over which aggregation functions can be computed.
Example:
table
.window(Over.partitionBy($("c")).orderBy($("rowTime")).preceding(lit(10).seconds()).as("ow")
.select($("c"), $("b").count().over($("ow")), $("e").sum().over($("ow")));
Scala Example:
table
.window(Over partitionBy $"c" orderBy $"rowTime" preceding 10.seconds as "ow")
.select($"c", $"b".count over $"ow", $"e".sum over $"ow")
Note: Computing over window aggregates on a streaming table is only a parallel operation if the window is partitioned. Otherwise, the whole stream will be processed by a single task, i.e., with parallelism 1.
Note: Over-windows for batch tables are currently not supported.
overWindows
- windows that specify the record interval over which aggregations are
computed.@Deprecated Table addColumns(String fields)
addColumns(Expression...)
Example:
tab.addColumns("a + 1 as a1, concat(b, 'sunny') as b1")
Table addColumns(Expression... fields)
Example:
tab.addColumns(
$("a").plus(1).as("a1"),
concat($("b"), "sunny").as("b1")
);
Scala Example:
tab.addColumns(
$"a" + 1 as "a1",
concat($"b", "sunny") as "b1"
)
@Deprecated Table addOrReplaceColumns(String fields)
addOrReplaceColumns(Expression...)
Example:
tab.addOrReplaceColumns("a + 1 as a1, concat(b, 'sunny') as b1")
Table addOrReplaceColumns(Expression... fields)
Example:
tab.addOrReplaceColumns(
$("a").plus(1).as("a1"),
concat($("b"), "sunny").as("b1")
);
Scala Example:
tab.addOrReplaceColumns(
$"a" + 1 as "a1",
concat($"b", "sunny") as "b1"
)
@Deprecated Table renameColumns(String fields)
renameColumns(Expression...)
Example:
tab.renameColumns("a as a1, b as b1")
Table renameColumns(Expression... fields)
Example:
tab.renameColumns(
$("a").as("a1"),
$("b").as("b1")
);
Scala Example:
tab.renameColumns(
$"a" as "a1",
$"b" as "b1"
)
@Deprecated Table dropColumns(String fields)
dropColumns(Expression...)
Example:
tab.dropColumns("a, b")
Table dropColumns(Expression... fields)
Example:
tab.dropColumns($("a"), $("b"));
Scala Example:
tab.dropColumns($"a", $"b")
@Deprecated Table map(String mapFunction)
map(Expression)
Example:
ScalarFunction func = new MyMapFunction();
tableEnv.registerFunction("func", func);
tab.map("func(c)");
Table map(Expression mapFunction)
Example:
tab.map(call(MyMapFunction.class, $("c")))
Scala Example:
val func = new MyMapFunction()
tab.map(func($"c"))
@Deprecated Table flatMap(String tableFunction)
flatMap(Expression)
Example:
TableFunction func = new MyFlatMapFunction();
tableEnv.registerFunction("func", func);
table.flatMap("func(c)");
Table flatMap(Expression tableFunction)
Example:
tab.flatMap(call(MyFlatMapFunction.class, $("c")))
Scala Example:
val func = new MyFlatMapFunction()
tab.flatMap(func($"c"))
@Deprecated AggregatedTable aggregate(String aggregateFunction)
aggregate(Expression)
aggregate(String)
with a select statement. The output will be flattened if the
output type is a composite type.
Example:
AggregateFunction aggFunc = new MyAggregateFunction()
tableEnv.registerFunction("aggFunc", aggFunc);
table.aggregate("aggFunc(a, b) as (f0, f1, f2)")
.select("f0, f1")
AggregatedTable aggregate(Expression aggregateFunction)
aggregate(Expression)
with a select statement. The output will be flattened if the
output type is a composite type.
Example:
tab.aggregate(call(MyAggregateFunction.class, $("a"), $("b")).as("f0", "f1", "f2"))
.select($("f0"), $("f1"));
Scala Example:
val aggFunc = new MyAggregateFunction
table.aggregate(aggFunc($"a", $"b") as ("f0", "f1", "f2"))
.select($"f0", $"f1")
@Deprecated FlatAggregateTable flatAggregate(String tableAggregateFunction)
flatAggregate(Expression)
Example:
TableAggregateFunction tableAggFunc = new MyTableAggregateFunction();
tableEnv.registerFunction("tableAggFunc", tableAggFunc);
tab.flatAggregate("tableAggFunc(a, b) as (x, y, z)")
.select("x, y, z")
FlatAggregateTable flatAggregate(Expression tableAggregateFunction)
Example:
tab.flatAggregate(call(MyTableAggregateFunction.class, $("a"), $("b")).as("x", "y", "z"))
.select($("x"), $("y"), $("z"));
Scala Example:
val tableAggFunc: TableAggregateFunction = new MyTableAggregateFunction
tab.flatAggregate(tableAggFunc($"a", $"b") as ("x", "y", "z"))
.select($"x", $"y", $"z")
TableResult executeInsert(String tablePath)
Table
to a TableSink
that was registered under the specified path,
and then execute the insert operation.
See the documentation of TableEnvironment.useDatabase(String)
or TableEnvironment.useCatalog(String)
for the rules on the path resolution.
A batch Table
can only be written to a org.apache.flink.table.sinks.BatchTableSink
, a streaming Table
requires a org.apache.flink.table.sinks.AppendStreamTableSink
, a org.apache.flink.table.sinks.RetractStreamTableSink
, or an org.apache.flink.table.sinks.UpsertStreamTableSink
.
Example:
Table table = tableEnv.fromQuery("select * from MyTable");
TableResult tableResult = table.executeInsert("MySink");
tableResult...
tablePath
- The path of the registered TableSink to which the Table is written.TableResult executeInsert(String tablePath, boolean overwrite)
Table
to a TableSink
that was registered under the specified path,
and then execute the insert operation.
See the documentation of TableEnvironment.useDatabase(String)
or TableEnvironment.useCatalog(String)
for the rules on the path resolution.
A batch Table
can only be written to a org.apache.flink.table.sinks.BatchTableSink
, a streaming Table
requires a org.apache.flink.table.sinks.AppendStreamTableSink
, a org.apache.flink.table.sinks.RetractStreamTableSink
, or an org.apache.flink.table.sinks.UpsertStreamTableSink
.
Example:
Table table = tableEnv.fromQuery("select * from MyTable");
TableResult tableResult = table.executeInsert("MySink", true);
tableResult...
tablePath
- The path of the registered TableSink to which the Table is written.overwrite
- The flag that indicates whether the insert should overwrite existing data or
not.TableResult execute()
Table table = tableEnv.fromQuery("select * from MyTable");
TableResult tableResult = table.execute();
tableResult...
String explain(ExplainDetail... extraDetails)
extraDetails
- The extra explain details which the explain result should include, e.g.
estimated cost, changelog mode for streamingCopyright © 2014–2021 The Apache Software Foundation. All rights reserved.