public class Table extends Object
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.
Example:
val env = ExecutionEnvironment.getExecutionEnvironment
val tEnv = TableEnvironment.getTableEnvironment(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.
Constructor and Description |
---|
Table(TableEnvironment tableEnv,
LogicalNode logicalPlan) |
Modifier and Type | Method and Description |
---|---|
Table |
as(scala.collection.Seq<Expression> fields)
Renames the fields of the expression result.
|
Table |
as(String fields)
Renames the fields of the expression result.
|
Table |
distinct()
Removes duplicate values and returns only distinct (different) values.
|
Table |
filter(Expression predicate)
Filters out elements that don't pass the filter predicate.
|
Table |
filter(String predicate)
Filters out elements that don't pass the filter predicate.
|
Table |
fullOuterJoin(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
fullOuterJoin(Table right,
String joinPredicate)
Joins two
Table s. |
org.apache.calcite.rel.RelNode |
getRelNode() |
GroupedTable |
groupBy(scala.collection.Seq<Expression> fields)
Groups the elements on some grouping keys.
|
GroupedTable |
groupBy(String fields)
Groups the elements on some grouping keys.
|
Table |
intersect(Table right)
Intersects two
Table s with duplicate records removed. |
Table |
intersectAll(Table right)
Intersects two
Table s. |
Table |
join(Expression udtf)
Joins this
Table to a user-defined TableFunction . |
Table |
join(String udtf)
Joins this
Table to a user-defined TableFunction . |
Table |
join(Table right)
Joins two
Table s. |
Table |
join(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
join(Table right,
String joinPredicate)
Joins two
Table s. |
Table |
leftOuterJoin(Expression udtf)
Joins this
Table to a user-defined TableFunction . |
Table |
leftOuterJoin(String udtf)
Joins this
Table to a user-defined TableFunction . |
Table |
leftOuterJoin(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
leftOuterJoin(Table right,
String joinPredicate)
Joins two
Table s. |
Table |
limit(int offset)
Limits a sorted result from an offset position.
|
Table |
limit(int offset,
int fetch)
Limits a sorted result to a specified number of records from an offset position.
|
LogicalNode |
logicalPlan() |
Table |
minus(Table right)
Minus of two
Table s with duplicate records removed. |
Table |
minusAll(Table right)
Minus of two
Table s. |
Table |
orderBy(scala.collection.Seq<Expression> fields)
Sorts the given
Table . |
Table |
orderBy(String fields)
Sorts the given
Table . |
FlinkRelBuilder |
relBuilder() |
Table |
rightOuterJoin(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
rightOuterJoin(Table right,
String joinPredicate)
Joins two
Table s. |
Table |
select(scala.collection.Seq<Expression> fields)
Performs a selection operation.
|
Table |
select(String fields)
Performs a selection operation.
|
TableEnvironment |
tableEnv() |
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)
Filters out elements that don't pass the filter predicate.
|
WindowedTable |
window(Window window)
Groups the records of a table by assigning them to windows defined by a time or row interval.
|
<T> void |
writeToSink(TableSink<T> sink)
Writes the
Table to a TableSink . |
public Table(TableEnvironment tableEnv, LogicalNode logicalPlan)
public TableEnvironment tableEnv()
public LogicalNode logicalPlan()
public FlinkRelBuilder relBuilder()
public org.apache.calcite.rel.RelNode getRelNode()
public Table select(scala.collection.Seq<Expression> fields)
Example:
tab.select('key, 'value.avg + " The average" as 'average)
public Table select(String fields)
Example:
tab.select("key, value.avg + ' The average' as average")
public Table as(scala.collection.Seq<Expression> fields)
Example:
tab.as('a, 'b)
public Table as(String fields)
Example:
tab.as("a, b")
public Table filter(Expression predicate)
Example:
tab.filter('name === "Fred")
public Table filter(String predicate)
Example:
tab.filter("name = 'Fred'")
public Table where(Expression predicate)
Example:
tab.where('name === "Fred")
public Table where(String predicate)
Example:
tab.where("name = 'Fred'")
public GroupedTable groupBy(scala.collection.Seq<Expression> fields)
Example:
tab.groupBy('key).select('key, 'value.avg)
public GroupedTable groupBy(String fields)
Example:
tab.groupBy("key").select("key, value.avg")
public Table distinct()
Example:
tab.select("key, value").distinct()
public Table join(Table right)
Table
s. Similar to an 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 === 'b && 'c > 3).select('a, 'b, 'd)
public Table join(Table right, String joinPredicate)
Table
s. Similar to an 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")
public Table join(Table right, Expression joinPredicate)
Table
s. Similar to an 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).select('a, 'b, 'd)
public Table leftOuterJoin(Table right, String joinPredicate)
Table
s. Similar to an 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 nullCheck enabled.
Example:
left.leftOuterJoin(right, "a = b").select('a, 'b, 'd)
public Table leftOuterJoin(Table right, Expression joinPredicate)
Table
s. Similar to an 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 nullCheck enabled.
Example:
left.leftOuterJoin(right, 'a === 'b).select('a, 'b, 'd)
public Table rightOuterJoin(Table right, String joinPredicate)
Table
s. Similar to an 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 nullCheck enabled.
Example:
left.rightOuterJoin(right, "a = b").select('a, 'b, 'd)
public Table rightOuterJoin(Table right, Expression joinPredicate)
Table
s. Similar to an 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 nullCheck enabled.
Example:
left.rightOuterJoin(right, 'a === 'b).select('a, 'b, 'd)
public Table fullOuterJoin(Table right, String joinPredicate)
Table
s. Similar to an 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 nullCheck enabled.
Example:
left.fullOuterJoin(right, "a = b").select('a, 'b, 'd)
public Table fullOuterJoin(Table right, Expression joinPredicate)
Table
s. Similar to an 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 nullCheck enabled.
Example:
left.fullOuterJoin(right, 'a === 'b).select('a, 'b, 'd)
public 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)
public Table minusAll(Table right)
Table
s. Similar to an 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)
public Table union(Table right)
Table
s with duplicate records removed.
Similar to an 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)
public Table unionAll(Table right)
Table
s. Similar to an 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)
public 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 an
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)
public 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)
public Table orderBy(scala.collection.Seq<Expression> fields)
Table
. Similar to SQL ORDER BY.
The resulting Table is globally sorted across all parallel partitions.
Example:
tab.orderBy('name.desc)
public Table orderBy(String fields)
Table
. Similar to SQL ORDER BY.
The resulting Table is sorted globally sorted across all parallel partitions.
Example:
tab.orderBy("name.desc")
public Table limit(int offset)
Example:
// returns unlimited number of records beginning with the 4th record
tab.orderBy('name.desc).limit(3)
offset
- number of records to skippublic Table limit(int offset, int fetch)
Example:
// returns 5 records beginning with the 4th record
tab.orderBy('name.desc).limit(3, 5)
offset
- number of records to skipfetch
- number of records to be returnedpublic Table join(Expression udtf)
Table
to a user-defined TableFunction
. Similar
to an SQL cross join, but it works with a table function. It returns rows from the outer
table (table on the left of the operator) that produces matching values from the table
function (which is defined in the expression on the right side of the operator).
Example:
class MySplitUDTF extends TableFunction[String] {
def eval(str: String): Unit = {
str.split("#").foreach(collect)
}
}
val split = new MySplitUDTF()
table.join(split('c) as ('s)).select('a,'b,'c,'s)
public Table join(String udtf)
Table
to a user-defined TableFunction
. Similar
to an SQL cross join, but it works with a table function. It returns rows from the outer
table (table on the left of the operator) that produces matching values from the table
function (which is defined in the expression on the right side of the operator).
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.join("split(c) as (s)").select("a, b, c, s");
public Table leftOuterJoin(Expression udtf)
Table
to a user-defined TableFunction
. Similar
to an SQL left outer join with ON TRUE, but it works with a table function. It returns all
the rows from the outer table (table on the left of the operator), and rows that do not match
the condition from the table function (which is defined in the expression on the right
side of the operator). Rows with no matching condition are filled with null values.
Example:
class MySplitUDTF extends TableFunction[String] {
def eval(str: String): Unit = {
str.split("#").foreach(collect)
}
}
val split = new MySplitUDTF()
table.leftOuterJoin(split('c) as ('s)).select('a,'b,'c,'s)
public Table leftOuterJoin(String udtf)
Table
to a user-defined TableFunction
. Similar
to an SQL left outer join with ON TRUE, but it works with a table function. It returns all
the rows from the outer table (table on the left of the operator), and rows that do not match
the condition from the table function (which is defined in the expression on the right
side of the operator). Rows with no matching condition are filled with null values.
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.leftOuterJoin("split(c) as (s)").select("a, b, c, s");
public <T> void writeToSink(TableSink<T> sink)
Table
to a TableSink
. A TableSink
defines an external storage location.
A batch Table
can only be written to a
BatchTableSink
, a streaming Table
requires a
StreamTableSink
.
sink
- The TableSink
to which the Table
is written.public WindowedTable window(Window window)
Windows are currently only supported for streaming tables. They are required to define finite groups on which group-based aggregates can be computed.
__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 window alias, the streamed table will be processed
by a single task, i.e., with parallelism 1.
window
- window that specifies how elements are grouped.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.