sunjincheng121 commented on a change in pull request #8087: [FLINK-12029][table] Add column operations for TableApi URL: https://github.com/apache/flink/pull/8087#discussion_r271086764
########## File path: docs/dev/table/tableApi.md ########## @@ -1682,6 +1682,286 @@ The `OverWindow` defines a range of rows over which aggregates are computed. `Ov {% top %} + +Column Operations +---------- + +The column operations are used to select or deselect table columns. + +| SYNTAX | DESC | +| :--------------------- | :-------------------------- | +| columns(...) | select the specified columns | +| -columns(...) | deselect the columns specified | + +The detailed syntax is as follows: + +{% highlight text %} +columnOperation: + [-]columns(columnExprs) + +columnExprs: + columnExpr [, columnExpr]* + +columnExpr: + columnRef | columnIndex ~ columnIndex | columnName ~ columnName + +columnRef: + columnName(The field name that exists in the table) | columnIndex(a positive integer starting from 1) +{% endhighlight %} + +The usage of the column operation is illustrated in the following table. (Suppose we have a table with 5 columns: `(a: Int, b: Long, c: String, d:String, e: String)`): + + +<div class="codetabs" markdown="1"> +<div data-lang="java" markdown="1"> + +<table class="table table-bordered"> + <thead> + <tr> + <th class="text-left" style="width: 20%">Api</th> + <th class="text-center">Usage</th> + <th class="text-center">Description</th> + </tr> + </thead> + <tbody> + <tr> + <td> + columns(*)|* + </td> + <td> +{% highlight java %} +select("columns(*)") | select("*") = select("a, b, c, d, e") +{% endhighlight %} + </td> + <td> + all the columns + </td> + </tr> + + <tr> + <td> + columns(m ~ n) + </td> + <td> +{% highlight java %} +select("columns(2 ~ 4)") = select("b, c, d") +{% endhighlight %} + </td> + <td> + columns from m to n + </td> + </tr> + + <tr> + <td> + columns(m, n, k) + </td> + <td> +{% highlight java %} +select("columns(1, 3, e)") = select("a, c, e") +{% endhighlight %} + </td> + <td> + columns m, n, k + </td> + </tr> + + <tr> + <td> + columns(m, n ~ k) + </td> + <td> +{% highlight java %} +select("columns(1, 3 ~ 5)") = select("a, c, d ,e") +{% endhighlight %} + </td> + <td> + mixing of the above two representation + </td> + </tr> + + <tr> + <td> + -columns(m ~ n) + </td> + <td> +{% highlight java %} +select("-columns(2 ~ 4)") = select("a, e") +{% endhighlight %} + </td> + <td> + deselect columns from m to n + </td> + </tr> + + <tr> + <td> + -columns(m, n, k) + </td> + <td> +{% highlight java %} +select("-columns(1, 3, 5)") = select("b, d") +{% endhighlight %} + </td> + <td> + deselect columns m, n, k + </td> + </tr> + + <tr> + <td> + -columns(m, n ~ k) + </td> + <td> +{% highlight java %} +select("-columns(1, 3 ~ 5)") = select("b") +{% endhighlight %} + </td> + <td> + mixing of the above two representation + </td> + </tr> + + </tbody> +</table> +</div> + +<div data-lang="scala" markdown="1"> +<table class="table table-bordered"> + <thead> + <tr> + <th class="text-left" style="width: 20%">Api</th> + <th class="text-center">Usage</th> + <th class="text-center">Description</th> + </tr> + </thead> + <tbody> + <tr> + <td> + columns(*)|* + </td> + <td> +{% highlight scala %} +select(columns('*)) | select('*) = select('a, 'b, 'c, 'd, 'e) +{% endhighlight %} + </td> + <td> + all the columns + </td> + </tr> + + <tr> + <td> + columns(m ~ n) + </td> + <td> +{% highlight scala %} +select(columns(2 ~ 4)) = select('b, 'c, 'd) Review comment: Please pay attention to the comments in [google doc ](https://docs.google.com/document/d/1tryl6swt1K1pw7yvv5pdvFXSxfrBZ3_OkOObymis2ck/edit#), Timo suggest tousing some real word instead `~`, Like `to` or `until`, +1 for `to` from my side, what do you think? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services