r_mappkg(C;S;X)
Returns a package value for each row in a table. (Available as of version 15.21)
Function type
Vector only
Syntax
r_mappkg(C;S;X)
Input
Argument | Type | Description |
---|---|---|
C |
any | A space- or comma-separated list of column names
If Note: The columns specified by
C must be either all numeric
(integer and decimal) or all text. |
S |
integer | A boolean column or an expression in
rcv_ /rcn_ /rct_ which determines
whether or not that column is selected to be included in the calculation. See System variables for more information about
rcv_ /rcn_ /rct_ .If
|
X |
any |
X is an expression that is used to transform the value or name of
each of the selected columns.Note: Use the system variables rcv_ ,
rcn_ , and rct_ to reference the column value,
name, and type, respectively. |
Return Value
For each row of the table, r_mappkg(C;S;X)
returns a package value. The
keys of the package are the column names specified in C
. The values of the
package corresponding to the keys are the values at each column transformed by
X
, an expression in
rcv_
/rcn_
/rct_
. If X
is omitted, then the values are simply the values of each column (or rcv_
,
the default). For example, r_mappkg(;;)
yields a package whose keys are the
column names and whose values are the values of those columns at each row.
Example
The following code finds the columns names beginning with the letter 'd' in the table
pub.demo.retail.prod, selects only those columns that contain string
data, and converts the values contained within the columns to upper case. Then, it converts
the package returned by r_mappkg
to JSON:
<base table="pub.demo.retail.prod"/>
<willbe name="package" value="r_mappkg('d*';rct_='a';strupcase(rcv_))"/>
<willbe name="json" value="enjson(package;)"/>
<colord cols="json"/>
The C
argument, 'd*'
, tells r_mappkg
to
select only those column names starting with 'd'. The S
argument,
rct_='a'
, tells r_mappkg
to select only columns of type
string. The only columns beginning with 'd' and containing string data are
deptdesc
and divdesc
. The expression in
X
,strupcase(rcv_)
, tells r_mappkg
to
convert the values in each column to upper case. Finally, enjson
converts
the resulting package to JSON.