Lambda Expressions

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Lambda expressions are anonymous functions you pass as arguments to higher-order functions such as ARRAY_TRANSFORM and ARRAY_FILTER. They enable element-wise operations on arrays without writing separate function definitions.

  • <param1>, <param2>, ...: One or more parameter names that represent the elements from the input arrays. The number of parameters must match the number of array arguments passed to the function.
  • <expression>: Any valid SQL expression that uses the parameters. The expression is evaluated once for each element (or tuple of elements) in the input arrays.
  • Lambda expressions can only be used as arguments to functions that accept them, such as ARRAY_TRANSFORM and ARRAY_FILTER.
  • The parameter names are local to the lambda and don’t conflict with column names in the outer query.
  • Lambda expressions can’t reference columns or variables from the outer query scope.
  • The return type of the lambda expression is inferred from the expression. If the expression returns only NULL, you must cast it to a specific type.
  • Data 360 uses the Python / DuckDB-style lambda syntax (lambda x: expr), not the Spark / Snowflake-style arrow syntax (x -> expr).

Use a single parameter when operating on one array.

Returns [2, 4, 6].

Use multiple parameters when operating on multiple arrays in parallel.

Returns [11, 22, 33].

Use CASE expressions within lambdas for conditional transformations.

Returns [4, 5, 6].

Return a boolean expression to filter array elements.

Returns [2, 4, 6].

Lambdas work with any data type.

Returns ["HELLO!", "WORLD?"].