From 7a76793a9060e3764618e1a4af257d6044b165f8 Mon Sep 17 00:00:00 2001 From: chengxiang li Date: Tue, 3 Nov 2015 15:11:09 +0800 Subject: [PATCH] [FLINK-2955] [Documentation] Add operators description in Table API page. --- docs/libs/table.md | 204 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 199 insertions(+), 5 deletions(-) diff --git a/docs/libs/table.md b/docs/libs/table.md index b59450e19323f..afd8779237519 100644 --- a/docs/libs/table.md +++ b/docs/libs/table.md @@ -123,13 +123,207 @@ DataSet result = tableEnv.toDataSet(filtered, WC.class); When using Java, the embedded DSL for specifying expressions cannot be used. Only String expressions are supported. They support exactly the same feature set as the expression DSL. -## Expression Syntax +## Table API Operators +Table API provide a domain-spcific language to execute language-integrated queries on structured data in Scala and Java. +This section gives a brief overview of all available operators. You can find more details of operators in the [Javadoc]({{site.baseurl}}/api/java/org/apache/flink/api/table/Table.html). + +
+
+ +
+ + + + + + + + + + + + + + + + + + + -A `Table` supports to following operations: `select`, `where`, `groupBy`, `join` (Plus `filter` as -an alias for `where`.). These are also documented in the [Javadoc](http://flink.apache.org/docs/latest/api/java/org/apache/flink/api/table/Table.html) -of Table. + + + + -Some of these expect an expression. These can either be specified using an embedded Scala DSL or + + + + + + + + + + + + + + + + + + + + + +
OperatorsDescription
Select +

Similar to a SQL SELECT statement. Perform a select operation.

+{% highlight java %} +Table in = tableEnv.fromDataSet(ds, "a, b, c"); +Table result = in.select("a, c as d"); +{% endhighlight %} +
As +

Rename fields.

+{% highlight java %} +Table in = tableEnv.fromDataSet(ds, "a, b, c"); +Table result = in.as("d, e, f"); +{% endhighlight %} +
Filter +

Similar to a SQL WHERE clause. Filter out elements that do not pass the filter predicate.

+{% highlight java %} +Table in = tableEnv.fromDataSet(ds, "a, b, c"); +Table result = in.filter("a % 2 = 0"); +{% endhighlight %} +
Where +

Similar to a SQL WHERE clause. Filter out elements that do not pass the filter predicate.

+{% highlight java %} +Table in = tableEnv.fromDataSet(ds, "a, b, c"); +Table result = in.where("b = 'red'"); +{% endhighlight %} +
GroupBy +

Similar to a SQL GROUPBY clause. Group the elements on the grouping keys, with a following aggregation

+

operator to aggregate on per-group basis.

+{% highlight java %} +Table in = tableEnv.fromDataSet(ds, "a, b, c"); +Table result = in.groupby("a").select("a, b.sum as d"); +{% endhighlight %} +
Join +

Similar to a SQL JOIN clause. Join two tables, both tables must have distinct field name, and the where

+

clause is mandatory for join condition.

+{% highlight java %} +Table left = tableEnv.fromDataSet(ds1, "a, b, c"); +Table right = tableEnv.fromDataSet(ds2, "d, e, f"); +Table result = left.join(right).where("a = d").select("a, b, e"); +{% endhighlight %} +
Union +

Similar to a SQL UNION ALL clause. Union two tables, both tables must have identical schema(field names and types).

+{% highlight java %} +Table left = tableEnv.fromDataSet(ds1, "a, b, c"); +Table right = tableEnv.fromDataSet(ds2, "a, b, c"); +Table result = left.union(right); +{% endhighlight %} +
+ +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
OperatorsDescription
Select +

Similar to a SQL SELECT statement. Perform a select operation.

+{% highlight scala %} +val in = ds.as('a, 'b, 'c); +val result = in.select('a, 'c as 'd); +{% endhighlight %} +
As +

Rename fields.

+{% highlight scala %} +val in = ds.as('a, 'b, 'c); +{% endhighlight %} +
Filter +

Similar to a SQL WHERE clause. Filter out elements that do not pass the filter predicate.

+{% highlight scala %} +val in = ds.as('a, 'b, 'c); +val result = in.filter('a % 2 === 0) +{% endhighlight %} +
Where +

Similar to a SQL WHERE clause. Filter out elements that do not pass the filter predicate.

+{% highlight scala %} +val in = ds.as('a, 'b, 'c); +val result = in.where('b === "red"); +{% endhighlight %} +
GroupBy +

Similar to a SQL GROUPBY clause. Group the elements on the grouping keys, with a following aggregation

+

operator to aggregate on per-group basis.

+{% highlight scala %} +val in = ds.as('a, 'b, 'c); +val result = in.groupby('a).select('a, 'b.sum as 'd); +{% endhighlight %} +
Join +

Similar to a SQL JOIN clause. Join two tables, both tables must have distinct field name, and the where

+

clause is mandatory for join condition.

+{% highlight scala %} +val left = ds1.as('a, 'b, 'c); +val right = ds2.as('d, 'e, 'f); +val result = left.join(right).where('a === 'd).select('a, 'b, 'e); +{% endhighlight %} +
Union +

Similar to a SQL UNION ALL clause. Union two tables, both tables must have identical schema(field names and types).

+{% highlight scala %} +val left = ds1.as('a, 'b, 'c); +val right = ds2.as('a, 'b, 'c); +val result = left.union(right); +{% endhighlight %} +
+
+
+ +## Expression Syntax +Some of operators in previous section expect an expression. These can either be specified using an embedded Scala DSL or a String expression. Please refer to the examples above to learn how expressions can be formulated.