Set Column directive

The SET-COLUMN directive sets the column value to the result of an expression execution.

Syntax

set-column :columm exp:{<expression>}
  • The column specifies the name of a column. If the column exists already, its value will be overwritten with the result of the specified expression. If the column does not exist, a new column will be created with the result of the specified expression.

  • The expression is a valid Apache Commons JEXL expression.

Usage Notes

The SET-COLUMN directive sets the column value to the result of the execution of an expression.

Expressions are written in Apache Commons JEXL notation.

Functions from other namespaces (such as string and math) can be called by adding the namespace and a colon before the function, such as math:ceil or string:upperCase.

Examples

Using this record as an example:

{ "first": "Root", "last": "Joltie", "age": "32", "hrlywage": "11.79", }

Applying these directives:

set-column :name concat(last, ", ", first) set-column :is_adult age > 21 ? 'yes' : 'no' set-column :salary hrlywage*40*50 set column :raised_hrlywage var x; x = math:ceil(toFLOAT(hrlywage)); x + 1 set column :salutation string:upperCase(concat(first, ' ', last))

results in this record:

Arithmetic and decimal operations example

Arithmetic operations can be used in several ways.

  • To apply a simple arithmetic operation to a single, non-Decimal column, use a mathematical notation, for example:

  • To apply an operation to a single column of type Decimal, use the decimal operations, for example.

  • To apply operations to multiple columns (of any type), use the arithmetic operations, for example.

For more information on working with numbers in Wrangler, Working with numbers.

Using this record as an example:

Applying these directives:

would result in this record:

 

Created in 2020 by Google Inc.