Skip to content

UserDefinedFunctionBuilder

Parameters

NameDescription
functionNameName of the UDF to create or drop.

Example

typescript
// Define a Java-based add_numbers function
const createSQL = new UserDefinedFunctionBuilder("add_numbers")
  .replace()
  .param("a", "int")
  .param("b", "int")
  .returns("int")
  .usingLanguage("java")
  .returnsNullOnNullInput()
  .securityDefiner()
  .as("return a + b;")
  .toSQL()
// Executes:
// CREATE OR REPLACE FUNCTION add_numbers(a int, b int)
// RETURNS int
// LANGUAGE java
// RETURNS NULL ON NULL INPUT
// SECURITY DEFINER
// AS $$return a + b;$$;

// To drop the function:
const dropSQL = new UserDefinedFunctionBuilder("add_numbers")
  .param("a", "int")
  .param("b", "int")
  .dropSQL()
// Executes: DROP FUNCTION IF EXISTS add_numbers(int, int);

UserDefinedFunctionBuilder

Builder for creating and dropping user-defined functions in ScyllaDB/Cassandra. Chain methods to configure the function signature, return type, language, and options.

ifNotExists

Add IF NOT EXISTS clause to CREATE.

replace

Add OR REPLACE clause to CREATE.

withParams

Define multiple parameters at once.

Parameters

NameDescription
paramsArray of [name, type] tuples.

param

Add a single parameter.

Parameters

NameDescription
nameParameter name.
typeParameter type.

returns

Set the return type.

Parameters

NameDescription
typePrimitiveScyllaType to return.

usingLanguage

Specify the language (java or javascript).

as

Define the function body.

Parameters

NameDescription
bodyCode block without delimiters.

calledOnNullInput

Functions are called even if input is null.

returnsNullOnNullInput

Functions return null when input is null.

securityDefiner

Set SECURITY DEFINER.

securityInvoker

Set SECURITY INVOKER.

toSQL

Build and return the CREATE FUNCTION CQL statement.

dropSQL

Build and return the DROP FUNCTION CQL statement.

Parameters

NameDescription
ifExistsInclude IF EXISTS clause.

Released under the MIT License.