Skip to content

Commit

Permalink
[hotfix][table]Improve column operations doc in tableAPI.
Browse files Browse the repository at this point in the history
This closes apache#8112.
  • Loading branch information
sunjincheng121 committed Apr 4, 2019
1 parent 0d2b082 commit e9edaaf
Showing 1 changed file with 117 additions and 84 deletions.
201 changes: 117 additions & 84 deletions docs/dev/table/tableApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,62 +185,9 @@ Table result = orders.select("a, c as d");
<p>You can use star (<code>*</code>) to act as a wild card, selecting all of the columns in the table.</p>
{% highlight java %}
Table result = orders.select("*");
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>AddColumns</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Performs a field add operation. It will throw an exception if the added fields already exist.</p>
{% highlight java %}
Table orders = tableEnv.scan("Orders");
Table result = orders.addColumns("concat(c, 'sunny')");
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>AddOrReplaceColumns</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Performs a field add operation. Existing fields will be replaced if add columns name is the same as the existing column name. Moreover, if the added fields have duplicate field name, then the last one is used. </p>
{% highlight java %}
Table orders = tableEnv.scan("Orders");
Table result = orders.addOrReplaceColumns("concat(c, 'sunny') as desc");
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>DropColumns</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Performs a field drop operation. The field expressions should be field reference expressions, and only existing fields can be dropped.</p>
{% highlight java %}
Table orders = tableEnv.scan("Orders");
Table result = orders.dropColumns("b, c");
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>RenameColumns</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Performs a field rename operation. The field expressions should be alias expressions, and only the existing fields can be renamed.</p>
{% highlight java %}
Table orders = tableEnv.scan("Orders");
Table result = orders.renameColumns("b as b2, c as c2");
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>As</strong><br>
Expand Down Expand Up @@ -317,6 +264,123 @@ val result = orders.select('*)
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>As</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Renames fields.</p>
{% highlight scala %}
val orders: Table = tableEnv.scan("Orders").as('x, 'y, 'z, 't)
{% endhighlight %}
</td>
</tr>

<tr>
<td>
<strong>Where / Filter</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Similar to a SQL WHERE clause. Filters out rows that do not pass the filter predicate.</p>
{% highlight scala %}
val orders: Table = tableEnv.scan("Orders")
val result = orders.filter('a % 2 === 0)
{% endhighlight %}
or
{% highlight scala %}
val orders: Table = tableEnv.scan("Orders")
val result = orders.where('b === "red")
{% endhighlight %}
</td>
</tr>
</tbody>
</table>
</div>
</div>

{% top %}

### Column Operations
<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%">Operators</th>
<th class="text-center">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong>AddColumns</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Performs a field add operation. It will throw an exception if the added fields already exist.</p>
{% highlight java %}
Table orders = tableEnv.scan("Orders");
Table result = orders.addColumns("concat(c, 'sunny')");
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>AddOrReplaceColumns</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Performs a field add operation. Existing fields will be replaced if add columns name is the same as the existing column name. Moreover, if the added fields have duplicate field name, then the last one is used. </p>
{% highlight java %}
Table orders = tableEnv.scan("Orders");
Table result = orders.addOrReplaceColumns("concat(c, 'sunny') as desc");
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>DropColumns</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Performs a field drop operation. The field expressions should be field reference expressions, and only existing fields can be dropped.</p>
{% highlight java %}
Table orders = tableEnv.scan("Orders");
Table result = orders.dropColumns("b, c");
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>RenameColumns</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Performs a field rename operation. The field expressions should be alias expressions, and only the existing fields can be renamed.</p>
{% highlight java %}
Table orders = tableEnv.scan("Orders");
Table result = orders.renameColumns("b as b2, c as c2");
{% endhighlight %}
</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%">Operators</th>
<th class="text-center">Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong>AddColumns</strong><br>
Expand Down Expand Up @@ -369,37 +433,6 @@ val result = orders.renameColumns('b as 'b2, 'c as 'c2)
{% endhighlight %}
</td>
</tr>
<tr>
<td>
<strong>As</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Renames fields.</p>
{% highlight scala %}
val orders: Table = tableEnv.scan("Orders").as('x, 'y, 'z, 't)
{% endhighlight %}
</td>
</tr>

<tr>
<td>
<strong>Where / Filter</strong><br>
<span class="label label-primary">Batch</span> <span class="label label-primary">Streaming</span>
</td>
<td>
<p>Similar to a SQL WHERE clause. Filters out rows that do not pass the filter predicate.</p>
{% highlight scala %}
val orders: Table = tableEnv.scan("Orders")
val result = orders.filter('a % 2 === 0)
{% endhighlight %}
or
{% highlight scala %}
val orders: Table = tableEnv.scan("Orders")
val result = orders.where('b === "red")
{% endhighlight %}
</td>
</tr>
</tbody>
</table>
</div>
Expand Down

0 comments on commit e9edaaf

Please sign in to comment.