Skip to content

Commit

Permalink
Add documentation for #507
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric L. Charlier committed Aug 23, 2019
1 parent 95a3142 commit f9ecf6b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 3 additions & 2 deletions _documentation/primitive-result-set.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,9 @@ More info about [shared-dataset](../docs/shared-dataset)

You can also define an alteration to the result-set. For the moment, three kinds of alterations are supported by NBi:

* [rename](../resultset-alterations/#renaming)
* [filter](../resultset-rows-count-advanced/#filter).
* [rename](../resultset-alterations/#renamings)
* [extend](../resultset-alterations/#extensions)
* [filter](../resultset-rows-count-advanced/#filters).
* [convert](../resultset-alterations/#converts)
* [transform](../transform-column/)

Expand Down
28 changes: 27 additions & 1 deletion _documentation/resultset-alterations.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Using the [new syntax](../syntax-2-0/), it's possible to define alterations on a

## Renamings

This alteration is useful when you want to rename a column. This kind of alteration is usually not needed except or can be handled by the query but when dealing with flat files, it could save you! To identify the original column to be renamed, you can use a column identifier of type ordinal such as *#3* or of type name such as *[myColumn]*. The new name of this column is a [scalar](../primitive-scalar/), it means that you can use a literal value but also variables, native transformations or formatting.
This alteration is useful when you want to rename a column. This kind of alteration is usually not needed because this kind of operation can be handled by the query. On the other hand, when dealing with flat files, it could save you!

To identify the original column to be renamed, you can use a column identifier of type ordinal such as *#3* or of type name such as *[myColumn]*. The new name of this column is a [scalar](../primitive-scalar/), it means that you can use a literal value but also variables, native transformations or formatting.

In the following example, the first column is renamed *keyField* and the column named *f1* is renamed based on the content of the variable *newName* upper-cased.

Expand All @@ -25,6 +27,30 @@ In the following example, the first column is renamed *keyField* and the column
</result-set>
{% endhighlight %}

## Extensions

This alteration is useful when you want to create a new column based on the content of some other columns. At the moment, you cannot use variables or values from other rows. The definition of the content of the new column is performed with the help of the *NCalc* language, using column identifications (ordinal or names) as input parameters of the NCalc function.

In the following example, two new columns are created. The first one will be positioned as the first column (due to the identifier #0) and the second one will be added at the end of the result-set and named *myNewColumn*.

{% highlight xml %}
<result-set>
<query>
select 10 as ColA, 20 as ColB, 30 as ColC union all select 1, 5, 9
</query>
<alteration>
<extend identifier="#0">
<script language="ncalc">[#1] * Max([#2], [#3])</script>
</extend>
<extend identifier="[myNewColumn]">
<script language="ncalc">[colA] * Max(ColB, ColC)</script>
</extend>
</alteration>
</result-set>
{% endhighlight %}

When using an index identifier the newly created column will be available at the expected position. If the expected position is unreachable (less columns that expected), the alteration will put the new column as the latest column. In case of a name identifier, if the newly created column has the same name than an existing column this column will be replaced.

## Filters

See [filters for row-count](../resultset-rows-count-advanced/#filter)
Expand Down

0 comments on commit f9ecf6b

Please sign in to comment.