Scalar-valued functions
Last updated
Was this helpful?
Last updated
Was this helpful?
Similar to the SQL construct of scalar-valued functions, you can use Scalar-valued functions to return a single value of any CQL data type. The function body can execute any JavaScript logic.
Select a scalar value UDF as a column (Image 1).
Once you confirm that the UDF returns the expected result though a query, a calculated column can be include.
Depending on how intensive or live you want the calculation to be, choose whether to make it a live or cached calculated column.
Simply add your UDF to the calculated column (Image 2).
To use the UDF to trigger an action (such as creating a row in another table), it should be a cached calculated column.
Watch out for the following scenarios:
Don't trigger when you don't have all the necessary fields.
Don't trigger when non-relevant data on the row changes.
Make sure to appropriately insert and/or update in another table.