Skip to content

UserDefinedAggregateBuilder

Parameters

NameDescription
aggregateNameName of the aggregate to create or drop.

Example

typescript
// Define an aggregate that sums integers
const createSQL = new UserDefinedAggregateBuilder("sum_ints")
  .orReplace()
  .withParameters(["int"])
  .stateFunction("state_sum")
  .stateTypeIs("int")
  .finalFunction("final_sum")
  .initialCondition("0")
  .toSQL()
// Executes:
// CREATE OR REPLACE AGGREGATE sum_ints(int)
// SFUNC state_sum
// STYPE int
// FINALFUNC final_sum
// INITCOND 0

// To drop the aggregate:
const dropSQL = new UserDefinedAggregateBuilder("sum_ints")
  .withParameters(["int"])
  .dropSQL()
// Executes: DROP AGGREGATE IF EXISTS sum_ints(int)

UserDefinedAggregateBuilder

Builder for creating and dropping user-defined aggregates in ScyllaDB/Cassandra. Chain methods to configure the aggregate signature, state/final functions, and options.

orReplace

Add OR REPLACE to the CREATE statement.

withParameters

Define the parameter types for the aggregate.

Parameters

NameDescription
typesList of Scylla primitive types.

stateFunction

Set the state transition function name (SFUNC).

Parameters

NameDescription
nameName of the function.

stateTypeIs

Set the state data type (STYPE).

Parameters

NameDescription
typePrimitive ScyllaDB type.

finalFunction

(Optional) Set the final function name (FINALFUNC).

Parameters

NameDescription
nameName of the final function.

initialCondition

(Optional) Set the initial condition (INITCOND).

Parameters

NameDescription
conditionInitial value expression.

toSQL

Build and return the CREATE AGGREGATE CQL statement.

dropSQL

Build and return the DROP AGGREGATE CQL statement (IF EXISTS).

Released under the MIT License.