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(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(Table right,
Expression joinPredicate)
Joins two
Table s. |
Table |
leftOuterJoin(Table right,
String joinPredicate)
Joins two
Table s. |
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.
|
<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 <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.Copyright © 2014–2017 The Apache Software Foundation. All rights reserved.