Skip to main content
Loading

Declare variables

Provides expressions for declaring variables, using variables, and control-flow.

cond

Introduced: 5.6.0

cond(condition0, action0, condition1, action1, ..., default-action)

Takes a set of test-expression/action-expression pairs. It evaluates each test one at a time. If a test returns true, 'cond' evaluates and returns the value of the corresponding expression and doesn't evaluate any of the other tests or expressions. The final expression is the default expression and is evaluated if all tests evaluate to false All actions-expressions must evaluate to the same type or be the unknown expression.

Arguments:
  • condition0 (boolean-expr)
  • action0 (expr)
  • condition1 (boolean-expr)
  • action1 (expr)
  • ... (expr)
  • default-action (expr)

Returns: (expr)

Example: Convert the value in bin "grade" from a number to a letter grade.

as_exp_build(write_exp,
as_exp_cond(
as_exp_cmp_ge(
as_exp_bin_float("grade"), as_exp_float(90.0)),
as_exp_str("A"),
as_exp_cmp_ge(
as_exp_bin_float("grade"), as_exp_float(80.0)),
as_exp_str("B"),
as_exp_cmp_ge(
as_exp_bin_float("grade"), as_exp_float(70.0)),
as_exp_str("C"),
as_exp_cmp_ge(
as_exp_bin_float("grade"), as_exp_float(60.0)),
as_exp_str("D"),
as_exp_str("F")));

unknown

Introduced: 5.6.0

unknown()

Allows you to abort an operation-expression ('write-exp' or 'read-exp'). This expression returns a special 'unknown' trilean value which, when returned by an operation-expression, will result in an error code 26 (not applicable). These failures can be ignored with the 'NO_EVAL_FAIL' policy, which allows the subsequent operations in the transaction to proceed.

This expression is only useful from an cond expression within an operation-expression and should be avoided in filter-expressions, where it might trigger an undesired move into the storage-data phase. If a 'test' expression within a cond expression yields the special 'unknown' trilean value, then the cond also immediately yields the 'unknown' value and does not evaluate any more 'test' expressions.

This special 'unknown' trilean value is the same value returned by any failed expression. For example the expression exp_div(1, 0) results in the 'unknown' value because integer division by zero is illegal.

Returns: (unknown)

Example: Add 1 to the value in the bin "count" unless the count is greater than or equal to 10.

as_exp_build(write_exp,
as_exp_cond(
as_exp_cmp_lt(as_exp_bin_int("count"), as_exp_int(10)),
as_exp_add(as_exp_bin_int("count"), as_exp_int(1)),
as_exp_unknown()));

let

Introduced: 5.6.0

let(def(...), def(...), ..., expr)

Defines variables to be used within the let expression's scope. The let expression returns the evaluated result of the last argument. This expression is useful if you need to reuse the result of a complicated or expensive expression.

Arguments:
  • def(...) (def-expr)
  • def(...) (def-expr)
  • ... (def-exprs)
  • expr (expr)

Returns: (expr)

Example: Find records where the count of hll-bin "cookies" is less than 1,000 or greater than 100,000,000.

as_exp_build(predexp,
as_exp_let(
as_exp_def("count",
as_exp_hll_get_count(as_exp_bin_hll("cookies"))),
as_exp_or(
as_exp_cmp_lt(as_exp_var("count"), as_exp_int(1000)),
as_exp_cmp_gt(
as_exp_var("count"), as_exp_int(100000000)))));

def

Introduced: 5.6.0

def(name, value)

Defines a variable within a let statement.

Arguments:
  • name (string-value)
  • value (expr)

Returns: (expr)

Example: See the example for the let expression.

var

Introduced: 5.6.0

var(name)

Retrieve the value from a variable that was defined within a let expression.

Arguments:
  • name (string-value)

Returns: (expr)

Example: See the example for the let expression.