Expression

@Beta
abstract class Expression

Known direct subclasses
BooleanExpression

A class that represents a filter condition.

FunctionExpression

This class defines the base class for Firestore Pipeline functions, which can be evaluated within pipeline execution.

Selectable

Expressions that have an alias are Selectable

Known indirect subclasses
AliasedExpression

Represents an expression that will be given the alias in the output document.

Field

Represents a reference to a field in a Firestore document.


Represents an expression that can be evaluated to a value within the execution of a Pipeline.

Expressions are the building blocks for creating complex queries and transformations in Firestore pipelines. They can represent:

  • Field references: Access values from document fields.

  • Literals: Represent constant values (strings, numbers, booleans).

  • Function calls: Apply functions to one or more expressions.

The Expression class provides a fluent API for building expressions. You can chain together method calls to create complex expressions.

Summary

Public companion functions

Expression
abs(numericExpr: Expression)

Creates an expression that returns the absolute value of numericExpr.

Expression
abs(numericField: String)

Creates an expression that returns the absolute value of numericField.

Expression
add(first: Expression, second: Expression)

Creates an expression that adds numeric expressions.

Expression
add(first: Expression, second: Number)

Creates an expression that adds numeric expressions with a constant.

Expression
add(numericFieldName: String, second: Expression)

Creates an expression that adds a numeric field with a numeric expression.

Expression
add(numericFieldName: String, second: Number)

Creates an expression that adds a numeric field with constant.

BooleanExpression
and(condition: BooleanExpression, vararg conditions: BooleanExpression)

Creates an expression that performs a logical 'AND' operation.

Expression
array(elements: List<Any?>)

Creates an expression that creates a Firestore array value from an input array.

Expression
array(vararg elements: Any?)

Creates an expression that creates a Firestore array value from an input array.

Expression
arrayConcat(
    firstArray: Expression,
    secondArray: Any,
    vararg otherArrays: Any
)

Creates an expression that concatenates an array with other arrays.

Expression
arrayConcat(
    firstArray: Expression,
    secondArray: Expression,
    vararg otherArrays: Any
)

Creates an expression that concatenates an array with other arrays.

Expression
arrayConcat(
    firstArrayField: String,
    secondArray: Any,
    vararg otherArrays: Any
)

Creates an expression that concatenates a field's array value with other arrays.

Expression
arrayConcat(
    firstArrayField: String,
    secondArray: Expression,
    vararg otherArrays: Any
)

Creates an expression that concatenates a field's array value with other arrays.

BooleanExpression
arrayContains(array: Expression, element: Any)

Creates an expression that checks if the array contains a specific element.

BooleanExpression
arrayContains(array: Expression, element: Expression)

Creates an expression that checks if the array contains a specific element.

BooleanExpression
arrayContains(arrayFieldName: String, element: Any)

Creates an expression that checks if the array field contains a specific element.

BooleanExpression
arrayContains(arrayFieldName: String, element: Expression)

Creates an expression that checks if the array field contains a specific element.

BooleanExpression
arrayContainsAll(array: Expression, arrayExpression: Expression)

Creates an expression that checks if array contains all elements of arrayExpression.

BooleanExpression
arrayContainsAll(array: Expression, values: List<Any>)

Creates an expression that checks if array contains all the specified values.

BooleanExpression
arrayContainsAll(arrayFieldName: String, arrayExpression: Expression)

Creates an expression that checks if array field contains all elements of arrayExpression.

BooleanExpression
arrayContainsAll(arrayFieldName: String, values: List<Any>)

Creates an expression that checks if array field contains all the specified values.

BooleanExpression
arrayContainsAny(array: Expression, arrayExpression: Expression)

Creates an expression that checks if array contains any elements of arrayExpression.

BooleanExpression
arrayContainsAny(array: Expression, values: List<Any>)

Creates an expression that checks if array contains any of the specified values.

BooleanExpression
arrayContainsAny(arrayFieldName: String, arrayExpression: Expression)

Creates an expression that checks if array field contains any elements of arrayExpression.

BooleanExpression
arrayContainsAny(arrayFieldName: String, values: List<Any>)

Creates an expression that checks if array field contains any of the specified values.

Expression
arrayGet(array: Expression, offset: Expression)

Creates an expression that indexes into an array from the beginning or end and return the element.

Expression
arrayGet(array: Expression, offset: Int)

Creates an expression that indexes into an array from the beginning or end and return the element.

Expression
arrayGet(arrayFieldName: String, offset: Expression)

Creates an expression that indexes into an array from the beginning or end and return the element.

Expression
arrayGet(arrayFieldName: String, offset: Int)

Creates an expression that indexes into an array from the beginning or end and return the element.

Expression

Creates an expression that calculates the length of an array expression.

Expression
arrayLength(arrayFieldName: String)

Creates an expression that calculates the length of an array field.

Expression

Reverses the order of elements in the array.

Expression
arrayReverse(arrayFieldName: String)

Reverses the order of elements in the array field.

Expression

Creates an expression that returns the sum of the elements in an array.

Expression
arraySum(arrayFieldName: String)

Creates an expression that returns the sum of the elements in an array field.

Expression
bitAnd(bits: Expression, bitsOther: ByteArray)

Creates an expression that applies a bitwise AND operation between an expression and a constant.

Expression
bitAnd(bits: Expression, bitsOther: Expression)

Creates an expression that applies a bitwise AND operation between two expressions.

Expression
bitAnd(bitsFieldName: String, bitsOther: ByteArray)

Creates an expression that applies a bitwise AND operation between an field and constant.

Expression
bitAnd(bitsFieldName: String, bitsOther: Expression)

Creates an expression that applies a bitwise AND operation between an field and an expression.

Expression
bitLeftShift(bits: Expression, number: Int)

Creates an expression that applies a bitwise left shift operation between an expression and a constant.

Expression
bitLeftShift(bits: Expression, numberExpr: Expression)

Creates an expression that applies a bitwise left shift operation between two expressions.

Expression
bitLeftShift(bitsFieldName: String, number: Int)

Creates an expression that applies a bitwise left shift operation between a field and a constant.

Expression
bitLeftShift(bitsFieldName: String, numberExpr: Expression)

Creates an expression that applies a bitwise left shift operation between a field and an expression.

Expression

Creates an expression that applies a bitwise NOT operation to an expression.

Expression
bitNot(bitsFieldName: String)

Creates an expression that applies a bitwise NOT operation to a field.

Expression
bitOr(bits: Expression, bitsOther: ByteArray)

Creates an expression that applies a bitwise OR operation between an expression and a constant.

Expression
bitOr(bits: Expression, bitsOther: Expression)

Creates an expression that applies a bitwise OR operation between two expressions.

Expression
bitOr(bitsFieldName: String, bitsOther: ByteArray)

Creates an expression that applies a bitwise OR operation between an field and constant.

Expression
bitOr(bitsFieldName: String, bitsOther: Expression)

Creates an expression that applies a bitwise OR operation between an field and an expression.

Expression
bitRightShift(bits: Expression, number: Int)

Creates an expression that applies a bitwise right shift operation between an expression and a constant.

Expression
bitRightShift(bits: Expression, numberExpr: Expression)

Creates an expression that applies a bitwise right shift operation between two expressions.

Expression
bitRightShift(bitsFieldName: String, number: Int)

Creates an expression that applies a bitwise right shift operation between a field and a constant.

Expression
bitRightShift(bitsFieldName: String, numberExpr: Expression)

Creates an expression that applies a bitwise right shift operation between a field and an expression.

Expression
bitXor(bits: Expression, bitsOther: ByteArray)

Creates an expression that applies a bitwise XOR operation between an expression and a constant.

Expression
bitXor(bits: Expression, bitsOther: Expression)

Creates an expression that applies a bitwise XOR operation between two expressions.

Expression
bitXor(bitsFieldName: String, bitsOther: ByteArray)

Creates an expression that applies a bitwise XOR operation between an field and constant.

Expression
bitXor(bitsFieldName: String, bitsOther: Expression)

Creates an expression that applies a bitwise XOR operation between an field and an expression.

Expression
byteLength(fieldName: String)

Creates an expression that calculates the length of a string represented by a field in UTF-8 bytes, or just the length of a Blob.

Expression

Creates an expression that calculates the length of a string in UTF-8 bytes, or just the length of a Blob.

Expression
ceil(numericExpr: Expression)

Creates an expression that returns the smallest integer that isn't less than numericExpr.

Expression
ceil(numericField: String)

Creates an expression that returns the smallest integer that isn't less than numericField.

Expression

Creates an expression that calculates the character length of a string expression in UTF8.

Expression
charLength(fieldName: String)

Creates an expression that calculates the character length of a string field in UTF8.

Expression

Creates an expression that returns the collection ID from a path.

Expression
collectionId(pathField: String)

Creates an expression that returns the collection ID from a path.

Expression
concat(first: Expression, second: Any, vararg others: Any)

Creates an expression that concatenates strings, arrays, or blobs.

Expression
concat(first: Expression, second: Expression, vararg others: Any)

Creates an expression that concatenates strings, arrays, or blobs.

Expression
concat(first: String, second: Any, vararg others: Any)

Creates an expression that concatenates strings, arrays, or blobs.

Expression
concat(first: String, second: Expression, vararg others: Any)

Creates an expression that concatenates strings, arrays, or blobs.

Expression
conditional(
    condition: BooleanExpression,
    thenExpr: Expression,
    elseExpr: Expression
)

Creates a conditional expression that evaluates to a thenExpr expression if a condition is true or an elseExpr expression if the condition is false.

Expression
conditional(condition: BooleanExpression, thenValue: Any, elseValue: Any)

Creates a conditional expression that evaluates to a thenValue if a condition is true or an elseValue if the condition is false.

Expression

Create a constant for a DocumentReference value.

Expression
constant(value: Blob)

Create a constant for a Blob value.

BooleanExpression
constant(value: Boolean)

Create a constant for a Boolean value.

Expression

Create a constant for a bytes value.

Expression
constant(value: Date)

Create a constant for a Date value.

Expression

Create a constant for a GeoPoint value.

Expression
constant(value: Number)

Create a constant for a Number value.

Expression
constant(value: String)

Create a constant for a String value.

Expression

Create a constant for a Timestamp value.

Expression

Create a constant for a VectorValue value.

Expression
cosineDistance(vector1: Expression, vector2: DoubleArray)

Calculates the Cosine distance between vector expression and a vector literal.

Expression
cosineDistance(vector1: Expression, vector2: Expression)

Calculates the Cosine distance between two vector expressions.

Expression
cosineDistance(vector1: Expression, vector2: VectorValue)

Calculates the Cosine distance between vector expression and a vector literal.

Expression
cosineDistance(vectorFieldName: String, vector: DoubleArray)

Calculates the Cosine distance between a vector field and a vector literal.

Expression
cosineDistance(vectorFieldName: String, vector: Expression)

Calculates the Cosine distance between a vector field and a vector expression.

Expression
cosineDistance(vectorFieldName: String, vector: VectorValue)

Calculates the Cosine distance between a vector field and a vector literal.

Expression

Creates an expression that evaluates to the current server timestamp.

Expression
divide(dividend: Expression, divisor: Expression)

Creates an expression that divides two numeric expressions.

Expression
divide(dividend: Expression, divisor: Number)

Creates an expression that divides a numeric expression by a constant.

Expression
divide(dividendFieldName: String, divisor: Expression)

Creates an expression that divides numeric field by a numeric expression.

Expression
divide(dividendFieldName: String, divisor: Number)

Creates an expression that divides a numeric field by a constant.

Expression

Creates an expression that returns the document ID from a DocumentReference.

Expression
documentId(documentPath: Expression)

Creates an expression that returns the document ID from a path.

Expression
documentId(documentPath: String)

Creates an expression that returns the document ID from a path.

Expression
dotProduct(vector1: Expression, vector2: DoubleArray)

Calculates the dot product distance between vector expression and a vector literal.

Expression
dotProduct(vector1: Expression, vector2: Expression)

Calculates the dot product distance between two vector expressions.

Expression
dotProduct(vector1: Expression, vector2: VectorValue)

Calculates the dot product distance between vector expression and a vector literal.

Expression
dotProduct(vectorFieldName: String, vector: DoubleArray)

Calculates the dot product distance between vector field and a vector literal.

Expression
dotProduct(vectorFieldName: String, vector: Expression)

Calculates the dot product distance between a vector field and a vector expression.

Expression
dotProduct(vectorFieldName: String, vector: VectorValue)

Calculates the dot product distance between a vector field and a vector literal.

BooleanExpression
endsWith(fieldName: String, suffix: Expression)

Creates an expression that checks if a string expression ends with a given suffix.

BooleanExpression
endsWith(fieldName: String, suffix: String)

Creates an expression that checks if a string expression ends with a given suffix.

BooleanExpression
endsWith(stringExpr: Expression, suffix: Expression)

Creates an expression that checks if a string expression ends with a given suffix.

BooleanExpression
endsWith(stringExpr: Expression, suffix: String)

Creates an expression that checks if a string expression ends with a given suffix.

BooleanExpression
equal(fieldName: String, expression: Expression)

Creates an expression that checks if a field's value is equal to an expression.

BooleanExpression
equal(fieldName: String, value: Any)

Creates an expression that checks if a field's value is equal to another value.

BooleanExpression
equal(left: Expression, right: Any)

Creates an expression that checks if an expression is equal to a value.

BooleanExpression
equal(left: Expression, right: Expression)

Creates an expression that checks if two expressions are equal.

BooleanExpression
equalAny(expression: Expression, arrayExpression: Expression)

Creates an expression that checks if an expression, when evaluated, is equal to any of the elements of arrayExpression.

BooleanExpression
equalAny(expression: Expression, values: List<Any>)

Creates an expression that checks if an expression, when evaluated, is equal to any of the provided values.

BooleanExpression
equalAny(fieldName: String, arrayExpression: Expression)

Creates an expression that checks if a field's value is equal to any of the elements of arrayExpression.

BooleanExpression
equalAny(fieldName: String, values: List<Any>)

Creates an expression that checks if a field's value is equal to any of the provided values .

Expression

Calculates the Euclidean distance between vector expression and a vector literal.

Expression
euclideanDistance(vector1: Expression, vector2: Expression)

Calculates the Euclidean distance between two vector expressions.

Expression

Calculates the Euclidean distance between vector expression and a vector literal.

Expression
euclideanDistance(vectorFieldName: String, vector: DoubleArray)

Calculates the Euclidean distance between a vector field and a vector literal.

Expression
euclideanDistance(vectorFieldName: String, vector: Expression)

Calculates the Euclidean distance between a vector field and a vector expression.

Expression
euclideanDistance(vectorFieldName: String, vector: VectorValue)

Calculates the Euclidean distance between a vector field and a vector literal.

BooleanExpression
exists(fieldName: String)

Creates an expression that checks if a field exists.

BooleanExpression

Creates an expression that checks if a field exists.

Expression
exp(numericExpr: Expression)

Creates an expression that returns Euler's number e raised to the power of numericExpr.

Expression
exp(numericField: String)

Creates an expression that returns Euler's number e raised to the power of numericField.

Field
field(fieldPath: FieldPath)

Creates a Field instance representing the field at the given path.

Field
field(name: String)

Creates a Field instance representing the field at the given path.

Expression
floor(numericExpr: Expression)

Creates an expression that returns the largest integer that is not greater than numericExpr

Expression
floor(numericField: String)

Creates an expression that returns the largest integer that is not greater than numericField.

BooleanExpression
greaterThan(fieldName: String, expression: Expression)

Creates an expression that checks if a field's value is greater than an expression.

BooleanExpression
greaterThan(fieldName: String, value: Any)

Creates an expression that checks if a field's value is greater than another value.

BooleanExpression
greaterThan(left: Expression, right: Any)

Creates an expression that checks if an expression is greater than a value.

BooleanExpression

Creates an expression that checks if the first expression is greater than the second expression.

BooleanExpression
greaterThanOrEqual(fieldName: String, expression: Expression)

Creates an expression that checks if a field's value is greater than or equal to an expression.

BooleanExpression
greaterThanOrEqual(fieldName: String, value: Any)

Creates an expression that checks if a field's value is greater than or equal to another value.

BooleanExpression

Creates an expression that checks if an expression is greater than or equal to a value.

BooleanExpression

Creates an expression that checks if the first expression is greater than or equal to the second expression.

Expression
ifAbsent(ifExpr: Expression, elseExpr: Expression)

Creates an expression that returns the elseExpr argument if ifExpr is absent, else return the result of the ifExpr argument evaluation.

Expression
ifAbsent(ifExpr: Expression, elseValue: Any)

Creates an expression that returns the elseValue argument if ifExpr is absent, else return the result of the ifExpr argument evaluation.

Expression
ifAbsent(ifFieldName: String, elseExpr: Expression)

Creates an expression that returns the elseExpr argument if ifFieldName is absent, else return the value of the field.

Expression
ifAbsent(ifFieldName: String, elseValue: Any)

Creates an expression that returns the elseValue argument if ifFieldName is absent, else return the value of the field.

BooleanExpression

Creates an expression that returns the catchExpr argument if there is an error, else return the result of the tryExpr argument evaluation.

Expression
ifError(tryExpr: Expression, catchExpr: Expression)

Creates an expression that returns the catchExpr argument if there is an error, else return the result of the tryExpr argument evaluation.

Expression
ifError(tryExpr: Expression, catchValue: Any)

Creates an expression that returns the catchValue argument if there is an error, else return the result of the tryExpr argument evaluation.

BooleanExpression
isAbsent(fieldName: String)

Creates an expression that returns true if a field is absent.

BooleanExpression

Creates an expression that returns true if a value is absent.

BooleanExpression

Creates an expression that checks if a given expression produces an error.

Expression
join(arrayExpression: Expression, delimiter: String)

Creates an expression that joins the elements of an array into a string.

Expression
join(arrayExpression: Expression, delimiterExpression: Expression)

Creates an expression that joins the elements of an array into a string.

Expression
join(arrayFieldName: String, delimiter: String)

Creates an expression that joins the elements of an array field into a string.

Expression
join(arrayFieldName: String, delimiterExpression: Expression)

Creates an expression that joins the elements of an array field into a string.

Expression

Creates an expression that calculates the length of a string, array, map, vector, or blob expression.

Expression
length(fieldName: String)

Creates an expression that calculates the length of a string, array, map, vector, or blob field.

BooleanExpression
lessThan(fieldName: String, expression: Expression)

Creates an expression that checks if a field's value is less than an expression.

BooleanExpression
lessThan(fieldName: String, value: Any)

Creates an expression that checks if a field's value is less than another value.

BooleanExpression
lessThan(left: Expression, right: Any)

Creates an expression that checks if an expression is less than a value.

BooleanExpression
lessThan(left: Expression, right: Expression)

Creates an expression that checks if the first expression is less than the second expression.

BooleanExpression
lessThanOrEqual(fieldName: String, expression: Expression)

Creates an expression that checks if a field's value is less than or equal to an expression.

BooleanExpression
lessThanOrEqual(fieldName: String, value: Any)

Creates an expression that checks if a field's value is less than or equal to another value.

BooleanExpression
lessThanOrEqual(left: Expression, right: Any)

Creates an expression that checks if an expression is less than or equal to a value.

BooleanExpression

Creates an expression that checks if the first expression is less than or equal to the second expression.

BooleanExpression
like(fieldName: String, pattern: Expression)

Creates an expression that performs a case-sensitive wildcard string comparison against a field.

BooleanExpression
like(fieldName: String, pattern: String)

Creates an expression that performs a case-sensitive wildcard string comparison against a field.

BooleanExpression
like(stringExpression: Expression, pattern: Expression)

Creates an expression that performs a case-sensitive wildcard string comparison.

BooleanExpression
like(stringExpression: Expression, pattern: String)

Creates an expression that performs a case-sensitive wildcard string comparison.

Expression
ln(numericExpr: Expression)

Creates an expression that returns the natural logarithm (base e) of numericExpr.

Expression
ln(numericField: String)

Creates an expression that returns the natural logarithm (base e) of numericField.

Expression
log(numericExpr: Expression, base: Expression)

Creates an expression that returns the logarithm of numericExpr with a given base.

Expression
log(numericExpr: Expression, base: Number)

Creates an expression that returns the logarithm of numericExpr with a given base.

Expression
log(numericField: String, base: Expression)

Creates an expression that returns the logarithm of numericField with a given base.

Expression
log(numericField: String, base: Number)

Creates an expression that returns the logarithm of numericField with a given base.

Expression
log10(numericExpr: Expression)

Creates an expression that returns the base 10 logarithm of numericExpr.

Expression
log10(numericField: String)

Creates an expression that returns the base 10 logarithm of numericField.

Expression
logicalMaximum(expr: Expression, vararg others: Any)

Creates an expression that returns the largest value between multiple input expressions or literal values.

Expression
logicalMaximum(fieldName: String, vararg others: Any)

Creates an expression that returns the largest value between multiple input expressions or literal values.

Expression
logicalMinimum(expr: Expression, vararg others: Any)

Creates an expression that returns the smallest value between multiple input expressions or literal values.

Expression
logicalMinimum(fieldName: String, vararg others: Any)

Creates an expression that returns the smallest value between multiple input expressions or literal values.

Expression
map(elements: Map<StringAny>)

Creates an expression that creates a Firestore map value from an input object.

Expression
mapGet(fieldName: String, key: String)

Accesses a value from a map (object) field using the provided key.

Expression
mapGet(fieldName: String, keyExpression: Expression)

Accesses a value from a map (object) field using the provided keyExpression.

Expression
mapGet(mapExpression: Expression, key: String)

Accesses a value from a map (object) field using the provided key.

Expression
mapGet(mapExpression: Expression, keyExpression: Expression)

Accesses a value from a map (object) field using the provided keyExpression.

Expression
mapMerge(
    firstMap: Expression,
    secondMap: Expression,
    vararg otherMaps: Expression
)

Creates an expression that merges multiple maps into a single map.

Expression
mapMerge(
    firstMapFieldName: String,
    secondMap: Expression,
    vararg otherMaps: Expression
)

Creates an expression that merges multiple maps into a single map.

Expression
mapRemove(mapExpr: Expression, key: Expression)

Creates an expression that removes a key from the map produced by evaluating an expression.

Expression
mapRemove(mapExpr: Expression, key: String)

Creates an expression that removes a key from the map produced by evaluating an expression.

Expression
mapRemove(mapField: String, key: Expression)

Creates an expression that removes a key from the map produced by evaluating an expression.

Expression
mapRemove(mapField: String, key: String)

Creates an expression that removes a key from the map produced by evaluating an expression.

Expression
mod(dividend: Expression, divisor: Expression)

Creates an expression that calculates the modulo (remainder) of dividing two numeric expressions.

Expression
mod(dividend: Expression, divisor: Number)

Creates an expression that calculates the modulo (remainder) of dividing a numeric expression by a constant.

Expression
mod(dividendFieldName: String, divisor: Expression)

Creates an expression that calculates the modulo (remainder) of dividing a numeric field by a constant.

Expression
mod(dividendFieldName: String, divisor: Number)

Creates an expression that calculates the modulo (remainder) of dividing a numeric field by a constant.

Expression
multiply(first: Expression, second: Expression)

Creates an expression that multiplies numeric expressions.

Expression
multiply(first: Expression, second: Number)

Creates an expression that multiplies numeric expressions with a constant.

Expression
multiply(numericFieldName: String, second: Expression)

Creates an expression that multiplies a numeric field with a numeric expression.

Expression
multiply(numericFieldName: String, second: Number)

Creates an expression that multiplies a numeric field with a constant.

BooleanExpression
not(condition: BooleanExpression)

Creates an expression that negates a boolean expression.

BooleanExpression
notEqual(fieldName: String, expression: Expression)

Creates an expression that checks if a field's value is not equal to an expression.

BooleanExpression
notEqual(fieldName: String, value: Any)

Creates an expression that checks if a field's value is not equal to another value.

BooleanExpression
notEqual(left: Expression, right: Any)

Creates an expression that checks if an expression is not equal to a value.

BooleanExpression
notEqual(left: Expression, right: Expression)

Creates an expression that checks if two expressions are not equal.

BooleanExpression
notEqualAny(expression: Expression, arrayExpression: Expression)

Creates an expression that checks if an expression, when evaluated, is not equal to all the elements of arrayExpression.

BooleanExpression
notEqualAny(expression: Expression, values: List<Any>)

Creates an expression that checks if an expression, when evaluated, is not equal to all the provided values.

BooleanExpression
notEqualAny(fieldName: String, arrayExpression: Expression)

Creates an expression that checks if a field's value is not equal to all of the elements of arrayExpression.

BooleanExpression
notEqualAny(fieldName: String, values: List<Any>)

Creates an expression that checks if a field's value is not equal to all of the provided values.

Expression

Constant for a null value.

BooleanExpression
or(condition: BooleanExpression, vararg conditions: BooleanExpression)

Creates an expression that performs a logical 'OR' operation.

Expression
pow(numericExpr: Expression, exponent: Expression)

Creates an expression that returns the numericExpr raised to the power of the exponent.

Expression
pow(numericExpr: Expression, exponent: Number)

Creates an expression that returns the numericExpr raised to the power of the exponent.

Expression
pow(numericField: String, exponent: Expression)

Creates an expression that returns the numericField raised to the power of the exponent.

Expression
pow(numericField: String, exponent: Number)

Creates an expression that returns the numericField raised to the power of the exponent.

Expression
rawFunction(name: String, vararg expr: Expression)

Creates a 'raw' function expression.

BooleanExpression
regexContains(fieldName: String, pattern: Expression)

Creates an expression that checks if a string field contains a specified regular expression as a substring.

BooleanExpression
regexContains(fieldName: String, pattern: String)

Creates an expression that checks if a string field contains a specified regular expression as a substring.

BooleanExpression
regexContains(stringExpression: Expression, pattern: Expression)

Creates an expression that checks if a string expression contains a specified regular expression as a substring.

BooleanExpression
regexContains(stringExpression: Expression, pattern: String)

Creates an expression that checks if a string expression contains a specified regular expression as a substring.

BooleanExpression
regexMatch(fieldName: String, pattern: Expression)

Creates an expression that checks if a string field matches a specified regular expression.

BooleanExpression
regexMatch(fieldName: String, pattern: String)

Creates an expression that checks if a string field matches a specified regular expression.

BooleanExpression
regexMatch(stringExpression: Expression, pattern: Expression)

Creates an expression that checks if a string field matches a specified regular expression.

BooleanExpression
regexMatch(stringExpression: Expression, pattern: String)

Creates an expression that checks if a string field matches a specified regular expression.

Expression
reverse(fieldName: String)

Creates an expression that reverses a string value from the specified field.

Expression
reverse(stringExpression: Expression)

Creates an expression that reverses a string.

Expression
round(numericExpr: Expression)

Creates an expression that rounds numericExpr to nearest integer.

Expression
round(numericField: String)

Creates an expression that rounds numericField to nearest integer.

Expression
roundToPrecision(numericExpr: Expression, decimalPlace: Expression)

Creates an expression that rounds off numericExpr to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative.

Expression
roundToPrecision(numericExpr: Expression, decimalPlace: Int)

Creates an expression that rounds off numericExpr to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative.

Expression
roundToPrecision(numericField: String, decimalPlace: Expression)

Creates an expression that rounds off numericField to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative.

Expression
roundToPrecision(numericField: String, decimalPlace: Int)

Creates an expression that rounds off numericField to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative.

Expression
split(fieldName: String, delimiter: Blob)

Creates an expression that splits a blob field by a blob delimiter.

Expression
split(fieldName: String, delimiter: Expression)

Creates an expression that splits a string or blob field by a delimiter.

Expression
split(fieldName: String, delimiter: String)

Creates an expression that splits a string or blob field by a string delimiter.

Expression
split(value: Expression, delimiter: Blob)

Creates an expression that splits a blob by a blob delimiter.

Expression
split(value: Expression, delimiter: Expression)

Creates an expression that splits a string or blob by a delimiter.

Expression
split(value: Expression, delimiter: String)

Creates an expression that splits a string or blob by a string delimiter.

Expression
sqrt(numericExpr: Expression)

Creates an expression that returns the square root of numericExpr.

Expression
sqrt(numericField: String)

Creates an expression that returns the square root of numericField.

BooleanExpression
startsWith(fieldName: String, prefix: Expression)

Creates an expression that checks if a string expression starts with a given prefix.

BooleanExpression
startsWith(fieldName: String, prefix: String)

Creates an expression that checks if a string expression starts with a given prefix.

BooleanExpression
startsWith(stringExpr: Expression, prefix: Expression)
// Check if the 'fullName' field starts with the value of the 'firstName' field
startsWith(field("fullName"), field("firstName"))
BooleanExpression
startsWith(stringExpr: Expression, prefix: String)

Creates an expression that checks if a string expression starts with a given prefix.

Expression
stringConcat(fieldName: String, vararg otherStrings: Any)

Creates an expression that concatenates string expressions together.

Expression
stringConcat(fieldName: String, vararg otherStrings: Expression)

Creates an expression that concatenates string expressions together.

Expression
stringConcat(firstString: Expression, vararg otherStrings: Any)

Creates an expression that concatenates string expressions together.

Expression
stringConcat(firstString: Expression, vararg otherStrings: Expression)

Creates an expression that concatenates string expressions together.

BooleanExpression
stringContains(fieldName: String, substring: Expression)

Creates an expression that checks if a string field contains a specified substring.

BooleanExpression
stringContains(fieldName: String, substring: String)

Creates an expression that checks if a string field contains a specified substring.

BooleanExpression
stringContains(stringExpression: Expression, substring: Expression)

Creates an expression that checks if a string expression contains a specified substring.

BooleanExpression
stringContains(stringExpression: Expression, substring: String)

Creates an expression that checks if a string expression contains a specified substring.

Expression
stringReverse(fieldName: String)

Reverses the given string field.

Expression

Reverses the given string expression.

Expression
substring(fieldName: String, index: Int, length: Int)

Creates an expression that returns a substring of the given string.

Expression
substring(
    stringExpression: Expression,
    index: Expression,
    length: Expression
)

Creates an expression that returns a substring of the given string.

Expression
subtract(minuend: Expression, subtrahend: Expression)

Creates an expression that subtracts two expressions.

Expression
subtract(minuend: Expression, subtrahend: Number)

Creates an expression that subtracts a constant value from a numeric expression.

Expression
subtract(numericFieldName: String, subtrahend: Expression)

Creates an expression that subtracts a numeric expressions from numeric field.

Expression
subtract(numericFieldName: String, subtrahend: Number)

Creates an expression that subtracts a constant from numeric field.

Expression
timestampAdd(fieldName: String, unit: Expression, amount: Expression)

Creates an expression that adds a specified amount of time to a timestamp.

Expression
timestampAdd(fieldName: String, unit: String, amount: Long)

Creates an expression that adds a specified amount of time to a timestamp.

Expression
timestampAdd(timestamp: Expression, unit: Expression, amount: Expression)

Creates an expression that adds a specified amount of time to a timestamp.

Expression
timestampAdd(timestamp: Expression, unit: String, amount: Long)

Creates an expression that adds a specified amount of time to a timestamp.

Expression
timestampSubtract(fieldName: String, unit: Expression, amount: Expression)

Creates an expression that subtracts a specified amount of time to a timestamp.

Expression
timestampSubtract(fieldName: String, unit: String, amount: Long)

Creates an expression that subtracts a specified amount of time to a timestamp.

Expression
timestampSubtract(
    timestamp: Expression,
    unit: Expression,
    amount: Expression
)

Creates an expression that subtracts a specified amount of time to a timestamp.

Expression
timestampSubtract(timestamp: Expression, unit: String, amount: Long)

Creates an expression that subtracts a specified amount of time to a timestamp.

Expression

Creates an expression that converts a timestamp expression to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression

Creates an expression that converts a timestamp field to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression

Creates an expression that converts a timestamp expression to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression

Creates an expression that converts a timestamp field to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression

Creates an expression that converts a timestamp expression to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression

Creates an expression that converts a timestamp field to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression
timestampTruncate(fieldName: String, granularity: Expression)

Creates an expression that truncates a timestamp to a specified granularity.

Expression
timestampTruncate(fieldName: String, granularity: String)

Creates an expression that truncates a timestamp to a specified granularity.

Expression
timestampTruncate(timestamp: Expression, granularity: Expression)

Creates an expression that truncates a timestamp to a specified granularity.

Expression
timestampTruncate(timestamp: Expression, granularity: String)

Creates an expression that truncates a timestamp to a specified granularity.

Expression
timestampTruncate(
    fieldName: String,
    granularity: Expression,
    timezone: String
)

Creates an expression that truncates a timestamp to a specified granularity in a given timezone.

Expression
timestampTruncate(fieldName: String, granularity: String, timezone: String)

Creates an expression that truncates a timestamp to a specified granularity in a given timezone.

Expression
timestampTruncate(
    timestamp: Expression,
    granularity: Expression,
    timezone: String
)

Creates an expression that truncates a timestamp to a specified granularity in a given timezone.

Expression
timestampTruncate(
    timestamp: Expression,
    granularity: String,
    timezone: String
)

Creates an expression that truncates a timestamp to a specified granularity in a given timezone.

Expression
toLower(fieldName: String)

Creates an expression that converts a string field to lowercase.

Expression
toLower(stringExpression: Expression)

Creates an expression that converts a string expression to lowercase.

Expression
toUpper(fieldName: String)

Creates an expression that converts a string field to uppercase.

Expression
toUpper(stringExpression: Expression)

Creates an expression that converts a string expression to uppercase.

Expression
trim(fieldName: String)

Creates an expression that removes leading and trailing whitespace from a string field.

Expression
trim(stringExpression: Expression)

Creates an expression that removes leading and trailing whitespace from a string expression.

Expression
trimValue(fieldName: String, valueToTrim: String)

Creates an expression that removes leading and trailing characters from a string field.

Expression
trimValue(stringExpression: Expression, valueToTrim: Expression)

Creates an expression that removes leading and trailing values from a expression.

Expression

Creates an expression that returns a string indicating the type of the value this expression evaluates to.

Expression
type(fieldName: String)

Creates an expression that returns a string indicating the type of the value this field evaluates to.

Expression

Creates an expression that interprets an expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Creates an expression that interprets a field's value as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Creates an expression that interprets an expression as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Creates an expression that interprets a field's value as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Creates an expression that interprets an expression as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Creates an expression that interprets a field's value as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Create a vector constant for a DoubleArray value.

Expression

Create a vector constant for a VectorValue value.

Expression
vectorLength(fieldName: String)

Creates an expression that calculates the length (dimension) of a Firestore Vector.

Expression
vectorLength(vectorExpression: Expression)

Creates an expression that calculates the length (dimension) of a Firestore Vector.

BooleanExpression
xor(condition: BooleanExpression, vararg conditions: BooleanExpression)

Creates an expression that performs a logical 'XOR' operation.

Public functions

Expression
abs()

Creates an expression that returns the absolute value of this expression.

Expression
add(second: Expression)

Creates an expression that adds this numeric expression to another numeric expression.

Expression
add(second: Number)

Creates an expression that adds this numeric expression to a constants.

open Selectable
alias(alias: String)

Assigns an alias to this expression.

Expression
arrayConcat(secondArray: Any, vararg otherArrays: Any)

Creates an expression that concatenates a field's array value with other arrays.

Expression
arrayConcat(secondArray: Expression, vararg otherArrays: Any)

Creates an expression that concatenates a field's array value with other arrays.

BooleanExpression
arrayContains(element: Any)

Creates an expression that checks if array contains a specific element.

BooleanExpression

Creates an expression that checks if array contains a specific element.

BooleanExpression
arrayContainsAll(arrayExpression: Expression)

Creates an expression that checks if array contains all elements of arrayExpression.

BooleanExpression

Creates an expression that checks if array contains all the specified values.

BooleanExpression
arrayContainsAny(arrayExpression: Expression)

Creates an expression that checks if array contains any elements of arrayExpression.

BooleanExpression

Creates an expression that checks if array contains any of the specified values.

Expression

Creates an expression that indexes into an array from the beginning or end and return the element.

Expression
arrayGet(offset: Int)

Creates an expression that indexes into an array from the beginning or end and return the element.

Expression

Creates an expression that calculates the length of an array expression.

Expression

Reverses the order of elements in the array.

Expression

Creates an expression that returns the sum of the elements in this array expression.

BooleanExpression

Casts the expression to a BooleanExpression.

Ordering

Create an Ordering that sorts documents in ascending order based on value of this expression

AggregateFunction

Creates an aggregation that calculates the average (mean) of this numeric expression across multiple stage inputs.

Expression
bitAnd(bitsOther: ByteArray)

Creates an expression that applies a bitwise AND operation with a constant.

Expression
bitAnd(bitsOther: Expression)

Creates an expression that applies a bitwise AND operation with other expression.

Expression
bitLeftShift(number: Int)

Creates an expression that applies a bitwise left shift operation with a constant.

Expression
bitLeftShift(numberExpr: Expression)

Creates an expression that applies a bitwise left shift operation with an expression.

Expression

Creates an expression that applies a bitwise NOT operation to this expression.

Expression
bitOr(bitsOther: ByteArray)

Creates an expression that applies a bitwise OR operation with a constant.

Expression
bitOr(bitsOther: Expression)

Creates an expression that applies a bitwise OR operation with other expression.

Expression
bitRightShift(number: Int)

Creates an expression that applies a bitwise right shift operation with a constant.

Expression

Creates an expression that applies a bitwise right shift operation with an expression.

Expression
bitXor(bitsOther: ByteArray)

Creates an expression that applies a bitwise XOR operation with a constant.

Expression
bitXor(bitsOther: Expression)

Creates an expression that applies a bitwise XOR operation with an expression.

Expression

Creates an expression that calculates the length of a string in UTF-8 bytes, or just the length of a Blob.

Expression

Creates an expression that returns the smallest integer that isn't less than this numeric expression.

Expression

Creates an expression that calculates the character length of this string expression in UTF8.

Expression

Creates an expression that returns the collection ID from this path expression.

Expression
concat(second: Any, vararg others: Any)

Creates an expression that concatenates this expression's value with others.

Expression
concat(second: Expression, vararg others: Any)

Creates an expression that concatenates this expression's value with others.

Expression

Calculates the Cosine distance between this vector expression and a vector literal.

Expression

Calculates the Cosine distance between this and another vector expressions.

Expression

Calculates the Cosine distance between this vector expression and a vector literal.

AggregateFunction

Creates an aggregation that counts the number of stage inputs with valid evaluations of the this expression.

AggregateFunction

Creates an aggregation that counts the number of distinct values of an expression across multiple stage inputs.

Ordering

Create an Ordering that sorts documents in descending order based on value of this expression

Expression
divide(divisor: Expression)

Creates an expression that divides this numeric expression by another numeric expression.

Expression
divide(divisor: Number)

Creates an expression that divides this numeric expression by a constant.

Expression

Creates an expression that returns the document ID from this path expression.

Expression

Calculates the dot product distance between this vector expression and a vector literal.

Expression

Calculates the dot product distance between this and another vector expression.

Expression

Calculates the dot product distance between this vector expression and a vector literal.

BooleanExpression

Creates an expression that checks if this string expression ends with a given suffix.

BooleanExpression
endsWith(suffix: String)

Creates an expression that checks if this string expression ends with a given suffix.

BooleanExpression
equal(other: Expression)

Creates an expression that checks if this and other expression are equal.

BooleanExpression
equal(value: Any)

Creates an expression that checks if this expression is equal to a value.

BooleanExpression
equalAny(arrayExpression: Expression)

Creates an expression that checks if this expression, when evaluated, is equal to any of the elements of arrayExpression.

BooleanExpression
equalAny(values: List<Any>)

Creates an expression that checks if this expression, when evaluated, is equal to any of the provided values.

Expression

Calculates the Euclidean distance between this vector expression and a vector literal.

Expression

Calculates the Euclidean distance between this and another vector expression.

Expression

Calculates the Euclidean distance between this vector expression and a vector literal.

BooleanExpression

Creates an expression that checks if this expression evaluates to a name of the field that exists.

Expression
exp()

Creates an expression that returns Euler's number e raised to the power of this expression.

Expression

Creates an expression that returns the largest integer that is not greater than this numeric expression.

BooleanExpression

Creates an expression that checks if this expression is greater than the other expression.

BooleanExpression
greaterThan(value: Any)

Creates an expression that checks if this expression is greater than a value.

BooleanExpression

Creates an expression that checks if this expression is greater than or equal to the other expression.

BooleanExpression

Creates an expression that checks if this expression is greater than or equal to a value.

Expression
ifAbsent(elseExpr: Expression)

Creates an expression that returns the elseExpr argument if this expression is absent, else return the result of this expression.

Expression
ifAbsent(elseValue: Any)

Creates an expression that returns the elseValue argument if this expression is absent, else return the result of this expression.

Expression
ifError(catchExpr: Expression)

Creates an expression that returns the catchExpr argument if there is an error, else return the result of this expression.

Expression
ifError(catchValue: Any)

Creates an expression that returns the catchValue argument if there is an error, else return the result of this expression.

BooleanExpression

Creates an expression that returns true if the result of this expression is absent.

BooleanExpression

Creates an expression that checks if this expression produces an error.

Expression
join(delimiter: String)

Creates an expression that joins the elements of an array into a string.

Expression
join(delimiterExpression: Expression)

Creates an expression that joins the elements of an array into a string.

Expression

Creates an expression that calculates the length of a string, array, map, vector, or blob expression.

BooleanExpression

Creates an expression that checks if this expression is less than the other expression.

BooleanExpression
lessThan(value: Any)

Creates an expression that checks if this expression is less than a value.

BooleanExpression

Creates an expression that checks if this expression is less than or equal to the other expression.

BooleanExpression

Creates an expression that checks if this expression is less than or equal to a value.

BooleanExpression
like(pattern: Expression)

Creates an expression that performs a case-sensitive wildcard string comparison.

BooleanExpression
like(pattern: String)

Creates an expression that performs a case-sensitive wildcard string comparison.

Expression
ln()

Creates an expression that returns the natural logarithm of this numeric expression.

Expression

Creates an expression that returns the base-10 logarithm of this numeric expression.

Expression
logicalMaximum(vararg others: Any)

Creates an expression that returns the largest value between multiple input expressions or literal values.

Expression
logicalMaximum(vararg others: Expression)

Creates an expression that returns the largest value between multiple input expressions or literal values.

Expression
logicalMinimum(vararg others: Any)

Creates an expression that returns the smallest value between multiple input expressions or literal values.

Expression
logicalMinimum(vararg others: Expression)

Creates an expression that returns the smallest value between multiple input expressions or literal values.

Expression
mapGet(key: String)

Accesses a map (object) value using the provided key.

Expression
mapGet(keyExpression: Expression)

Accesses a map (object) value using the provided keyExpression.

Expression
mapMerge(mapExpr: Expression, vararg otherMaps: Expression)

Creates an expression that merges multiple maps into a single map.

Expression

Creates an expression that removes a key from this map expression.

Expression
mapRemove(keyExpression: Expression)

Creates an expression that removes a key from this map expression.

AggregateFunction

Creates an aggregation that finds the maximum value of this expression across multiple stage inputs.

AggregateFunction

Creates an aggregation that finds the minimum value of this expression across multiple stage inputs.

Expression
mod(divisor: Expression)

Creates an expression that calculates the modulo (remainder) of dividing this numeric expressions by another numeric expression.

Expression
mod(divisor: Number)

Creates an expression that calculates the modulo (remainder) of dividing this numeric expressions by a constant.

Expression

Creates an expression that multiplies this numeric expression with another numeric expression.

Expression
multiply(second: Number)

Creates an expression that multiplies this numeric expression with a constant.

BooleanExpression

Creates an expression that checks if this expressions is not equal to the other expression.

BooleanExpression
notEqual(value: Any)

Creates an expression that checks if this expression is not equal to a value.

BooleanExpression
notEqualAny(arrayExpression: Expression)

Creates an expression that checks if this expression, when evaluated, is not equal to all the elements of arrayExpression.

BooleanExpression
notEqualAny(values: List<Any>)

Creates an expression that checks if this expression, when evaluated, is not equal to all the provided values.

Expression
pow(exponent: Expression)

Creates an expression that returns this numeric expression raised to the power of the exponent.

Expression
pow(exponent: Number)

Creates an expression that returns this numeric expression raised to the power of the exponent.

BooleanExpression

Creates an expression that checks if this string expression contains a specified regular expression as a substring.

BooleanExpression

Creates an expression that checks if this string expression contains a specified regular expression as a substring.

BooleanExpression

Creates an expression that checks if this string expression matches a specified regular expression.

BooleanExpression
regexMatch(pattern: String)

Creates an expression that checks if this string expression matches a specified regular expression.

Expression

Creates an expression that reverses this string expression.

Expression

Creates an expression that rounds this numeric expression to nearest integer.

Expression

Creates an expression that rounds off this numeric expression to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative.

Expression
roundToPrecision(decimalPlace: Int)

Creates an expression that rounds off this numeric expression to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative.

Expression
split(delimiter: Blob)

Creates an expression that splits this blob expression by a blob delimiter.

Expression
split(delimiter: Expression)

Creates an expression that splits this string or blob expression by a delimiter.

Expression
split(delimiter: String)

Creates an expression that splits this string or blob expression by a string delimiter.

Expression

Creates an expression that returns the square root of this numeric expression.

BooleanExpression

Creates an expression that checks if this string expression starts with a given prefix.

BooleanExpression
startsWith(prefix: String)

Creates an expression that checks if this string expression starts with a given prefix.

Expression
stringConcat(vararg stringExpressions: Expression)

Creates an expression that concatenates string expressions together.

Expression
stringConcat(vararg strings: Any)

Creates an expression that concatenates string expressions and string constants together.

Expression
stringConcat(vararg strings: String)

Creates an expression that concatenates this string expression with string constants.

BooleanExpression

Creates an expression that checks if this string expression contains a specified substring.

BooleanExpression
stringContains(substring: String)

Creates an expression that checks if this string expression contains a specified substring.

Expression

Creates an expression that performs a reverse operation on this string expression.

Expression
substring(start: Expression, length: Expression)

Creates an expression that returns a substring of the given string.

Expression
substring(start: Int, length: Int)

Creates an expression that returns a substring of the given string.

Expression
subtract(subtrahend: Expression)

Creates an expression that subtracts a constant from this numeric expression.

Expression
subtract(subtrahend: Number)

Creates an expression that subtracts a numeric expressions from this numeric expression.

AggregateFunction
sum()

Creates an aggregation that calculates the sum of this numeric expression across multiple stage inputs.

Expression

Creates an expression that adds a specified amount of time to this timestamp expression.

Expression
timestampAdd(unit: String, amount: Long)

Creates an expression that adds a specified amount of time to this timestamp expression.

Expression

Creates an expression that subtracts a specified amount of time to this timestamp expression.

Expression
timestampSubtract(unit: String, amount: Long)

Creates an expression that subtracts a specified amount of time to this timestamp expression.

Expression

Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression

Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression

Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

Expression

Creates an expression that truncates this timestamp expression to a specified granularity.

Expression
timestampTruncate(granularity: String)

Creates an expression that truncates this timestamp expression to a specified granularity.

Expression

Creates an expression that converts this string expression to lowercase.

Expression

Creates an expression that converts this string expression to uppercase.

Expression

Creates an expression that removes leading and trailing whitespace from this string expression.

Expression
trimValue(valueToTrim: Expression)

Creates an expression that removes leading and trailing value from this expression.

Expression
trimValue(valueToTrim: String)

Creates an expression that removes leading and trailing characters from this string expression.

Expression

Creates an expression that returns a string indicating the type of the value this expression evaluates to.

Expression

Creates an expression that interprets this expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Creates an expression that interprets this expression as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Creates an expression that interprets this expression as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

Expression

Creates an expression that calculates the length (dimension) of a Firestore Vector.

Public companion functions

abs

fun abs(numericExpr: Expression): Expression

Creates an expression that returns the absolute value of numericExpr.

// Get the absolute value of the 'change' field.
abs(field("change"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the absolute value operation.

abs

fun abs(numericField: String): Expression

Creates an expression that returns the absolute value of numericField.

// Get the absolute value of the 'change' field.
abs("change")
Parameters
numericField: String

Name of field that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the absolute value operation.

add

fun add(first: Expression, second: Expression): Expression

Creates an expression that adds numeric expressions.

// Add the value of the 'quantity' field and the 'reserve' field.
add(field("quantity"), field("reserve"))
Parameters
first: Expression

Numeric expression to add.

second: Expression

Numeric expression to add.

Returns
Expression

A new Expression representing the addition operation.

add

fun add(first: Expression, second: Number): Expression

Creates an expression that adds numeric expressions with a constant.

// Add 5 to the value of the 'quantity' field.
add(field("quantity"), 5)
Parameters
first: Expression

Numeric expression to add.

second: Number

Constant to add.

Returns
Expression

A new Expression representing the addition operation.

add

fun add(numericFieldName: String, second: Expression): Expression

Creates an expression that adds a numeric field with a numeric expression.

// Add the value of the 'quantity' field and the 'reserve' field.
add("quantity", field("reserve"))
Parameters
numericFieldName: String

Numeric field to add.

second: Expression

Numeric expression to add to field value.

Returns
Expression

A new Expression representing the addition operation.

add

fun add(numericFieldName: String, second: Number): Expression

Creates an expression that adds a numeric field with constant.

// Add 5 to the value of the 'quantity' field.
add("quantity", 5)
Parameters
numericFieldName: String

Numeric field to add.

second: Number

Constant to add.

Returns
Expression

A new Expression representing the addition operation.

and

fun and(condition: BooleanExpression, vararg conditions: BooleanExpression): BooleanExpression

Creates an expression that performs a logical 'AND' operation.

// Check if 'status' is "new" and 'priority' is greater than 1
and(field("status").equal("new"), field("priority").greaterThan(1))
Parameters
condition: BooleanExpression

The first BooleanExpression.

vararg conditions: BooleanExpression

Additional BooleanExpressions.

Returns
BooleanExpression

A new BooleanExpression representing the logical 'AND' operation.

array

fun array(elements: List<Any?>): Expression

Creates an expression that creates a Firestore array value from an input array.

Parameters
elements: List<Any?>

The input array to evaluate in the expression.

Returns
Expression

A new Expression representing the array function.

array

fun array(vararg elements: Any?): Expression

Creates an expression that creates a Firestore array value from an input array.

// Create an array of numbers
array(1, 2, 3)

// Create an array containing a field value and a constant
array(field("quantity"), 10)
Parameters
vararg elements: Any?

The input array to evaluate in the expression.

Returns
Expression

A new Expression representing the array function.

arrayConcat

fun arrayConcat(
    firstArray: Expression,
    secondArray: Any,
    vararg otherArrays: Any
): Expression

Creates an expression that concatenates an array with other arrays.

// Combine the 'items' array with another array field.
arrayConcat(field("items"), field("otherItems"))
Parameters
firstArray: Expression

The first array expression to concatenate to.

secondArray: Any

An array expression or array literal to concatenate.

vararg otherArrays: Any

Optional additional array expressions or array literals to concatenate.

Returns
Expression

A new Expression representing the arrayConcat operation.

arrayConcat

fun arrayConcat(
    firstArray: Expression,
    secondArray: Expression,
    vararg otherArrays: Any
): Expression

Creates an expression that concatenates an array with other arrays.

// Combine the 'items' array with another array field.
arrayConcat(field("items"), field("otherItems"))
Parameters
firstArray: Expression

The first array expression to concatenate to.

secondArray: Expression

An expression that evaluates to array to concatenate.

vararg otherArrays: Any

Optional additional array expressions or array literals to concatenate.

Returns
Expression

A new Expression representing the arrayConcat operation.

arrayConcat

fun arrayConcat(
    firstArrayField: String,
    secondArray: Any,
    vararg otherArrays: Any
): Expression

Creates an expression that concatenates a field's array value with other arrays.

// Combine the 'items' array with a literal array.
arrayConcat("items", listOf("a", "b"))
Parameters
firstArrayField: String

The name of field that contains first array to concatenate to.

secondArray: Any

An array expression or array literal to concatenate.

vararg otherArrays: Any

Optional additional array expressions or array literals to concatenate.

Returns
Expression

A new Expression representing the arrayConcat operation.

arrayConcat

fun arrayConcat(
    firstArrayField: String,
    secondArray: Expression,
    vararg otherArrays: Any
): Expression

Creates an expression that concatenates a field's array value with other arrays.

// Combine the 'items' array with another array field.
arrayConcat("items", field("otherItems"))
Parameters
firstArrayField: String

The name of field that contains first array to concatenate to.

secondArray: Expression

An expression that evaluates to array to concatenate.

vararg otherArrays: Any

Optional additional array expressions or array literals to concatenate.

Returns
Expression

A new Expression representing the arrayConcat operation.

arrayContains

fun arrayContains(array: Expression, element: Any): BooleanExpression

Creates an expression that checks if the array contains a specific element.

// Check if the 'sizes' array contains the value from the 'selectedSize' field
arrayContains(field("sizes"), field("selectedSize"))

// Check if the 'colors' array contains "red"
arrayContains(field("colors"), "red")
Parameters
array: Expression

The array expression to check.

element: Any

The element to search for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContains operation.

arrayContains

fun arrayContains(array: Expression, element: Expression): BooleanExpression

Creates an expression that checks if the array contains a specific element.

Parameters
array: Expression

The array expression to check.

element: Expression

The element to search for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContains operation.

arrayContains

fun arrayContains(arrayFieldName: String, element: Any): BooleanExpression

Creates an expression that checks if the array field contains a specific element.

// Check if the 'colors' array contains "red"
arrayContains("colors", "red")
Parameters
arrayFieldName: String

The name of field that contains array to check.

element: Any

The element to search for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContains operation.

arrayContains

fun arrayContains(arrayFieldName: String, element: Expression): BooleanExpression

Creates an expression that checks if the array field contains a specific element.

// Check if the 'sizes' array contains the value from the 'selectedSize' field
arrayContains("sizes", field("selectedSize"))
Parameters
arrayFieldName: String

The name of field that contains array to check.

element: Expression

The element to search for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContains operation.

arrayContainsAll

fun arrayContainsAll(array: Expression, arrayExpression: Expression): BooleanExpression

Creates an expression that checks if array contains all elements of arrayExpression.

// Check if the 'tags' array contains both of the values from field "tag1" and the literal value "tag2"
arrayContainsAll(field("tags"), array(field("tag1"), "tag2"))
Parameters
array: Expression

The array expression to check.

arrayExpression: Expression

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAll operation.

arrayContainsAll

fun arrayContainsAll(array: Expression, values: List<Any>): BooleanExpression

Creates an expression that checks if array contains all the specified values.

// Check if the 'tags' array contains both the value in field "tag1" and the literal value "tag2"
arrayContainsAll(field("tags"), listOf(field("tag1"), "tag2"))
Parameters
array: Expression

The array expression to check.

values: List<Any>

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAll operation.

arrayContainsAll

fun arrayContainsAll(arrayFieldName: String, arrayExpression: Expression): BooleanExpression

Creates an expression that checks if array field contains all elements of arrayExpression.

// Check if the 'permissions' array contains all the required permissions
arrayContainsAll("permissions", field("requiredPermissions"))
Parameters
arrayFieldName: String

The name of field that contains array to check.

arrayExpression: Expression

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAll operation.

arrayContainsAll

fun arrayContainsAll(arrayFieldName: String, values: List<Any>): BooleanExpression

Creates an expression that checks if array field contains all the specified values.

// Check if the 'tags' array contains both "internal" and "public"
arrayContainsAll("tags", listOf("internal", "public"))
Parameters
arrayFieldName: String

The name of field that contains array to check.

values: List<Any>

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAll operation.

arrayContainsAny

fun arrayContainsAny(array: Expression, arrayExpression: Expression): BooleanExpression

Creates an expression that checks if array contains any elements of arrayExpression.

// Check if the 'groups' array contains either the value from the 'userGroup' field
// or the value "guest"
arrayContainsAny(field("groups"), array(field("userGroup"), "guest"))
Parameters
array: Expression

The array expression to check.

arrayExpression: Expression

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAny operation.

arrayContainsAny

fun arrayContainsAny(array: Expression, values: List<Any>): BooleanExpression

Creates an expression that checks if array contains any of the specified values.

// Check if the 'categories' array contains either values from field "cate1" or "cate2"
arrayContainsAny(field("categories"), listOf(field("cate1"), field("cate2")))
Parameters
array: Expression

The array expression to check.

values: List<Any>

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAny operation.

arrayContainsAny

fun arrayContainsAny(arrayFieldName: String, arrayExpression: Expression): BooleanExpression

Creates an expression that checks if array field contains any elements of arrayExpression.

// Check if the 'userGroups' array contains any of the 'targetGroups'
arrayContainsAny("userGroups", field("targetGroups"))
Parameters
arrayFieldName: String

The name of field that contains array to check.

arrayExpression: Expression

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAny operation.

arrayContainsAny

fun arrayContainsAny(arrayFieldName: String, values: List<Any>): BooleanExpression

Creates an expression that checks if array field contains any of the specified values.

// Check if the 'roles' array contains "admin" or "editor"
arrayContainsAny("roles", listOf("admin", "editor"))
Parameters
arrayFieldName: String

The name of field that contains array to check.

values: List<Any>

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAny operation.

arrayGet

fun arrayGet(array: Expression, offset: Expression): Expression

Creates an expression that indexes into an array from the beginning or end and return the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.

// Return the value in the tags field array at index specified by field 'favoriteTag'.
arrayGet(field("tags"), field("favoriteTag"))
Parameters
array: Expression

An Expression evaluating to an array.

offset: Expression

An Expression evaluating to the index of the element to return.

Returns
Expression

A new Expression representing the arrayOffset operation.

arrayGet

fun arrayGet(array: Expression, offset: Int): Expression

Creates an expression that indexes into an array from the beginning or end and return the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.

// Return the value in the 'tags' field array at index `1`.
arrayGet(field("tags"), 1)
Parameters
array: Expression

An Expression evaluating to an array.

offset: Int

The index of the element to return.

Returns
Expression

A new Expression representing the arrayOffset operation.

arrayGet

fun arrayGet(arrayFieldName: String, offset: Expression): Expression

Creates an expression that indexes into an array from the beginning or end and return the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.

// Return the value in the tags field array at index specified by field 'favoriteTag'.
arrayGet("tags", field("favoriteTag"))
Parameters
arrayFieldName: String

The name of an array field.

offset: Expression

An Expression evaluating to the index of the element to return.

Returns
Expression

A new Expression representing the arrayOffset operation.

arrayGet

fun arrayGet(arrayFieldName: String, offset: Int): Expression

Creates an expression that indexes into an array from the beginning or end and return the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.

// Return the value in the 'tags' field array at index `1`.
arrayGet("tags", 1)
Parameters
arrayFieldName: String

The name of an array field.

offset: Int

The index of the element to return.

Returns
Expression

A new Expression representing the arrayOffset operation.

arrayLength

fun arrayLength(array: Expression): Expression

Creates an expression that calculates the length of an array expression.

// Get the number of items in the 'cart' array
arrayLength(field("cart"))
Parameters
array: Expression

The array expression to calculate the length of.

Returns
Expression

A new Expression representing the length of the array.

arrayLength

fun arrayLength(arrayFieldName: String): Expression

Creates an expression that calculates the length of an array field.

// Get the number of items in the 'cart' array
arrayLength("cart")
Parameters
arrayFieldName: String

The name of the field containing an array to calculate the length of.

Returns
Expression

A new Expression representing the length of the array.

arrayReverse

fun arrayReverse(array: Expression): Expression

Reverses the order of elements in the array.

// Reverse the value of the 'myArray' field.
arrayReverse(field("myArray"))
Parameters
array: Expression

The array expression to reverse.

Returns
Expression

A new Expression representing the arrayReverse operation.

arrayReverse

fun arrayReverse(arrayFieldName: String): Expression

Reverses the order of elements in the array field.

// Reverse the value of the 'myArray' field.
arrayReverse("myArray")
Parameters
arrayFieldName: String

The name of field that contains the array to reverse.

Returns
Expression

A new Expression representing the arrayReverse operation.

arraySum

fun arraySum(array: Expression): Expression

Creates an expression that returns the sum of the elements in an array.

// Get the sum of elements in the 'scores' array.
arraySum(field("scores"))
Parameters
array: Expression

The array expression to sum.

Returns
Expression

A new Expression representing the sum of the array elements.

arraySum

fun arraySum(arrayFieldName: String): Expression

Creates an expression that returns the sum of the elements in an array field.

// Get the sum of elements in the 'scores' array.
arraySum("scores")
Parameters
arrayFieldName: String

The name of the field containing the array to sum.

Returns
Expression

A new Expression representing the sum of the array elements.

bitAnd

fun bitAnd(bits: Expression, bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise AND operation between an expression and a constant.

// Bitwise AND the value of the 'flags' field with a constant mask.
bitAnd(field("flags"), byteArrayOf(0b00001111))
Parameters
bits: Expression

An expression that returns bits when evaluated.

bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise AND operation.

bitAnd

fun bitAnd(bits: Expression, bitsOther: Expression): Expression

Creates an expression that applies a bitwise AND operation between two expressions.

// Bitwise AND the value of the 'flags' field with the value of the 'mask' field.
bitAnd(field("flags"), field("mask"))
Parameters
bits: Expression

An expression that returns bits when evaluated.

bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise AND operation.

bitAnd

fun bitAnd(bitsFieldName: String, bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise AND operation between an field and constant.

// Bitwise AND the value of the 'flags' field with a constant mask.
bitAnd("flags", byteArrayOf(0b00001111))
Parameters
bitsFieldName: String

Name of field that contains bits data.

bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise AND operation.

bitAnd

fun bitAnd(bitsFieldName: String, bitsOther: Expression): Expression

Creates an expression that applies a bitwise AND operation between an field and an expression.

// Bitwise AND the value of the 'flags' field with the value of the 'mask' field.
bitAnd("flags", field("mask"))
Parameters
bitsFieldName: String

Name of field that contains bits data.

bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise AND operation.

bitLeftShift

fun bitLeftShift(bits: Expression, number: Int): Expression

Creates an expression that applies a bitwise left shift operation between an expression and a constant.

// Left shift the value of the 'bits' field by 2.
bitLeftShift(field("bits"), 2)
Parameters
bits: Expression

An expression that returns bits when evaluated.

number: Int

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise left shift operation.

bitLeftShift

fun bitLeftShift(bits: Expression, numberExpr: Expression): Expression

Creates an expression that applies a bitwise left shift operation between two expressions.

// Left shift the value of the 'bits' field by the value of the 'shift' field.
bitLeftShift(field("bits"), field("shift"))
Parameters
bits: Expression

An expression that returns bits when evaluated.

numberExpr: Expression

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise left shift operation.

bitLeftShift

fun bitLeftShift(bitsFieldName: String, number: Int): Expression

Creates an expression that applies a bitwise left shift operation between a field and a constant.

// Left shift the value of the 'bits' field by 2.
bitLeftShift("bits", 2)
Parameters
bitsFieldName: String

Name of field that contains bits data.

number: Int

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise left shift operation.

bitLeftShift

fun bitLeftShift(bitsFieldName: String, numberExpr: Expression): Expression

Creates an expression that applies a bitwise left shift operation between a field and an expression.

// Left shift the value of the 'bits' field by the value of the 'shift' field.
bitLeftShift("bits", field("shift"))
Parameters
bitsFieldName: String

Name of field that contains bits data.

numberExpr: Expression

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise left shift operation.

bitNot

fun bitNot(bits: Expression): Expression

Creates an expression that applies a bitwise NOT operation to an expression.

// Bitwise NOT the value of the 'flags' field.
bitNot(field("flags"))
Parameters
bits: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise NOT operation.

bitNot

fun bitNot(bitsFieldName: String): Expression

Creates an expression that applies a bitwise NOT operation to a field.

// Bitwise NOT the value of the 'flags' field.
bitNot("flags")
Parameters
bitsFieldName: String

Name of field that contains bits data.

Returns
Expression

A new Expression representing the bitwise NOT operation.

bitOr

fun bitOr(bits: Expression, bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise OR operation between an expression and a constant.

// Bitwise OR the value of the 'flags' field with a constant mask.
bitOr(field("flags"), byteArrayOf(0b00001111))
Parameters
bits: Expression

An expression that returns bits when evaluated.

bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise OR operation.

bitOr

fun bitOr(bits: Expression, bitsOther: Expression): Expression

Creates an expression that applies a bitwise OR operation between two expressions.

// Bitwise OR the value of the 'flags' field with the value of the 'mask' field.
bitOr(field("flags"), field("mask"))
Parameters
bits: Expression

An expression that returns bits when evaluated.

bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise OR operation.

bitOr

fun bitOr(bitsFieldName: String, bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise OR operation between an field and constant.

// Bitwise OR the value of the 'flags' field with a constant mask.
bitOr("flags", byteArrayOf(0b00001111))
Parameters
bitsFieldName: String

Name of field that contains bits data.

bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise OR operation.

bitOr

fun bitOr(bitsFieldName: String, bitsOther: Expression): Expression

Creates an expression that applies a bitwise OR operation between an field and an expression.

// Bitwise OR the value of the 'flags' field with the value of the 'mask' field.
bitOr("flags", field("mask"))
Parameters
bitsFieldName: String

Name of field that contains bits data.

bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise OR operation.

bitRightShift

fun bitRightShift(bits: Expression, number: Int): Expression

Creates an expression that applies a bitwise right shift operation between an expression and a constant.

// Right shift the value of the 'bits' field by 2.
bitRightShift(field("bits"), 2)
Parameters
bits: Expression

An expression that returns bits when evaluated.

number: Int

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise right shift operation.

bitRightShift

fun bitRightShift(bits: Expression, numberExpr: Expression): Expression

Creates an expression that applies a bitwise right shift operation between two expressions.

// Right shift the value of the 'bits' field by the value of the 'shift' field.
bitRightShift(field("bits"), field("shift"))
Parameters
bits: Expression

An expression that returns bits when evaluated.

numberExpr: Expression

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise right shift operation.

bitRightShift

fun bitRightShift(bitsFieldName: String, number: Int): Expression

Creates an expression that applies a bitwise right shift operation between a field and a constant.

// Right shift the value of the 'bits' field by 2.
bitRightShift("bits", 2)
Parameters
bitsFieldName: String

Name of field that contains bits data.

number: Int

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise right shift operation.

bitRightShift

fun bitRightShift(bitsFieldName: String, numberExpr: Expression): Expression

Creates an expression that applies a bitwise right shift operation between a field and an expression.

// Right shift the value of the 'bits' field by the value of the 'shift' field.
bitRightShift("bits", field("shift"))
Parameters
bitsFieldName: String

Name of field that contains bits data.

numberExpr: Expression

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise right shift operation.

bitXor

fun bitXor(bits: Expression, bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise XOR operation between an expression and a constant.

// Bitwise XOR the value of the 'flags' field with a constant mask.
bitXor(field("flags"), byteArrayOf(0b00001111))
Parameters
bits: Expression

An expression that returns bits when evaluated.

bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise XOR operation.

bitXor

fun bitXor(bits: Expression, bitsOther: Expression): Expression

Creates an expression that applies a bitwise XOR operation between two expressions.

// Bitwise XOR the value of the 'flags' field with the value of the 'mask' field.
bitXor(field("flags"), field("mask"))
Parameters
bits: Expression

An expression that returns bits when evaluated.

bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise XOR operation.

bitXor

fun bitXor(bitsFieldName: String, bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise XOR operation between an field and constant.

// Bitwise XOR the value of the 'flags' field with a constant mask.
bitXor("flags", byteArrayOf(0b00001111))
Parameters
bitsFieldName: String

Name of field that contains bits data.

bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise XOR operation.

bitXor

fun bitXor(bitsFieldName: String, bitsOther: Expression): Expression

Creates an expression that applies a bitwise XOR operation between an field and an expression.

// Bitwise XOR the value of the 'flags' field with the value of the 'mask' field.
bitXor("flags", field("mask"))
Parameters
bitsFieldName: String

Name of field that contains bits data.

bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise XOR operation.

byteLength

fun byteLength(fieldName: String): Expression

Creates an expression that calculates the length of a string represented by a field in UTF-8 bytes, or just the length of a Blob.

// Calculate the length of the 'myString' field in bytes.
byteLength("myString")
Parameters
fieldName: String

The name of the field containing the string.

Returns
Expression

A new Expression representing the length of the string in bytes.

byteLength

fun byteLength(value: Expression): Expression

Creates an expression that calculates the length of a string in UTF-8 bytes, or just the length of a Blob.

// Calculate the length of the 'myString' field in bytes.
byteLength("myString")
Parameters
value: Expression

The expression representing the string.

Returns
Expression

A new Expression representing the length of the string in bytes.

ceil

fun ceil(numericExpr: Expression): Expression

Creates an expression that returns the smallest integer that isn't less than numericExpr.

// Compute the ceiling of the 'price' field.
ceil(field("price"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

Returns
Expression

A new Expression representing an integer result from the ceil operation.

ceil

fun ceil(numericField: String): Expression

Creates an expression that returns the smallest integer that isn't less than numericField.

// Compute the ceiling of the 'price' field.
ceil("price")
Parameters
numericField: String

Name of field that returns number when evaluated.

Returns
Expression

A new Expression representing an integer result from the ceil operation.

charLength

fun charLength(expr: Expression): Expression

Creates an expression that calculates the character length of a string expression in UTF8.

// Get the character length of the 'name' field in UTF-8.
charLength("name")
Parameters
expr: Expression

The expression representing the string.

Returns
Expression

A new Expression representing the charLength operation.

charLength

fun charLength(fieldName: String): Expression

Creates an expression that calculates the character length of a string field in UTF8.

// Get the character length of the 'name' field in UTF-8.
charLength("name")
Parameters
fieldName: String

The name of the field containing the string.

Returns
Expression

A new Expression representing the charLength operation.

collectionId

fun collectionId(path: Expression): Expression

Creates an expression that returns the collection ID from a path.

// Get the collection ID from the 'path' field
collectionId(field("path"))
Parameters
path: Expression

An expression the evaluates to a path.

Returns
Expression

A new Expression representing the collectionId operation.

collectionId

fun collectionId(pathField: String): Expression

Creates an expression that returns the collection ID from a path.

// Get the collection ID from a path field
collectionId("pathField")
Parameters
pathField: String

The string representation of the path.

Returns
Expression

A new Expression representing the collectionId operation.

concat

fun concat(first: Expression, second: Any, vararg others: Any): Expression

Creates an expression that concatenates strings, arrays, or blobs. Types cannot be mixed.

// Concatenate a field with a literal string.
concat(field("firstName"), "Doe")
Parameters
first: Expression

The first expression to concatenate.

second: Any

The second value to concatenate.

vararg others: Any

Additional values to concatenate.

Returns
Expression

A new Expression representing the concatenation.

concat

fun concat(first: Expression, second: Expression, vararg others: Any): Expression

Creates an expression that concatenates strings, arrays, or blobs. Types cannot be mixed.

// Concatenate the 'firstName' and 'lastName' fields with a space in between.
concat(field("firstName"), " ", field("lastName"))
Parameters
first: Expression

The first expression to concatenate.

second: Expression

The second expression to concatenate.

vararg others: Any

Additional expressions to concatenate.

Returns
Expression

A new Expression representing the concatenation.

concat

fun concat(first: String, second: Any, vararg others: Any): Expression

Creates an expression that concatenates strings, arrays, or blobs. Types cannot be mixed.

// Concatenate a field name with a literal string.
concat("firstName", "Doe")
Parameters
first: String

The name of the field containing the first value to concatenate.

second: Any

The second value to concatenate.

vararg others: Any

Additional values to concatenate.

Returns
Expression

A new Expression representing the concatenation.

concat

fun concat(first: String, second: Expression, vararg others: Any): Expression

Creates an expression that concatenates strings, arrays, or blobs. Types cannot be mixed.

// Concatenate a field name with an expression.
concat("firstName", field("lastName"))
Parameters
first: String

The name of the field containing the first value to concatenate.

second: Expression

The second expression to concatenate.

vararg others: Any

Additional expressions to concatenate.

Returns
Expression

A new Expression representing the concatenation.

conditional

fun conditional(
    condition: BooleanExpression,
    thenExpr: Expression,
    elseExpr: Expression
): Expression

Creates a conditional expression that evaluates to a thenExpr expression if a condition is true or an elseExpr expression if the condition is false.

Parameters
condition: BooleanExpression

The condition to evaluate.

thenExpr: Expression

The expression to evaluate if the condition is true.

elseExpr: Expression

The expression to evaluate if the condition is false.

Returns
Expression

A new Expression representing the conditional operation.

conditional

fun conditional(condition: BooleanExpression, thenValue: Any, elseValue: Any): Expression

Creates a conditional expression that evaluates to a thenValue if a condition is true or an elseValue if the condition is false.

// If the 'quantity' field is greater than 10, return "High", otherwise return "Low"
conditional(field("quantity").greaterThan(10), "High", "Low")
Parameters
condition: BooleanExpression

The condition to evaluate.

thenValue: Any

Value if the condition is true.

elseValue: Any

Value if the condition is false.

Returns
Expression

A new Expression representing the conditional operation.

constant

fun constant(ref: DocumentReference): Expression

Create a constant for a DocumentReference value.

// val firestore = FirebaseFirestore.getInstance()
// val docRef = firestore.collection("cities").document("SF")
// constant(docRef)
Parameters
ref: DocumentReference

The DocumentReference value.

Returns
Expression

A new Expression constant instance.

constant

fun constant(value: Blob): Expression

Create a constant for a Blob value.

// Create a constant with a Blob
constant(Blob.fromBytes(byteArrayOf(0x48, 0x65, 0x6c, 0x6c, 0x6f))) // "Hello"
Parameters
value: Blob

The Blob value.

Returns
Expression

A new Expression constant instance.

constant

fun constant(value: Boolean): BooleanExpression

Create a constant for a Boolean value.

// Create a constant with the value true
constant(true)
Parameters
value: Boolean

The Boolean value.

Returns
BooleanExpression

A new BooleanExpression constant instance.

constant

fun constant(value: ByteArray): Expression

Create a constant for a bytes value.

// Create a constant with a byte array
constant(byteArrayOf(0x48, 0x65, 0x6c, 0x6c, 0x6f)) // "Hello"
Parameters
value: ByteArray

The bytes value.

Returns
Expression

A new Expression constant instance.

constant

fun constant(value: Date): Expression

Create a constant for a Date value.

// Create a constant with the current date
constant(Date())
Parameters
value: Date

The Date value.

Returns
Expression

A new Expression constant instance.

constant

fun constant(value: GeoPoint): Expression

Create a constant for a GeoPoint value.

// Create a constant with a GeoPoint
constant(GeoPoint(37.7749, -122.4194))
Parameters
value: GeoPoint

The GeoPoint value.

Returns
Expression

A new Expression constant instance.

constant

fun constant(value: Number): Expression

Create a constant for a Number value.

// Create a constant with the value 123
constant(123)
Parameters
value: Number

The Number value.

Returns
Expression

A new Expression constant instance.

constant

fun constant(value: String): Expression

Create a constant for a String value.

// Create a constant with the value "hello"
constant("hello")
Parameters
value: String

The String value.

Returns
Expression

A new Expression constant instance.

constant

fun constant(value: Timestamp): Expression

Create a constant for a Timestamp value.

// Create a constant with the current timestamp
constant(Timestamp.now())
Parameters
value: Timestamp

The Timestamp value.

Returns
Expression

A new Expression constant instance.

constant

fun constant(value: VectorValue): Expression

Create a constant for a VectorValue value.

// Create a constant with a VectorValue
constant(VectorValue(listOf(1.0, 2.0, 3.0)))
Parameters
value: VectorValue

The VectorValue value.

Returns
Expression

A new Expression constant instance.

cosineDistance

fun cosineDistance(vector1: Expression, vector2: DoubleArray): Expression

Calculates the Cosine distance between vector expression and a vector literal.

// Calculate the Cosine distance between the 'location' field and a target location
cosineDistance(field("location"), doubleArrayOf(37.7749, -122.4194))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

cosineDistance

fun cosineDistance(vector1: Expression, vector2: Expression): Expression

Calculates the Cosine distance between two vector expressions.

// Calculate the cosine distance between the 'userVector' field and the 'itemVector' field
cosineDistance(field("userVector"), field("itemVector"))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

cosineDistance

fun cosineDistance(vector1: Expression, vector2: VectorValue): Expression

Calculates the Cosine distance between vector expression and a vector literal.

// Calculate the Cosine distance between the 'location' field and a target location
cosineDistance(field("location"), VectorValue.from(listOf(37.7749, -122.4194)))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

cosineDistance

fun cosineDistance(vectorFieldName: String, vector: DoubleArray): Expression

Calculates the Cosine distance between a vector field and a vector literal.

// Calculate the Cosine distance between the 'location' field and a target location
cosineDistance("location", doubleArrayOf(37.7749, -122.4194))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

cosineDistance

fun cosineDistance(vectorFieldName: String, vector: Expression): Expression

Calculates the Cosine distance between a vector field and a vector expression.

// Calculate the cosine distance between the 'userVector' field and the 'itemVector' field
cosineDistance("userVector", field("itemVector"))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

cosineDistance

fun cosineDistance(vectorFieldName: String, vector: VectorValue): Expression

Calculates the Cosine distance between a vector field and a vector literal.

// Calculate the Cosine distance between the 'location' field and a target location
cosineDistance("location", VectorValue.from(listOf(37.7749, -122.4194)))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

currentTimestamp

fun currentTimestamp(): Expression

Creates an expression that evaluates to the current server timestamp.

// Get the current server timestamp
currentTimestamp()
Returns
Expression

A new Expression representing the current server timestamp.

divide

fun divide(dividend: Expression, divisor: Expression): Expression

Creates an expression that divides two numeric expressions.

// Divide the 'total' field by the 'count' field
divide(field("total"), field("count"))
Parameters
dividend: Expression

The numeric expression to be divided.

divisor: Expression

The numeric expression to divide by.

Returns
Expression

A new Expression representing the division operation.

divide

fun divide(dividend: Expression, divisor: Number): Expression

Creates an expression that divides a numeric expression by a constant.

// Divide the 'value' field by 10
divide(field("value"), 10)
Parameters
dividend: Expression

The numeric expression to be divided.

divisor: Number

The constant to divide by.

Returns
Expression

A new Expression representing the division operation.

divide

fun divide(dividendFieldName: String, divisor: Expression): Expression

Creates an expression that divides numeric field by a numeric expression.

// Divide the 'total' field by the 'count' field.
divide("total", field("count"))
Parameters
dividendFieldName: String

The numeric field name to be divided.

divisor: Expression

The numeric expression to divide by.

Returns
Expression

A new Expression representing the divide operation.

divide

fun divide(dividendFieldName: String, divisor: Number): Expression

Creates an expression that divides a numeric field by a constant.

// Divide the 'total' field by 2.
divide("total", 2)
Parameters
dividendFieldName: String

The numeric field name to be divided.

divisor: Number

The constant to divide by.

Returns
Expression

A new Expression representing the divide operation.

documentId

fun documentId(docRef: DocumentReference): Expression

Creates an expression that returns the document ID from a DocumentReference.

Parameters
docRef: DocumentReference

The DocumentReference.

Returns
Expression

A new Expression representing the documentId operation.

documentId

fun documentId(documentPath: Expression): Expression

Creates an expression that returns the document ID from a path.

// Get the document ID from the 'path' field
documentId(field("path"))
Parameters
documentPath: Expression

An expression the evaluates to document path.

Returns
Expression

A new Expression representing the documentId operation.

documentId

fun documentId(documentPath: String): Expression

Creates an expression that returns the document ID from a path.

// Get the document ID from a path string
documentId("projects/p/databases/d/documents/c/d")
Parameters
documentPath: String

The string representation of the document path.

Returns
Expression

A new Expression representing the documentId operation.

dotProduct

fun dotProduct(vector1: Expression, vector2: DoubleArray): Expression

Calculates the dot product distance between vector expression and a vector literal.

// Calculate the dot product between the 'vector' field and a constant vector
dotProduct(field("vector"), doubleArrayOf(1.0, 2.0, 3.0))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

dotProduct

fun dotProduct(vector1: Expression, vector2: Expression): Expression

Calculates the dot product distance between two vector expressions.

// Calculate the dot product between the 'userVector' field and the 'itemVector' field
dotProduct(field("userVector"), field("itemVector"))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

dotProduct

fun dotProduct(vector1: Expression, vector2: VectorValue): Expression

Calculates the dot product distance between vector expression and a vector literal.

// Calculate the dot product between the 'vector' field and a constant vector
dotProduct(field("vector"), VectorValue.from(listOf(1.0, 2.0, 3.0)))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

dotProduct

fun dotProduct(vectorFieldName: String, vector: DoubleArray): Expression

Calculates the dot product distance between vector field and a vector literal.

// Calculate the dot product between the 'vector' field and a constant vector
dotProduct("vector", doubleArrayOf(1.0, 2.0, 3.0))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

dotProduct

fun dotProduct(vectorFieldName: String, vector: Expression): Expression

Calculates the dot product distance between a vector field and a vector expression.

// Calculate the dot product between the 'userVector' field and the 'itemVector' field
dotProduct("userVector", field("itemVector"))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

dotProduct

fun dotProduct(vectorFieldName: String, vector: VectorValue): Expression

Calculates the dot product distance between a vector field and a vector literal.

// Calculate the dot product between the 'vector' field and a constant vector
dotProduct("vector", VectorValue.from(listOf(1.0, 2.0, 3.0)))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

endsWith

fun endsWith(fieldName: String, suffix: Expression): BooleanExpression

Creates an expression that checks if a string expression ends with a given suffix.

// Check if the 'url' field ends with the value of the 'extension' field
endsWith("url", field("extension"))
Parameters
fieldName: String

The name of field that contains a string to check.

suffix: Expression

The suffix string expression to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'ends with' comparison.

endsWith

fun endsWith(fieldName: String, suffix: String): BooleanExpression

Creates an expression that checks if a string expression ends with a given suffix.

// Check if the 'filename' field ends with ".txt"
endsWith("filename", ".txt")
Parameters
fieldName: String

The name of field that contains a string to check.

suffix: String

The suffix string to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'ends with' comparison.

endsWith

fun endsWith(stringExpr: Expression, suffix: Expression): BooleanExpression

Creates an expression that checks if a string expression ends with a given suffix.

// Check if the 'url' field ends with the value of the 'extension' field
endsWith(field("url"), field("extension"))
Parameters
stringExpr: Expression

The expression to check.

suffix: Expression

The suffix string expression to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'ends with' comparison.

endsWith

fun endsWith(stringExpr: Expression, suffix: String): BooleanExpression

Creates an expression that checks if a string expression ends with a given suffix.

// Check if the 'filename' field ends with ".txt"
endsWith(field("filename"), ".txt")
Parameters
stringExpr: Expression

The expression to check.

suffix: String

The suffix string to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'ends with' comparison.

equal

fun equal(fieldName: String, expression: Expression): BooleanExpression

Creates an expression that checks if a field's value is equal to an expression.

// Check if the 'age' field is equal to the 'limit' field
equal("age", field("limit"))
Parameters
fieldName: String

The field name to compare.

expression: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the equality comparison.

equal

fun equal(fieldName: String, value: Any): BooleanExpression

Creates an expression that checks if a field's value is equal to another value.

// Check if the 'city' field is equal to string constant "London"
equal("city", "London")
Parameters
fieldName: String

The field name to compare.

value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the equality comparison.

equal

fun equal(left: Expression, right: Any): BooleanExpression

Creates an expression that checks if an expression is equal to a value.

// Check if the 'age' field is equal to 21
equal(field("age"), 21)
Parameters
left: Expression

The first expression to compare.

right: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the equality comparison.

equal

fun equal(left: Expression, right: Expression): BooleanExpression

Creates an expression that checks if two expressions are equal.

// Check if the 'age' field is equal to an expression
equal(field("age"), field("minAge").add(10))
Parameters
left: Expression

The first expression to compare.

right: Expression

The second expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the equality comparison.

equalAny

fun equalAny(expression: Expression, arrayExpression: Expression): BooleanExpression

Creates an expression that checks if an expression, when evaluated, is equal to any of the elements of arrayExpression.

// Check if the 'category' field is in the 'availableCategories' array field.
equalAny(field("category"), field("availableCategories"))
Parameters
expression: Expression

The expression whose results to compare.

arrayExpression: Expression

An expression that evaluates to an array, whose elements to check for equality to the input.

Returns
BooleanExpression

A new BooleanExpression representing the 'IN' comparison.

equalAny

fun equalAny(expression: Expression, values: List<Any>): BooleanExpression

Creates an expression that checks if an expression, when evaluated, is equal to any of the provided values.

// Check if the 'category' field is either "Electronics" or the value of the 'primaryType' field.
equalAny(field("category"), listOf("Electronics", field("primaryType")))
Parameters
expression: Expression

The expression whose results to compare.

values: List<Any>

The values to check against.

Returns
BooleanExpression

A new BooleanExpression representing the 'IN' comparison.

equalAny

fun equalAny(fieldName: String, arrayExpression: Expression): BooleanExpression

Creates an expression that checks if a field's value is equal to any of the elements of arrayExpression.

// Check if the 'category' field is in the 'availableCategories' array field.
equalAny("category", field("availableCategories"))
Parameters
fieldName: String

The field to compare.

arrayExpression: Expression

An expression that evaluates to an array, whose elements to check for equality to the input.

Returns
BooleanExpression

A new BooleanExpression representing the 'IN' comparison.

equalAny

fun equalAny(fieldName: String, values: List<Any>): BooleanExpression

Creates an expression that checks if a field's value is equal to any of the provided values .

// Check if the 'category' field is either "Electronics" or "Apparel".
equalAny("category", listOf("Electronics", "Apparel"))
Parameters
fieldName: String

The field to compare.

values: List<Any>

The values to check against.

Returns
BooleanExpression

A new BooleanExpression representing the 'IN' comparison.

euclideanDistance

fun euclideanDistance(vector1: Expression, vector2: DoubleArray): Expression

Calculates the Euclidean distance between vector expression and a vector literal.

// Calculate the Euclidean distance between the 'vector' field and a constant vector
euclideanDistance(field("vector"), doubleArrayOf(1.0, 2.0, 3.0))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

euclideanDistance

fun euclideanDistance(vector1: Expression, vector2: Expression): Expression

Calculates the Euclidean distance between two vector expressions.

// Calculate the Euclidean distance between the 'userVector' field and the 'itemVector' field
euclideanDistance(field("userVector"), field("itemVector"))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

euclideanDistance

fun euclideanDistance(vector1: Expression, vector2: VectorValue): Expression

Calculates the Euclidean distance between vector expression and a vector literal.

// Calculate the Euclidean distance between the 'vector' field and a constant vector
euclideanDistance(field("vector"), VectorValue.from(listOf(1.0, 2.0, 3.0)))
Parameters
vector1: Expression

The first vector (represented as an Expression) to compare against.

vector2: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

euclideanDistance

fun euclideanDistance(vectorFieldName: String, vector: DoubleArray): Expression

Calculates the Euclidean distance between a vector field and a vector literal.

// Calculate the Euclidean distance between the 'vector' field and a constant vector
euclideanDistance("vector", doubleArrayOf(1.0, 2.0, 3.0))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

euclideanDistance

fun euclideanDistance(vectorFieldName: String, vector: Expression): Expression

Calculates the Euclidean distance between a vector field and a vector expression.

// Calculate the Euclidean distance between the 'userVector' field and the 'itemVector' field
euclideanDistance("userVector", field("itemVector"))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

euclideanDistance

fun euclideanDistance(vectorFieldName: String, vector: VectorValue): Expression

Calculates the Euclidean distance between a vector field and a vector literal.

// Calculate the Euclidean distance between the 'vector' field and a constant vector
euclideanDistance("vector", VectorValue.from(listOf(1.0, 2.0, 3.0)))
Parameters
vectorFieldName: String

The name of the field containing the first vector.

vector: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

exists

fun exists(fieldName: String): BooleanExpression

Creates an expression that checks if a field exists.

Parameters
fieldName: String

The field name to check.

Returns
BooleanExpression

A new Expression representing the exists check.

exists

fun exists(value: Expression): BooleanExpression

Creates an expression that checks if a field exists.

Parameters
value: Expression

An expression evaluates to the name of the field to check.

Returns
BooleanExpression

A new Expression representing the exists check.

exp

fun exp(numericExpr: Expression): Expression

Creates an expression that returns Euler's number e raised to the power of numericExpr.

// Compute e to the power of the 'value' field.
exp(field("value"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the exponentiation.

exp

fun exp(numericField: String): Expression

Creates an expression that returns Euler's number e raised to the power of numericField.

// Compute e to the power of the 'value' field.
exp("value")
Parameters
numericField: String

Name of field that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the exponentiation.

field

fun field(fieldPath: FieldPath): Field

Creates a Field instance representing the field at the given path.

The path can be a simple field name (e.g., "name") or a dot-separated path to a nested field (e.g., "address.city").

// Get the 'address.city' field
field(FieldPath.of("address", "city"))
Parameters
fieldPath: FieldPath

The FieldPath to the field.

Returns
Field

A new Field instance representing the specified path.

field

fun field(name: String): Field

Creates a Field instance representing the field at the given path.

The path can be a simple field name (e.g., "name") or a dot-separated path to a nested field (e.g., "address.city").

Parameters
name: String

The path to the field.

Returns
Field

A new Field instance representing the specified path.

floor

fun floor(numericExpr: Expression): Expression

Creates an expression that returns the largest integer that is not greater than numericExpr

// Compute the floor of the 'price' field.
floor(field("price"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

Returns
Expression

A new Expression representing an integer result from the floor operation.

floor

fun floor(numericField: String): Expression

Creates an expression that returns the largest integer that is not greater than numericField.

// Compute the floor of the 'price' field.
floor("price")
Parameters
numericField: String

Name of field that returns number when evaluated.

Returns
Expression

A new Expression representing an integer result from the floor operation.

greaterThan

fun greaterThan(fieldName: String, expression: Expression): BooleanExpression

Creates an expression that checks if a field's value is greater than an expression.

// Check if the 'age' field is greater than the 'limit' field
greaterThan("age", field("limit"))
Parameters
fieldName: String

The field name to compare.

expression: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than comparison.

greaterThan

fun greaterThan(fieldName: String, value: Any): BooleanExpression

Creates an expression that checks if a field's value is greater than another value.

// Check if the 'price' field is greater than 100
greaterThan("price", 100)
Parameters
fieldName: String

The field name to compare.

value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than comparison.

greaterThan

fun greaterThan(left: Expression, right: Any): BooleanExpression

Creates an expression that checks if an expression is greater than a value.

// Check if the 'price' field is greater than 100
greaterThan(field("price"), 100)
Parameters
left: Expression

The first expression to compare.

right: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than comparison.

greaterThan

fun greaterThan(left: Expression, right: Expression): BooleanExpression

Creates an expression that checks if the first expression is greater than the second expression.

// Check if the 'age' field is greater than the 'limit' field
greaterThan(field("age"), field("limit"))
Parameters
left: Expression

The first expression to compare.

right: Expression

The second expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than comparison.

greaterThanOrEqual

fun greaterThanOrEqual(fieldName: String, expression: Expression): BooleanExpression

Creates an expression that checks if a field's value is greater than or equal to an expression.

// Check if the 'quantity' field is greater than or equal to field 'requirement' plus 1
greaterThanOrEqual("quantity", field("requirement").add(1))
Parameters
fieldName: String

The field name to compare.

expression: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than or equal to comparison.

greaterThanOrEqual

fun greaterThanOrEqual(fieldName: String, value: Any): BooleanExpression

Creates an expression that checks if a field's value is greater than or equal to another value.

// Check if the 'score' field is greater than or equal to 80
greaterThanOrEqual("score", 80)
Parameters
fieldName: String

The field name to compare.

value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than or equal to comparison.

greaterThanOrEqual

fun greaterThanOrEqual(left: Expression, right: Any): BooleanExpression

Creates an expression that checks if an expression is greater than or equal to a value.

// Check if the 'score' field is greater than or equal to 80
greaterThanOrEqual(field("score"), 80)
Parameters
left: Expression

The first expression to compare.

right: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than or equal to comparison.

greaterThanOrEqual

fun greaterThanOrEqual(left: Expression, right: Expression): BooleanExpression

Creates an expression that checks if the first expression is greater than or equal to the second expression.

// Check if the 'quantity' field is greater than or equal to field 'requirement' plus 1
greaterThanOrEqual(field("quantity"), field("requirement").add(1))
Parameters
left: Expression

The first expression to compare.

right: Expression

The second expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than or equal to comparison.

ifAbsent

fun ifAbsent(ifExpr: Expression, elseExpr: Expression): Expression

Creates an expression that returns the elseExpr argument if ifExpr is absent, else return the result of the ifExpr argument evaluation.

// Returns the value of the optional field 'optional_field', or returns 'default_value'
// if the field is absent.
ifAbsent(field("optional_field"), "default_value")
Parameters
ifExpr: Expression

The expression to check for absence.

elseExpr: Expression

The expression that will be evaluated and returned if ifExpr is absent.

Returns
Expression

A new Expression representing the ifAbsent operation.

ifAbsent

fun ifAbsent(ifExpr: Expression, elseValue: Any): Expression

Creates an expression that returns the elseValue argument if ifExpr is absent, else return the result of the ifExpr argument evaluation.

// Returns the value of the optional field 'optional_field', or returns 'default_value'
// if the field is absent.
ifAbsent(field("optional_field"), "default_value")
Parameters
ifExpr: Expression

The expression to check for absence.

elseValue: Any

The value that will be returned if ifExpr is absent.

Returns
Expression

A new Expression representing the ifAbsent operation.

ifAbsent

fun ifAbsent(ifFieldName: String, elseExpr: Expression): Expression

Creates an expression that returns the elseExpr argument if ifFieldName is absent, else return the value of the field.

// Returns the value of the optional field 'optional_field', or returns the value of
// 'default_field' if 'optional_field' is absent.
ifAbsent("optional_field", field("default_field"))
Parameters
ifFieldName: String

The field to check for absence.

elseExpr: Expression

The expression that will be evaluated and returned if ifFieldName is absent.

Returns
Expression

A new Expression representing the ifAbsent operation.

ifAbsent

fun ifAbsent(ifFieldName: String, elseValue: Any): Expression

Creates an expression that returns the elseValue argument if ifFieldName is absent, else return the value of the field.

// Returns the value of the optional field 'optional_field', or returns 'default_value'
// if the field is absent.
ifAbsent("optional_field", "default_value")
Parameters
ifFieldName: String

The field to check for absence.

elseValue: Any

The value that will be returned if ifFieldName is absent.

Returns
Expression

A new Expression representing the ifAbsent operation.

ifError

fun ifError(tryExpr: BooleanExpression, catchExpr: BooleanExpression): BooleanExpression

Creates an expression that returns the catchExpr argument if there is an error, else return the result of the tryExpr argument evaluation.

This overload will return BooleanExpression when both parameters are also BooleanExpression.

// Returns the result of the boolean expression, or false if it errors.
ifError(field("is_premium"), false)
Parameters
tryExpr: BooleanExpression

The try boolean expression.

catchExpr: BooleanExpression

The catch boolean expression that will be evaluated and returned if the tryExpr produces an error.

Returns
BooleanExpression

A new BooleanExpression representing the ifError operation.

ifError

fun ifError(tryExpr: Expression, catchExpr: Expression): Expression

Creates an expression that returns the catchExpr argument if there is an error, else return the result of the tryExpr argument evaluation.

// Returns the first item in the title field arrays, or returns
// the entire title field if the array is empty or the field is another type.
ifError(arrayGet(field("title"), 0), field("title"))
Parameters
tryExpr: Expression

The try expression.

catchExpr: Expression

The catch expression that will be evaluated and returned if the tryExpr produces an error.

Returns
Expression

A new Expression representing the ifError operation.

ifError

fun ifError(tryExpr: Expression, catchValue: Any): Expression

Creates an expression that returns the catchValue argument if there is an error, else return the result of the tryExpr argument evaluation.

// Returns the first item in the title field arrays, or returns "Default Title"
ifError(arrayGet(field("title"), 0), "Default Title")
Parameters
tryExpr: Expression

The try expression.

catchValue: Any

The value that will be returned if the tryExpr produces an error.

Returns
Expression

A new Expression representing the ifError operation.

isAbsent

fun isAbsent(fieldName: String): BooleanExpression

Creates an expression that returns true if a field is absent. Otherwise, returns false even if the field value is null.

// Check if the field `value` is absent.
isAbsent("value")
Parameters
fieldName: String

The field to check.

Returns
BooleanExpression

A new BooleanExpression representing the isAbsent operation.

isAbsent

fun isAbsent(value: Expression): BooleanExpression

Creates an expression that returns true if a value is absent. Otherwise, returns false even if the value is null.

// Check if the field `value` is absent.
isAbsent(field("value"))
Parameters
value: Expression

The expression to check.

Returns
BooleanExpression

A new BooleanExpression representing the isAbsent operation.

isError

fun isError(expr: Expression): BooleanExpression

Creates an expression that checks if a given expression produces an error.

// Check if the result of a calculation is an error
isError(arrayContains(field("title"), 1))
Parameters
expr: Expression

The expression to check.

Returns
BooleanExpression

A new BooleanExpression representing the isError check.

join

fun join(arrayExpression: Expression, delimiter: String): Expression

Creates an expression that joins the elements of an array into a string.

// Join the elements of the 'tags' field with a comma and space.
join(field("tags"), ", ")
Parameters
arrayExpression: Expression

The expression that evaluates to an array.

delimiter: String

The string to use as a delimiter.

Returns
Expression

A new Expression representing the join operation.

join

fun join(arrayExpression: Expression, delimiterExpression: Expression): Expression

Creates an expression that joins the elements of an array into a string.

// Join the elements of the 'tags' field with the delimiter from the 'separator' field.
join(field("tags"), field("separator"))
Parameters
arrayExpression: Expression

The expression that evaluates to an array.

delimiterExpression: Expression

The expression that evaluates to the delimiter string.

Returns
Expression

A new Expression representing the join operation.

join

fun join(arrayFieldName: String, delimiter: String): Expression

Creates an expression that joins the elements of an array field into a string.

// Join the elements of the 'tags' field with a comma and space.
join("tags", ", ")
Parameters
arrayFieldName: String

The name of the field containing the array.

delimiter: String

The string to use as a delimiter.

Returns
Expression

A new Expression representing the join operation.

join

fun join(arrayFieldName: String, delimiterExpression: Expression): Expression

Creates an expression that joins the elements of an array field into a string.

// Join the elements of the 'tags' field with the delimiter from the 'separator' field.
join("tags", field("separator"))
Parameters
arrayFieldName: String

The name of the field containing the array.

delimiterExpression: Expression

The expression that evaluates to the delimiter string.

Returns
Expression

A new Expression representing the join operation.

length

fun length(expr: Expression): Expression

Creates an expression that calculates the length of a string, array, map, vector, or blob expression.

// Get the length of the 'value' field where the value type can be any of a string, array, map, vector or blob.
length(field("value"))
Parameters
expr: Expression

The expression representing the string.

Returns
Expression

A new Expression representing the length operation.

length

fun length(fieldName: String): Expression

Creates an expression that calculates the length of a string, array, map, vector, or blob field.

// Get the length of the 'value' field where the value type can be any of a string, array, map, vector or blob.
charLength("value")
Parameters
fieldName: String

The name of the field containing the string.

Returns
Expression

A new Expression representing the length operation.

lessThan

fun lessThan(fieldName: String, expression: Expression): BooleanExpression

Creates an expression that checks if a field's value is less than an expression.

// Check if the 'age' field is less than 'limit'
lessThan("age", field("limit"))
Parameters
fieldName: String

The field name to compare.

expression: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than comparison.

lessThan

fun lessThan(fieldName: String, value: Any): BooleanExpression

Creates an expression that checks if a field's value is less than another value.

// Check if the 'price' field is less than 50
lessThan("price", 50)
Parameters
fieldName: String

The field name to compare.

value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than comparison.

lessThan

fun lessThan(left: Expression, right: Any): BooleanExpression

Creates an expression that checks if an expression is less than a value.

// Check if the 'price' field is less than 50
lessThan(field("price"), 50)
Parameters
left: Expression

The first expression to compare.

right: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than comparison.

lessThan

fun lessThan(left: Expression, right: Expression): BooleanExpression

Creates an expression that checks if the first expression is less than the second expression.

// Check if the 'age' field is less than 'limit'
lessThan(field("age"), field("limit"))
Parameters
left: Expression

The first expression to compare.

right: Expression

The second expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than comparison.

lessThanOrEqual

fun lessThanOrEqual(fieldName: String, expression: Expression): BooleanExpression

Creates an expression that checks if a field's value is less than or equal to an expression.

// Check if the 'quantity' field is less than or equal to 20
lessThanOrEqual("quantity", constant(20))
Parameters
fieldName: String

The field name to compare.

expression: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than or equal to comparison.

lessThanOrEqual

fun lessThanOrEqual(fieldName: String, value: Any): BooleanExpression

Creates an expression that checks if a field's value is less than or equal to another value.

// Check if the 'score' field is less than or equal to 70
lessThanOrEqual("score", 70)
Parameters
fieldName: String

The field name to compare.

value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than or equal to comparison.

lessThanOrEqual

fun lessThanOrEqual(left: Expression, right: Any): BooleanExpression

Creates an expression that checks if an expression is less than or equal to a value.

// Check if the 'score' field is less than or equal to 70
lessThanOrEqual(field("score"), 70)
Parameters
left: Expression

The first expression to compare.

right: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than or equal to comparison.

lessThanOrEqual

fun lessThanOrEqual(left: Expression, right: Expression): BooleanExpression

Creates an expression that checks if the first expression is less than or equal to the second expression.

// Check if the 'quantity' field is less than or equal to 20
lessThanOrEqual(field("quantity"), constant(20))
Parameters
left: Expression

The first expression to compare.

right: Expression

The second expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than or equal to comparison.

like

fun like(fieldName: String, pattern: Expression): BooleanExpression

Creates an expression that performs a case-sensitive wildcard string comparison against a field.

// Check if the 'title' field contains the string "guide"
like("title", "%guide%")
Parameters
fieldName: String

The name of the field containing the string.

pattern: Expression

The pattern to search for. You can use "%" as a wildcard character.

Returns
BooleanExpression

A new BooleanExpression representing the like comparison.

like

fun like(fieldName: String, pattern: String): BooleanExpression

Creates an expression that performs a case-sensitive wildcard string comparison against a field.

// Check if the 'title' field contains the string "guide"
like("title", "%guide%")
Parameters
fieldName: String

The name of the field containing the string.

pattern: String

The pattern to search for. You can use "%" as a wildcard character.

Returns
BooleanExpression

A new BooleanExpression representing the like comparison.

like

fun like(stringExpression: Expression, pattern: Expression): BooleanExpression

Creates an expression that performs a case-sensitive wildcard string comparison.

// Check if the 'title' field contains the string "guide"
like(field("title"), "%guide%")
Parameters
stringExpression: Expression

The expression representing the string to perform the comparison on.

pattern: Expression

The pattern to search for. You can use "%" as a wildcard character.

Returns
BooleanExpression

A new BooleanExpression representing the like operation.

like

fun like(stringExpression: Expression, pattern: String): BooleanExpression

Creates an expression that performs a case-sensitive wildcard string comparison.

// Check if the 'title' field contains the string "guide"
like(field("title"), "%guide%")
Parameters
stringExpression: Expression

The expression representing the string to perform the comparison on.

pattern: String

The pattern to search for. You can use "%" as a wildcard character.

Returns
BooleanExpression

A new BooleanExpression representing the like operation.

ln

fun ln(numericExpr: Expression): Expression

Creates an expression that returns the natural logarithm (base e) of numericExpr.

// Compute the natural logarithm of the 'value' field.
ln(field("value"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the natural logarithm.

ln

fun ln(numericField: String): Expression

Creates an expression that returns the natural logarithm (base e) of numericField.

// Compute the natural logarithm of the 'value' field.
ln("value")
Parameters
numericField: String

Name of field that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the natural logarithm.

log

fun log(numericExpr: Expression, base: Expression): Expression

Creates an expression that returns the logarithm of numericExpr with a given base.

// Compute the logarithm of the 'value' field with the base in the 'base' field.
log(field("value"), field("base"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

base: Expression

The base of the logarithm.

Returns
Expression

A new Expression representing a numeric result from the logarithm of numericExpr with a given base.

log

fun log(numericExpr: Expression, base: Number): Expression

Creates an expression that returns the logarithm of numericExpr with a given base.

// Compute the logarithm of the 'value' field with base 10.
log(field("value"), 10)
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

base: Number

The base of the logarithm.

Returns
Expression

A new Expression representing a numeric result from the logarithm of numericExpr with a given base.

log

fun log(numericField: String, base: Expression): Expression

Creates an expression that returns the logarithm of numericField with a given base.

// Compute the logarithm of the 'value' field with the base in the 'base' field.
log("value", field("base"))
Parameters
numericField: String

Name of field that returns number when evaluated.

base: Expression

The base of the logarithm.

Returns
Expression

A new Expression representing a numeric result from the logarithm of numericField with a given base.

log

fun log(numericField: String, base: Number): Expression

Creates an expression that returns the logarithm of numericField with a given base.

// Compute the logarithm of the 'value' field with base 10.
log("value", 10)
Parameters
numericField: String

Name of field that returns number when evaluated.

base: Number

The base of the logarithm.

Returns
Expression

A new Expression representing a numeric result from the logarithm of numericField with a given base.

log10

fun log10(numericExpr: Expression): Expression

Creates an expression that returns the base 10 logarithm of numericExpr.

// Compute the base 10 logarithm of the 'value' field.
log10(field("value"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the base 10 logarithm.

log10

fun log10(numericField: String): Expression

Creates an expression that returns the base 10 logarithm of numericField.

// Compute the base 10 logarithm of the 'value' field.
log10("value")
Parameters
numericField: String

Name of field that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the base 10 logarithm.

logicalMaximum

fun logicalMaximum(expr: Expression, vararg others: Any): Expression

Creates an expression that returns the largest value between multiple input expressions or literal values. Based on Firestore's value type ordering.

// Returns the larger value between the 'timestamp' field and the current timestamp.
logicalMaximum(field("timestamp"), currentTimestamp())
Parameters
expr: Expression

The first operand expression.

vararg others: Any

Optional additional expressions or literals.

Returns
Expression

A new Expression representing the logical maximum operation.

logicalMaximum

fun logicalMaximum(fieldName: String, vararg others: Any): Expression

Creates an expression that returns the largest value between multiple input expressions or literal values. Based on Firestore's value type ordering.

// Returns the larger value between the 'timestamp' field and the current timestamp.
logicalMaximum("timestamp", currentTimestamp())
Parameters
fieldName: String

The first operand field name.

vararg others: Any

Optional additional expressions or literals.

Returns
Expression

A new Expression representing the logical maximum operation.

logicalMinimum

fun logicalMinimum(expr: Expression, vararg others: Any): Expression

Creates an expression that returns the smallest value between multiple input expressions or literal values. Based on Firestore's value type ordering.

// Returns the smaller value between the 'timestamp' field and the current timestamp.
logicalMinimum(field("timestamp"), currentTimestamp())
Parameters
expr: Expression

The first operand expression.

vararg others: Any

Optional additional expressions or literals.

Returns
Expression

A new Expression representing the logical minimum operation.

logicalMinimum

fun logicalMinimum(fieldName: String, vararg others: Any): Expression

Creates an expression that returns the smallest value between multiple input expressions or literal values. Based on Firestore's value type ordering.

// Returns the smaller value between the 'timestamp' field and the current timestamp.
logicalMinimum("timestamp", currentTimestamp())
Parameters
fieldName: String

The first operand field name.

vararg others: Any

Optional additional expressions or literals.

Returns
Expression

A new Expression representing the logical minimum operation.

map

fun map(elements: Map<StringAny>): Expression

Creates an expression that creates a Firestore map value from an input object.

// Create a map with a constant key and a field value
map(mapOf("name" to field("productName"), "quantity" to 1))
Parameters
elements: Map<StringAny>

The input map to evaluate in the expression.

Returns
Expression

A new Expression representing the map function.

mapGet

fun mapGet(fieldName: String, key: String): Expression

Accesses a value from a map (object) field using the provided key.

// Get the 'city' value from the 'address' map field
mapGet("address", "city")
Parameters
fieldName: String

The field name of the map field.

key: String

The key to access in the map.

Returns
Expression

A new Expression representing the value associated with the given key in the map.

mapGet

fun mapGet(fieldName: String, keyExpression: Expression): Expression

Accesses a value from a map (object) field using the provided keyExpression.

// Get the value from the 'address' map field, using the key from the 'keyField' field
mapGet("address", field("keyField"))
Parameters
fieldName: String

The field name of the map field.

keyExpression: Expression

The key to access in the map.

Returns
Expression

A new Expression representing the value associated with the given key in the map.

mapGet

fun mapGet(mapExpression: Expression, key: String): Expression

Accesses a value from a map (object) field using the provided key.

// Get the 'city' value from the 'address' map field
mapGet(field("address"), "city")
Parameters
mapExpression: Expression

The expression representing the map.

key: String

The key to access in the map.

Returns
Expression

A new Expression representing the value associated with the given key in the map.

mapGet

fun mapGet(mapExpression: Expression, keyExpression: Expression): Expression

Accesses a value from a map (object) field using the provided keyExpression.

// Get the value from the 'address' map field, using the key from the 'keyField' field
mapGet(field("address"), field("keyField"))
Parameters
mapExpression: Expression

The expression representing the map.

keyExpression: Expression

The key to access in the map.

Returns
Expression

A new Expression representing the value associated with the given key in the map.

mapMerge

fun mapMerge(
    firstMap: Expression,
    secondMap: Expression,
    vararg otherMaps: Expression
): Expression

Creates an expression that merges multiple maps into a single map. If multiple maps have the same key, the later value is used.

// Merges the map in the settings field with, a map literal, and a map in
// that is conditionally returned by another expression
mapMerge(
field("settings"),
map(mapOf("enabled" to true)),
conditional(
field("isAdmin").equal(true),
map(mapOf("admin" to true)),
map(emptyMap<String, Any>())
)
)
Parameters
firstMap: Expression

First map expression that will be merged.

secondMap: Expression

Second map expression that will be merged.

vararg otherMaps: Expression

Additional maps to merge.

Returns
Expression

A new Expression representing the mapMerge operation.

mapMerge

fun mapMerge(
    firstMapFieldName: String,
    secondMap: Expression,
    vararg otherMaps: Expression
): Expression

Creates an expression that merges multiple maps into a single map. If multiple maps have the same key, the later value is used.

// Merges the map in the settings field with, a map literal, and a map in
// that is conditionally returned by another expression
mapMerge(
"settings",
map(mapOf("enabled" to true)),
conditional(
field("isAdmin").equal(true),
map(mapOf("admin" to true)),
map(emptyMap<String, Any>())
)
)
Parameters
firstMapFieldName: String

First map field name that will be merged.

secondMap: Expression

Second map expression that will be merged.

vararg otherMaps: Expression

Additional maps to merge.

Returns
Expression

A new Expression representing the mapMerge operation.

mapRemove

fun mapRemove(mapExpr: Expression, key: Expression): Expression

Creates an expression that removes a key from the map produced by evaluating an expression.

// Removes the key 'baz' from the input map.
mapRemove(map(mapOf("foo" to "bar", "baz" to true)), constant("baz"))
Parameters
mapExpr: Expression

An expression that evaluates to a map.

key: Expression

The name of the key to remove from the input map.

Returns
Expression

A new Expression that evaluates to a modified map.

mapRemove

fun mapRemove(mapExpr: Expression, key: String): Expression

Creates an expression that removes a key from the map produced by evaluating an expression.

// Removes the key 'baz' from the input map.
mapRemove(map(mapOf("foo" to "bar", "baz" to true)), "baz")
Parameters
mapExpr: Expression

An expression that evaluates to a map.

key: String

The name of the key to remove from the input map.

Returns
Expression

A new Expression that evaluates to a modified map.

mapRemove

fun mapRemove(mapField: String, key: Expression): Expression

Creates an expression that removes a key from the map produced by evaluating an expression.

// Removes the key 'city' field from the map in the address field of the input document.
mapRemove("address", constant("city"))
Parameters
mapField: String

The name of a field containing a map value.

key: Expression

The name of the key to remove from the input map.

Returns
Expression

A new Expression that evaluates to a modified map.

mapRemove

fun mapRemove(mapField: String, key: String): Expression

Creates an expression that removes a key from the map produced by evaluating an expression.

// Removes the key 'city' field from the map in the address field of the input document.
mapRemove("address", "city")
Parameters
mapField: String

The name of a field containing a map value.

key: String

The name of the key to remove from the input map.

Returns
Expression

A new Expression that evaluates to a modified map.

mod

fun mod(dividend: Expression, divisor: Expression): Expression

Creates an expression that calculates the modulo (remainder) of dividing two numeric expressions.

// Calculate the remainder of dividing the 'value' field by the 'divisor' field
mod(field("value"), field("divisor"))
Parameters
dividend: Expression

The numeric expression to be divided.

divisor: Expression

The numeric expression to divide by.

Returns
Expression

A new Expression representing the modulo operation.

mod

fun mod(dividend: Expression, divisor: Number): Expression

Creates an expression that calculates the modulo (remainder) of dividing a numeric expression by a constant.

// Calculate the remainder of dividing the 'value' field by 3.
mod(field("value"), 3)
Parameters
dividend: Expression

The numeric expression to be divided.

divisor: Number

The constant to divide by.

Returns
Expression

A new Expression representing the modulo operation.

mod

fun mod(dividendFieldName: String, divisor: Expression): Expression

Creates an expression that calculates the modulo (remainder) of dividing a numeric field by a constant.

// Calculate the remainder of dividing the 'value' field by the 'divisor' field.
mod("value", field("divisor"))
Parameters
dividendFieldName: String

The numeric field name to be divided.

divisor: Expression

The numeric expression to divide by.

Returns
Expression

A new Expression representing the modulo operation.

mod

fun mod(dividendFieldName: String, divisor: Number): Expression

Creates an expression that calculates the modulo (remainder) of dividing a numeric field by a constant.

// Calculate the remainder of dividing the 'value' field by 3.
mod("value", 3)
Parameters
dividendFieldName: String

The numeric field name to be divided.

divisor: Number

The constant to divide by.

Returns
Expression

A new Expression representing the modulo operation.

multiply

fun multiply(first: Expression, second: Expression): Expression

Creates an expression that multiplies numeric expressions.

// Multiply the 'quantity' field by the 'price' field
multiply(field("quantity"), field("price"))
Parameters
first: Expression

Numeric expression to multiply.

second: Expression

Numeric expression to multiply.

Returns
Expression

A new Expression representing the multiplication operation.

multiply

fun multiply(first: Expression, second: Number): Expression

Creates an expression that multiplies numeric expressions with a constant.

// Multiply the 'quantity' field by 1.1.
multiply(field("quantity"), 1.1)
Parameters
first: Expression

Numeric expression to multiply.

second: Number

Constant to multiply.

Returns
Expression

A new Expression representing the multiplication operation.

multiply

fun multiply(numericFieldName: String, second: Expression): Expression

Creates an expression that multiplies a numeric field with a numeric expression.

// Multiply the 'quantity' field by the 'price' field.
multiply("quantity", field("price"))
Parameters
numericFieldName: String

Numeric field to multiply.

second: Expression

Numeric expression to multiply.

Returns
Expression

A new Expression representing the multiplication operation.

multiply

fun multiply(numericFieldName: String, second: Number): Expression

Creates an expression that multiplies a numeric field with a constant.

// Multiply the 'quantity' field by 1.1.
multiply("quantity", 1.1)
Parameters
numericFieldName: String

Numeric field to multiply.

second: Number

Constant to multiply.

Returns
Expression

A new Expression representing the multiplication operation.

not

fun not(condition: BooleanExpression): BooleanExpression

Creates an expression that negates a boolean expression.

// Check if 'is_admin' is not true
not(field("is_admin"))
Parameters
condition: BooleanExpression

The boolean expression to negate.

Returns
BooleanExpression

A new BooleanExpression representing the not operation.

notEqual

fun notEqual(fieldName: String, expression: Expression): BooleanExpression

Creates an expression that checks if a field's value is not equal to an expression.

// Check if the 'status' field is not equal to the value of the 'otherStatus' field
notEqual("status", field("otherStatus"))
Parameters
fieldName: String

The field name to compare.

expression: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the inequality comparison.

notEqual

fun notEqual(fieldName: String, value: Any): BooleanExpression

Creates an expression that checks if a field's value is not equal to another value.

// Check if the 'status' field is not equal to "completed"
notEqual("status", "completed")

// Check if the 'country' field is not equal to "USA"
notEqual("country", "USA")
Parameters
fieldName: String

The field name to compare.

value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the inequality comparison.

notEqual

fun notEqual(left: Expression, right: Any): BooleanExpression

Creates an expression that checks if an expression is not equal to a value.

// Check if the 'status' field is not equal to "completed"
notEqual(field("status"), "completed")
Parameters
left: Expression

The first expression to compare.

right: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the inequality comparison.

notEqual

fun notEqual(left: Expression, right: Expression): BooleanExpression

Creates an expression that checks if two expressions are not equal.

// Check if the 'status' field is not equal to the value of the 'otherStatus' field
notEqual(field("status"), field("otherStatus"))
Parameters
left: Expression

The first expression to compare.

right: Expression

The second expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the inequality comparison.

notEqualAny

fun notEqualAny(expression: Expression, arrayExpression: Expression): BooleanExpression

Creates an expression that checks if an expression, when evaluated, is not equal to all the elements of arrayExpression.

// Check if the 'status' field is not in the 'inactiveStatuses' array field.
notEqualAny(field("status"), field("inactiveStatuses"))
Parameters
expression: Expression

The expression whose results to compare.

arrayExpression: Expression

An expression that evaluates to an array, whose elements to check for equality to the input.

Returns
BooleanExpression

A new BooleanExpression representing the 'NOT IN' comparison.

notEqualAny

fun notEqualAny(expression: Expression, values: List<Any>): BooleanExpression

Creates an expression that checks if an expression, when evaluated, is not equal to all the provided values.

// Check if the 'status' field is neither "pending" nor the value of the 'rejectedStatus' field.
notEqualAny(field("status"), listOf("pending", field("rejectedStatus")))
Parameters
expression: Expression

The expression whose results to compare.

values: List<Any>

The values to check against.

Returns
BooleanExpression

A new BooleanExpression representing the 'NOT IN' comparison.

notEqualAny

fun notEqualAny(fieldName: String, arrayExpression: Expression): BooleanExpression

Creates an expression that checks if a field's value is not equal to all of the elements of arrayExpression.

// Check if the 'status' field is not in the 'inactiveStatuses' array field.
notEqualAny("status", field("inactiveStatuses"))
Parameters
fieldName: String

The field to compare.

arrayExpression: Expression

An expression that evaluates to an array, whose elements to check for equality to the input.

Returns
BooleanExpression

A new BooleanExpression representing the 'NOT IN' comparison.

notEqualAny

fun notEqualAny(fieldName: String, values: List<Any>): BooleanExpression

Creates an expression that checks if a field's value is not equal to all of the provided values.

// Check if the 'status' field is not "archived" or "deleted".
notEqualAny("status", listOf("archived", "deleted"))
Parameters
fieldName: String

The field to compare.

values: List<Any>

The values to check against.

Returns
BooleanExpression

A new BooleanExpression representing the 'NOT IN' comparison.

nullValue

fun nullValue(): Expression

Constant for a null value.

// Create a null constant
nullValue()
Returns
Expression

A Expression constant instance.

or

fun or(condition: BooleanExpression, vararg conditions: BooleanExpression): BooleanExpression

Creates an expression that performs a logical 'OR' operation.

// Check if 'status' is "new" or "open"
or(field("status").equal("new"), field("status").equal("open"))
Parameters
condition: BooleanExpression

The first BooleanExpression.

vararg conditions: BooleanExpression

Additional BooleanExpressions.

Returns
BooleanExpression

A new BooleanExpression representing the logical 'OR' operation.

pow

fun pow(numericExpr: Expression, exponent: Expression): Expression

Creates an expression that returns the numericExpr raised to the power of the exponent. Returns infinity on overflow and zero on underflow.

// Raise the value of the 'base' field to the power of the 'exponent' field.
pow(field("base"), field("exponent"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

exponent: Expression

The numeric power to raise the numericExpr.

Returns
Expression

A new Expression representing a numeric result from raising numericExpr to the power of exponent.

pow

fun pow(numericExpr: Expression, exponent: Number): Expression

Creates an expression that returns the numericExpr raised to the power of the exponent. Returns infinity on overflow and zero on underflow.

// Raise the value of the 'base' field to the power of 2.
pow(field("base"), 2)
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

exponent: Number

The numeric power to raise the numericExpr.

Returns
Expression

A new Expression representing a numeric result from raising numericExpr to the power of exponent.

pow

fun pow(numericField: String, exponent: Expression): Expression

Creates an expression that returns the numericField raised to the power of the exponent. Returns infinity on overflow and zero on underflow.

// Raise the value of the 'base' field to the power of the 'exponent' field.
pow("base", field("exponent"))
Parameters
numericField: String

Name of field that returns number when evaluated.

exponent: Expression

The numeric power to raise the numericField.

Returns
Expression

A new Expression representing a numeric result from raising numericField to the power of exponent.

pow

fun pow(numericField: String, exponent: Number): Expression

Creates an expression that returns the numericField raised to the power of the exponent. Returns infinity on overflow and zero on underflow.

// Raise the value of the 'base' field to the power of 2.
pow("base", 2)
Parameters
numericField: String

Name of field that returns number when evaluated.

exponent: Number

The numeric power to raise the numericField.

Returns
Expression

A new Expression representing a numeric result from raising numericField to the power of exponent.

rawFunction

fun rawFunction(name: String, vararg expr: Expression): Expression

Creates a 'raw' function expression. This is useful if the expression is available in the backend, but not yet in the current version of the SDK yet.

// Create a generic function call
rawFunction("my_function", field("arg1"), constant(42))
Parameters
name: String

The name of the raw function.

vararg expr: Expression

The expressions to be passed as arguments to the function.

Returns
Expression

A new Expression representing the raw function.

regexContains

fun regexContains(fieldName: String, pattern: Expression): BooleanExpression

Creates an expression that checks if a string field contains a specified regular expression as a substring.

// Check if the 'description' field contains the regex from the 'pattern' field.
regexContains("description", field("pattern"))
Parameters
fieldName: String

The name of the field containing the string.

pattern: Expression

The regular expression to use for the search.

Returns
BooleanExpression

A new BooleanExpression representing the contains regular expression comparison.

regexContains

fun regexContains(fieldName: String, pattern: String): BooleanExpression

Creates an expression that checks if a string field contains a specified regular expression as a substring.

// Check if the 'description' field contains "example" (case-insensitive)
regexContains("description", "(?i)example")
Parameters
fieldName: String

The name of the field containing the string.

pattern: String

The regular expression to use for the search.

Returns
BooleanExpression

A new BooleanExpression representing the contains regular expression comparison.

regexContains

fun regexContains(stringExpression: Expression, pattern: Expression): BooleanExpression

Creates an expression that checks if a string expression contains a specified regular expression as a substring.

// Check if the 'description' field contains "example" (case-insensitive)
regexContains(field("description"), "(?i)example")
Parameters
stringExpression: Expression

The expression representing the string to perform the comparison on.

pattern: Expression

The regular expression to use for the search.

Returns
BooleanExpression

A new BooleanExpression representing the contains regular expression comparison.

regexContains

fun regexContains(stringExpression: Expression, pattern: String): BooleanExpression

Creates an expression that checks if a string expression contains a specified regular expression as a substring.

// Check if the 'description' field contains "example" (case-insensitive)
regexContains(field("description"), "(?i)example")
Parameters
stringExpression: Expression

The expression representing the string to perform the comparison on.

pattern: String

The regular expression to use for the search.

Returns
BooleanExpression

A new BooleanExpression representing the contains regular expression comparison.

regexMatch

fun regexMatch(fieldName: String, pattern: Expression): BooleanExpression

Creates an expression that checks if a string field matches a specified regular expression.

// Check if the 'email' field matches the regex from the 'pattern' field.
regexMatch("email", field("pattern"))
Parameters
fieldName: String

The name of the field containing the string.

pattern: Expression

The regular expression to use for the match.

Returns
BooleanExpression

A new BooleanExpression representing the regular expression match comparison.

regexMatch

fun regexMatch(fieldName: String, pattern: String): BooleanExpression

Creates an expression that checks if a string field matches a specified regular expression.

// Check if the 'email' field matches a valid email pattern
regexMatch("email", "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}")
Parameters
fieldName: String

The name of the field containing the string.

pattern: String

The regular expression to use for the match.

Returns
BooleanExpression

A new BooleanExpression representing the regular expression match comparison.

regexMatch

fun regexMatch(stringExpression: Expression, pattern: Expression): BooleanExpression

Creates an expression that checks if a string field matches a specified regular expression.

// Check if the 'email' field matches a valid email pattern
regexMatch(field("email"), "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}")
Parameters
stringExpression: Expression

The expression representing the string to match against.

pattern: Expression

The regular expression to use for the match.

Returns
BooleanExpression

A new BooleanExpression representing the regular expression match comparison.

regexMatch

fun regexMatch(stringExpression: Expression, pattern: String): BooleanExpression

Creates an expression that checks if a string field matches a specified regular expression.

// Check if the 'email' field matches a valid email pattern
regexMatch(field("email"), "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}")
Parameters
stringExpression: Expression

The expression representing the string to match against.

pattern: String

The regular expression to use for the match.

Returns
BooleanExpression

A new BooleanExpression representing the regular expression match comparison.

reverse

fun reverse(fieldName: String): Expression

Creates an expression that reverses a string value from the specified field.

// Reverse the value of the 'myString' field.
reverse("myString")
Parameters
fieldName: String

The name of the field that contains the string to reverse.

Returns
Expression

A new Expression representing the reversed string.

reverse

fun reverse(stringExpression: Expression): Expression

Creates an expression that reverses a string.

// Reverse the value of the 'myString' field.
reverse(field("myString"))
Parameters
stringExpression: Expression

An expression evaluating to a string value, which will be reversed.

Returns
Expression

A new Expression representing the reversed string.

round

fun round(numericExpr: Expression): Expression

Creates an expression that rounds numericExpr to nearest integer.

// Round the value of the 'price' field.
round(field("price"))

Rounds away from zero in halfway cases.

Parameters
numericExpr: Expression

An expression that returns number when evaluated.

Returns
Expression

A new Expression representing an integer result from the round operation.

round

fun round(numericField: String): Expression

Creates an expression that rounds numericField to nearest integer.

// Round the value of the 'price' field.
round("price")

Rounds away from zero in halfway cases.

Parameters
numericField: String

Name of field that returns number when evaluated.

Returns
Expression

A new Expression representing an integer result from the round operation.

roundToPrecision

fun roundToPrecision(numericExpr: Expression, decimalPlace: Expression): Expression

Creates an expression that rounds off numericExpr to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative. Rounds away from zero in halfway cases.

// Round the value of the 'price' field to the number of decimal places specified in the
// 'precision' field.
roundToPrecision(field("price"), field("precision"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

decimalPlace: Expression

The number of decimal places to round.

Returns
Expression

A new Expression representing the round operation.

roundToPrecision

fun roundToPrecision(numericExpr: Expression, decimalPlace: Int): Expression

Creates an expression that rounds off numericExpr to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative. Rounds away from zero in halfway cases.

// Round the value of the 'price' field to 2 decimal places.
roundToPrecision(field("price"), 2)
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

decimalPlace: Int

The number of decimal places to round.

Returns
Expression

A new Expression representing the round operation.

roundToPrecision

fun roundToPrecision(numericField: String, decimalPlace: Expression): Expression

Creates an expression that rounds off numericField to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative. Rounds away from zero in halfway cases.

// Round the value of the 'price' field to the number of decimal places specified in the
// 'precision' field.
roundToPrecision("price", field("precision"))
Parameters
numericField: String

Name of field that returns number when evaluated.

decimalPlace: Expression

The number of decimal places to round.

Returns
Expression

A new Expression representing the round operation.

roundToPrecision

fun roundToPrecision(numericField: String, decimalPlace: Int): Expression

Creates an expression that rounds off numericField to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative. Rounds away from zero in halfway cases.

// Round the value of the 'price' field to 2 decimal places.
roundToPrecision("price", 2)
Parameters
numericField: String

Name of field that returns number when evaluated.

decimalPlace: Int

The number of decimal places to round.

Returns
Expression

A new Expression representing the round operation.

split

fun split(fieldName: String, delimiter: Blob): Expression

Creates an expression that splits a blob field by a blob delimiter.

// Split the 'data' field by a delimiter
split("data", Blob.fromBytes(byteArrayOf(0x0a)))
Parameters
fieldName: String

The name of the field containing the blob to be split.

delimiter: Blob

The blob delimiter to split by.

Returns
Expression

A new Expression that evaluates to an array of segments.

split

fun split(fieldName: String, delimiter: Expression): Expression

Creates an expression that splits a string or blob field by a delimiter.

// Split the 'tags' field by the value of the 'delimiter' field
split("tags", field("delimiter"))
Parameters
fieldName: String

The name of the field containing the string or blob to be split.

delimiter: Expression

The delimiter to split by.

Returns
Expression

A new Expression that evaluates to an array of segments.

split

fun split(fieldName: String, delimiter: String): Expression

Creates an expression that splits a string or blob field by a string delimiter.

// Split the 'tags' field by a comma
split("tags", ",")
Parameters
fieldName: String

The name of the field containing the string or blob to be split.

delimiter: String

The string delimiter to split by.

Returns
Expression

A new Expression that evaluates to an array of segments.

split

fun split(value: Expression, delimiter: Blob): Expression

Creates an expression that splits a blob by a blob delimiter.

// Split the 'data' field by a delimiter
split(field("data"), Blob.fromBytes(byteArrayOf(0x0a)))
Parameters
value: Expression

The expression evaluating to a blob to be split.

delimiter: Blob

The blob delimiter to split by.

Returns
Expression

A new Expression that evaluates to an array of segments.

split

fun split(value: Expression, delimiter: Expression): Expression

Creates an expression that splits a string or blob by a delimiter.

// Split the 'tags' field by a comma
split(field("tags"), field("delimiter"))
Parameters
value: Expression

The expression evaluating to a string or blob to be split.

delimiter: Expression

The delimiter to split by. Must be of the same type as value.

Returns
Expression

A new Expression that evaluates to an array of segments.

split

fun split(value: Expression, delimiter: String): Expression

Creates an expression that splits a string or blob by a string delimiter.

// Split the 'tags' field by a comma
split(field("tags"), ",")
Parameters
value: Expression

The expression evaluating to a string or blob to be split.

delimiter: String

The string delimiter to split by.

Returns
Expression

A new Expression that evaluates to an array of segments.

sqrt

fun sqrt(numericExpr: Expression): Expression

Creates an expression that returns the square root of numericExpr.

// Compute the square root of the 'value' field.
sqrt(field("value"))
Parameters
numericExpr: Expression

An expression that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the square root operation.

sqrt

fun sqrt(numericField: String): Expression

Creates an expression that returns the square root of numericField.

// Compute the square root of the 'value' field.
sqrt("value")
Parameters
numericField: String

Name of field that returns number when evaluated.

Returns
Expression

A new Expression representing the numeric result of the square root operation.

startsWith

fun startsWith(fieldName: String, prefix: Expression): BooleanExpression

Creates an expression that checks if a string expression starts with a given prefix.

// Check if the 'fullName' field starts with the value of the 'firstName' field
startsWith("fullName", field("firstName"))
Parameters
fieldName: String

The name of field that contains a string to check.

prefix: Expression

The prefix string expression to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'starts with' comparison.

startsWith

fun startsWith(fieldName: String, prefix: String): BooleanExpression

Creates an expression that checks if a string expression starts with a given prefix.

// Check if the 'name' field starts with "Mr."
startsWith("name", "Mr.")
Parameters
fieldName: String

The name of field that contains a string to check.

prefix: String

The prefix string to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'starts with' comparison.

startsWith

fun startsWith(stringExpr: Expression, prefix: Expression): BooleanExpression
// Check if the 'fullName' field starts with the value of the 'firstName' field
startsWith(field("fullName"), field("firstName"))
Parameters
stringExpr: Expression

The expression to check.

prefix: Expression

The prefix string expression to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'starts with' comparison.

startsWith

fun startsWith(stringExpr: Expression, prefix: String): BooleanExpression

Creates an expression that checks if a string expression starts with a given prefix.

// Check if the 'name' field starts with "Mr."
startsWith(field("name"), "Mr.")
Parameters
stringExpr: Expression

The expression to check.

prefix: String

The prefix string to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'starts with' comparison.

stringConcat

fun stringConcat(fieldName: String, vararg otherStrings: Any): Expression

Creates an expression that concatenates string expressions together.

// Combine the 'firstName', " ", and 'lastName' fields into a single string
stringConcat("firstName", " ", "lastName")
Parameters
fieldName: String

The field name containing the initial string value.

vararg otherStrings: Any

Optional additional string expressions or string constants to concatenate.

Returns
Expression

A new Expression representing the concatenated string.

stringConcat

fun stringConcat(fieldName: String, vararg otherStrings: Expression): Expression

Creates an expression that concatenates string expressions together.

// Combine the 'firstName', " ", and 'lastName' fields into a single string
stringConcat("firstName", constant(" "), field("lastName"))
Parameters
fieldName: String

The field name containing the initial string value.

vararg otherStrings: Expression

Optional additional string expressions to concatenate.

Returns
Expression

A new Expression representing the concatenated string.

stringConcat

fun stringConcat(firstString: Expression, vararg otherStrings: Any): Expression

Creates an expression that concatenates string expressions together.

// Combine the 'firstName', " ", and 'lastName' fields into a single string
stringConcat(field("firstName"), " ", field("lastName"))
Parameters
firstString: Expression

The expression representing the initial string value.

vararg otherStrings: Any

Optional additional string expressions or string constants to concatenate.

Returns
Expression

A new Expression representing the concatenated string.

stringConcat

fun stringConcat(firstString: Expression, vararg otherStrings: Expression): Expression

Creates an expression that concatenates string expressions together.

// Combine the 'firstName', " ", and 'lastName' fields into a single string
stringConcat(field("firstName"), constant(" "), field("lastName"))
Parameters
firstString: Expression

The expression representing the initial string value.

vararg otherStrings: Expression

Optional additional string expressions to concatenate.

Returns
Expression

A new Expression representing the concatenated string.

stringContains

fun stringContains(fieldName: String, substring: Expression): BooleanExpression

Creates an expression that checks if a string field contains a specified substring.

// Check if the 'description' field contains the value of the 'keyword' field.
stringContains("description", field("keyword"))
Parameters
fieldName: String

The name of the field to perform the comparison on.

substring: Expression

The expression representing the substring to search for.

Returns
BooleanExpression

A new BooleanExpression representing the contains comparison.

stringContains

fun stringContains(fieldName: String, substring: String): BooleanExpression

Creates an expression that checks if a string field contains a specified substring.

// Check if the 'description' field contains "example".
stringContains("description", "example")
Parameters
fieldName: String

The name of the field to perform the comparison on.

substring: String

The substring to search for.

Returns
BooleanExpression

A new BooleanExpression representing the contains comparison.

stringContains

fun stringContains(stringExpression: Expression, substring: Expression): BooleanExpression

Creates an expression that checks if a string expression contains a specified substring.

// Check if the 'description' field contains the value of the 'keyword' field.
stringContains(field("description"), field("keyword"))
Parameters
stringExpression: Expression

The expression representing the string to perform the comparison on.

substring: Expression

The expression representing the substring to search for.

Returns
BooleanExpression

A new BooleanExpression representing the contains comparison.

stringContains

fun stringContains(stringExpression: Expression, substring: String): BooleanExpression

Creates an expression that checks if a string expression contains a specified substring.

// Check if the 'description' field contains "example".
stringContains(field("description"), "example")
Parameters
stringExpression: Expression

The expression representing the string to perform the comparison on.

substring: String

The substring to search for.

Returns
BooleanExpression

A new BooleanExpression representing the contains comparison.

stringReverse

fun stringReverse(fieldName: String): Expression

Reverses the given string field.

// Reverse the value of the 'myString' field.
stringReverse("myString")
Parameters
fieldName: String

The name of field that contains the string to reverse.

Returns
Expression

A new Expression representing the stringReverse operation.

stringReverse

fun stringReverse(str: Expression): Expression

Reverses the given string expression.

// Reverse the value of the 'myString' field.
stringReverse(field("myString"))
Parameters
str: Expression

The string expression to reverse.

Returns
Expression

A new Expression representing the stringReverse operation.

substring

fun substring(fieldName: String, index: Int, length: Int): Expression

Creates an expression that returns a substring of the given string.

// Get a substring of the 'message' field starting at index 5 with length 10.
substring("message", 5, 10)
Parameters
fieldName: String

The name of the field containing the string to get a substring from.

index: Int

The starting index of the substring.

length: Int

The length of the substring.

Returns
Expression

A new Expression representing the substring.

substring

fun substring(
    stringExpression: Expression,
    index: Expression,
    length: Expression
): Expression

Creates an expression that returns a substring of the given string.

// Get a substring of the 'message' field starting at index 5 with length 10.
substring(field("message"), constant(5), constant(10))
Parameters
stringExpression: Expression

The expression representing the string to get a substring from.

index: Expression

The starting index of the substring.

length: Expression

The length of the substring.

Returns
Expression

A new Expression representing the substring.

subtract

fun subtract(minuend: Expression, subtrahend: Expression): Expression

Creates an expression that subtracts two expressions.

// Subtract the 'discount' field from the 'price' field
subtract(field("price"), field("discount"))
Parameters
minuend: Expression

Numeric expression to subtract from.

subtrahend: Expression

Numeric expression to subtract.

Returns
Expression

A new Expression representing the subtract operation.

subtract

fun subtract(minuend: Expression, subtrahend: Number): Expression

Creates an expression that subtracts a constant value from a numeric expression.

// Subtract 10 from the 'price' field.
subtract(field("price"), 10)
Parameters
minuend: Expression

Numeric expression to subtract from.

subtrahend: Number

Constant to subtract.

Returns
Expression

A new Expression representing the subtract operation.

subtract

fun subtract(numericFieldName: String, subtrahend: Expression): Expression

Creates an expression that subtracts a numeric expressions from numeric field.

// Subtract the 'discount' field from the 'price' field.
subtract("price", field("discount"))
Parameters
numericFieldName: String

Numeric field to subtract from.

subtrahend: Expression

Numeric expression to subtract.

Returns
Expression

A new Expression representing the subtract operation.

subtract

fun subtract(numericFieldName: String, subtrahend: Number): Expression

Creates an expression that subtracts a constant from numeric field.

// Subtract 10 from the 'price' field.
subtract("price", 10)
Parameters
numericFieldName: String

Numeric field to subtract from.

subtrahend: Number

Constant to subtract.

Returns
Expression

A new Expression representing the subtract operation.

timestampAdd

fun timestampAdd(fieldName: String, unit: Expression, amount: Expression): Expression

Creates an expression that adds a specified amount of time to a timestamp.

// Add some duration determined by field 'unit' and 'amount' to the 'timestamp' field.
timestampAdd("timestamp", field("unit"), field("amount"))
Parameters
fieldName: String

The name of the field that contains the timestamp.

unit: Expression

The expression representing the unit of time to add. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Expression

The expression representing the amount of time to add.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampAdd

fun timestampAdd(fieldName: String, unit: String, amount: Long): Expression

Creates an expression that adds a specified amount of time to a timestamp.

// Add 1 day to the 'timestamp' field.
timestampAdd("timestamp", "day", 1)
Parameters
fieldName: String

The name of the field that contains the timestamp.

unit: String

The unit of time to add. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Long

The amount of time to add.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampAdd

fun timestampAdd(timestamp: Expression, unit: Expression, amount: Expression): Expression

Creates an expression that adds a specified amount of time to a timestamp.

// Add some duration determined by field 'unit' and 'amount' to the 'timestamp' field.
timestampAdd(field("timestamp"), field("unit"), field("amount"))
Parameters
timestamp: Expression

The expression representing the timestamp.

unit: Expression

The expression representing the unit of time to add. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Expression

The expression representing the amount of time to add.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampAdd

fun timestampAdd(timestamp: Expression, unit: String, amount: Long): Expression

Creates an expression that adds a specified amount of time to a timestamp.

// Add 1 day to the 'timestamp' field.
timestampAdd(field("timestamp"), "day", 1)
Parameters
timestamp: Expression

The expression representing the timestamp.

unit: String

The unit of time to add. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Long

The amount of time to add.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampSubtract

fun timestampSubtract(fieldName: String, unit: Expression, amount: Expression): Expression

Creates an expression that subtracts a specified amount of time to a timestamp.

// Subtract some duration determined by field 'unit' and 'amount' from the 'timestamp' field.
timestampSubtract("timestamp", field("unit"), field("amount"))
Parameters
fieldName: String

The name of the field that contains the timestamp.

unit: Expression

The unit of time to subtract. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Expression

The amount of time to subtract.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampSubtract

fun timestampSubtract(fieldName: String, unit: String, amount: Long): Expression

Creates an expression that subtracts a specified amount of time to a timestamp.

// Subtract 1 day from the 'timestamp' field.
timestampSubtract("timestamp", "day", 1)
Parameters
fieldName: String

The name of the field that contains the timestamp.

unit: String

The unit of time to subtract. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Long

The amount of time to subtract.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampSubtract

fun timestampSubtract(
    timestamp: Expression,
    unit: Expression,
    amount: Expression
): Expression

Creates an expression that subtracts a specified amount of time to a timestamp.

// Subtract some duration determined by field 'unit' and 'amount' from the 'timestamp' field.
timestampSubtract(field("timestamp"), field("unit"), field("amount"))
Parameters
timestamp: Expression

The expression representing the timestamp.

unit: Expression

The expression representing the unit of time to subtract. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Expression

The expression representing the amount of time to subtract.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampSubtract

fun timestampSubtract(timestamp: Expression, unit: String, amount: Long): Expression

Creates an expression that subtracts a specified amount of time to a timestamp.

// Subtract 1 day from the 'timestamp' field.
timestampSubtract(field("timestamp"), "day", 1)
Parameters
timestamp: Expression

The expression representing the timestamp.

unit: String

The unit of time to subtract. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Long

The amount of time to subtract.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampToUnixMicros

fun timestampToUnixMicros(expr: Expression): Expression

Creates an expression that converts a timestamp expression to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to microseconds since epoch.
timestampToUnixMicros(field("timestamp"))
Parameters
expr: Expression

The expression representing the timestamp.

Returns
Expression

A new Expression representing the number of microseconds since epoch.

timestampToUnixMicros

fun timestampToUnixMicros(fieldName: String): Expression

Creates an expression that converts a timestamp field to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to microseconds since epoch.
timestampToUnixMicros("timestamp")
Parameters
fieldName: String

The name of the field that contains the timestamp.

Returns
Expression

A new Expression representing the number of microseconds since epoch.

timestampToUnixMillis

fun timestampToUnixMillis(expr: Expression): Expression

Creates an expression that converts a timestamp expression to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to milliseconds since epoch.
timestampToUnixMillis(field("timestamp"))
Parameters
expr: Expression

The expression representing the timestamp.

Returns
Expression

A new Expression representing the number of milliseconds since epoch.

timestampToUnixMillis

fun timestampToUnixMillis(fieldName: String): Expression

Creates an expression that converts a timestamp field to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to milliseconds since epoch.
timestampToUnixMillis("timestamp")
Parameters
fieldName: String

The name of the field that contains the timestamp.

Returns
Expression

A new Expression representing the number of milliseconds since epoch.

timestampToUnixSeconds

fun timestampToUnixSeconds(expr: Expression): Expression

Creates an expression that converts a timestamp expression to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to seconds since epoch.
timestampToUnixSeconds(field("timestamp"))
Parameters
expr: Expression

The expression representing the timestamp.

Returns
Expression

A new Expression representing the number of seconds since epoch.

timestampToUnixSeconds

fun timestampToUnixSeconds(fieldName: String): Expression

Creates an expression that converts a timestamp field to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to seconds since epoch.
timestampToUnixSeconds("timestamp")
Parameters
fieldName: String

The name of the field that contains the timestamp.

Returns
Expression

A new Expression representing the number of seconds since epoch.

timestampTruncate

fun timestampTruncate(fieldName: String, granularity: Expression): Expression

Creates an expression that truncates a timestamp to a specified granularity.

// Truncate the 'createdAt' timestamp to the beginning of the day.
timestampTruncate("createdAt", field("granularity"))
Parameters
fieldName: String

The name of the field containing the timestamp.

granularity: Expression

The granularity expression to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

Returns
Expression

A new Expression representing the truncated timestamp.

timestampTruncate

fun timestampTruncate(fieldName: String, granularity: String): Expression

Creates an expression that truncates a timestamp to a specified granularity.

// Truncate the 'createdAt' timestamp to the beginning of the day.
timestampTruncate("createdAt", "day")
Parameters
fieldName: String

The name of the field containing the timestamp.

granularity: String

The granularity to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

Returns
Expression

A new Expression representing the truncated timestamp.

timestampTruncate

fun timestampTruncate(timestamp: Expression, granularity: Expression): Expression

Creates an expression that truncates a timestamp to a specified granularity.

// Truncate the 'createdAt' timestamp to the beginning of the day.
timestampTruncate(field("createdAt"), field("granularity"))
Parameters
timestamp: Expression

The timestamp expression.

granularity: Expression

The granularity expression to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

Returns
Expression

A new Expression representing the truncated timestamp.

timestampTruncate

fun timestampTruncate(timestamp: Expression, granularity: String): Expression

Creates an expression that truncates a timestamp to a specified granularity.

// Truncate the 'createdAt' timestamp to the beginning of the day.
timestampTruncate(field("createdAt"), "day")
Parameters
timestamp: Expression

The timestamp expression.

granularity: String

The granularity to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

Returns
Expression

A new Expression representing the truncated timestamp.

timestampTruncate

fun timestampTruncate(
    fieldName: String,
    granularity: Expression,
    timezone: String
): Expression

Creates an expression that truncates a timestamp to a specified granularity in a given timezone.

// Truncate the 'createdAt' timestamp to the beginning of the day in "America/Los_Angeles"
// timezone.
timestampTruncate("createdAt", field("granularity"), "America/Los_Angeles")
Parameters
fieldName: String

The name of the field containing the timestamp.

granularity: Expression

The granularity expression to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

timezone: String

The timezone to use for truncation. Valid values are from the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1".

Returns
Expression

A new Expression representing the truncated timestamp.

timestampTruncate

fun timestampTruncate(fieldName: String, granularity: String, timezone: String): Expression

Creates an expression that truncates a timestamp to a specified granularity in a given timezone.

// Truncate the 'createdAt' timestamp to the beginning of the day in "America/Los_Angeles"
// timezone.
timestampTruncate("createdAt", "day", "America/Los_Angeles")
Parameters
fieldName: String

The name of the field containing the timestamp.

granularity: String

The granularity to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

timezone: String

The timezone to use for truncation. Valid values are from the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1".

Returns
Expression

A new Expression representing the truncated timestamp.

timestampTruncate

fun timestampTruncate(
    timestamp: Expression,
    granularity: Expression,
    timezone: String
): Expression

Creates an expression that truncates a timestamp to a specified granularity in a given timezone.

// Truncate the 'createdAt' timestamp to the beginning of the day in "America/Los_Angeles"
// timezone.
timestampTruncate(field("createdAt"), field("granularity"), "America/Los_Angeles")
Parameters
timestamp: Expression

The timestamp expression.

granularity: Expression

The granularity expression to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

timezone: String

The timezone to use for truncation. Valid values are from the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1".

Returns
Expression

A new Expression representing the truncated timestamp.

timestampTruncate

fun timestampTruncate(
    timestamp: Expression,
    granularity: String,
    timezone: String
): Expression

Creates an expression that truncates a timestamp to a specified granularity in a given timezone.

// Truncate the 'createdAt' timestamp to the beginning of the day in "America/Los_Angeles"
// timezone.
timestampTruncate(field("createdAt"), "day", "America/Los_Angeles")
Parameters
timestamp: Expression

The timestamp expression.

granularity: String

The granularity to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

timezone: String

The timezone to use for truncation. Valid values are from the TZ database (e.g., "America/Los_Angeles") or in the format "Etc/GMT-1".

Returns
Expression

A new Expression representing the truncated timestamp.

toLower

fun toLower(fieldName: String): Expression

Creates an expression that converts a string field to lowercase.

// Convert the 'name' field to lowercase
toLower("name")
Parameters
fieldName: String

The name of the field containing the string to convert to lowercase.

Returns
Expression

A new Expression representing the lowercase string.

toLower

fun toLower(stringExpression: Expression): Expression

Creates an expression that converts a string expression to lowercase.

// Convert the 'name' field to lowercase
toLower(field("name"))
Parameters
stringExpression: Expression

The expression representing the string to convert to lowercase.

Returns
Expression

A new Expression representing the lowercase string.

toUpper

fun toUpper(fieldName: String): Expression

Creates an expression that converts a string field to uppercase.

// Convert the 'title' field to uppercase
toUpper("title")
Parameters
fieldName: String

The name of the field containing the string to convert to uppercase.

Returns
Expression

A new Expression representing the uppercase string.

toUpper

fun toUpper(stringExpression: Expression): Expression

Creates an expression that converts a string expression to uppercase.

// Convert the 'title' field to uppercase
toUpper(field("title"))
Parameters
stringExpression: Expression

The expression representing the string to convert to uppercase.

Returns
Expression

A new Expression representing the uppercase string.

trim

fun trim(fieldName: String): Expression

Creates an expression that removes leading and trailing whitespace from a string field.

// Trim whitespace from the 'userInput' field
trim("userInput")
Parameters
fieldName: String

The name of the field containing the string to trim.

Returns
Expression

A new Expression representing the trimmed string.

trim

fun trim(stringExpression: Expression): Expression

Creates an expression that removes leading and trailing whitespace from a string expression.

// Trim whitespace from the 'userInput' field
trim(field("userInput"))
Parameters
stringExpression: Expression

The expression representing the string to trim.

Returns
Expression

A new Expression representing the trimmed string.

trimValue

fun trimValue(fieldName: String, valueToTrim: String): Expression

Creates an expression that removes leading and trailing characters from a string field.

// Trim '-', and '_' from the beginning and the end of 'userInput' field
trimValue("userInput", "-_")
Parameters
fieldName: String

The name of the field containing the string to trim.

valueToTrim: String

This parameter is treated as a set of characters or bytes that will be matched against the input from both ends.

Returns
Expression

A new Expression representing the trimmed string.

trimValue

fun trimValue(stringExpression: Expression, valueToTrim: Expression): Expression

Creates an expression that removes leading and trailing values from a expression. The accepted values types are string and blob.

// Trim specified characters from the 'userInput' field
trimValue(field("userInput"), field("valueToTrim"))
Parameters
stringExpression: Expression

The expression representing the string to trim.

valueToTrim: Expression

The expression evaluated to either a string or a blob. This parameter is treated as a set of characters or bytes that will be matched against the input from both ends.

Returns
Expression

A new Expression representing the trimmed string or bytes.

type

fun type(expr: Expression): Expression

Creates an expression that returns a string indicating the type of the value this expression evaluates to.

// Get the type of the 'value' field.
type(field("value"))
Parameters
expr: Expression

The expression to get the type of.

Returns
Expression

A new Expression representing the type operation.

type

fun type(fieldName: String): Expression

Creates an expression that returns a string indicating the type of the value this field evaluates to.

// Get the type of the 'field' field.
type("field")
Parameters
fieldName: String

The name of the field to get the type of.

Returns
Expression

A new Expression representing the type operation.

unixMicrosToTimestamp

fun unixMicrosToTimestamp(expr: Expression): Expression

Creates an expression that interprets an expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'microseconds' field as microseconds since epoch.
unixMicrosToTimestamp(field("microseconds"))
Parameters
expr: Expression

The expression representing the number of microseconds since epoch.

Returns
Expression

A new Expression representing the timestamp.

unixMicrosToTimestamp

fun unixMicrosToTimestamp(fieldName: String): Expression

Creates an expression that interprets a field's value as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'microseconds' field as microseconds since epoch.
unixMicrosToTimestamp("microseconds")
Parameters
fieldName: String

The name of the field containing the number of microseconds since epoch.

Returns
Expression

A new Expression representing the timestamp.

unixMillisToTimestamp

fun unixMillisToTimestamp(expr: Expression): Expression

Creates an expression that interprets an expression as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'milliseconds' field as milliseconds since epoch.
unixMillisToTimestamp(field("milliseconds"))
Parameters
expr: Expression

The expression representing the number of milliseconds since epoch.

Returns
Expression

A new Expression representing the timestamp.

unixMillisToTimestamp

fun unixMillisToTimestamp(fieldName: String): Expression

Creates an expression that interprets a field's value as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'milliseconds' field as milliseconds since epoch.
unixMillisToTimestamp("milliseconds")
Parameters
fieldName: String

The name of the field containing the number of milliseconds since epoch.

Returns
Expression

A new Expression representing the timestamp.

unixSecondsToTimestamp

fun unixSecondsToTimestamp(expr: Expression): Expression

Creates an expression that interprets an expression as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'seconds' field as seconds since epoch.
unixSecondsToTimestamp(field("seconds"))
Parameters
expr: Expression

The expression representing the number of seconds since epoch.

Returns
Expression

A new Expression representing the timestamp.

unixSecondsToTimestamp

fun unixSecondsToTimestamp(fieldName: String): Expression

Creates an expression that interprets a field's value as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'seconds' field as seconds since epoch.
unixSecondsToTimestamp("seconds")
Parameters
fieldName: String

The name of the field containing the number of seconds since epoch.

Returns
Expression

A new Expression representing the timestamp.

vector

fun vector(vector: DoubleArray): Expression

Create a vector constant for a DoubleArray value.

// Create a vector constant from a DoubleArray
vector(doubleArrayOf(1.0, 2.0, 3.0))
Parameters
vector: DoubleArray

The DoubleArray value.

Returns
Expression

A Expression constant instance.

vector

fun vector(vector: VectorValue): Expression

Create a vector constant for a VectorValue value.

// Create a vector constant from a VectorValue
vector(VectorValue(listOf(1.0, 2.0, 3.0)))
Parameters
vector: VectorValue

The VectorValue value.

Returns
Expression

A Expression constant instance.

vectorLength

fun vectorLength(fieldName: String): Expression

Creates an expression that calculates the length (dimension) of a Firestore Vector.

// Get the vector length (dimension) of the field 'embedding'.
vectorLength("embedding")
Parameters
fieldName: String

The name of the field containing the Firestore Vector.

Returns
Expression

A new Expression representing the length (dimension) of the vector.

vectorLength

fun vectorLength(vectorExpression: Expression): Expression

Creates an expression that calculates the length (dimension) of a Firestore Vector.

// Get the vector length (dimension) of the field 'embedding'.
vectorLength(field("embedding"))
Parameters
vectorExpression: Expression

The expression representing the Firestore Vector.

Returns
Expression

A new Expression representing the length (dimension) of the vector.

xor

fun xor(condition: BooleanExpression, vararg conditions: BooleanExpression): BooleanExpression

Creates an expression that performs a logical 'XOR' operation.

// Check if either 'a' is true or 'b' is true, but not both
xor(field("a"), field("b"))
Parameters
condition: BooleanExpression

The first BooleanExpression.

vararg conditions: BooleanExpression

Additional BooleanExpressions.

Returns
BooleanExpression

A new BooleanExpression representing the logical 'XOR' operation.

Public functions

abs

fun abs(): Expression

Creates an expression that returns the absolute value of this expression.

// Get the absolute value of the 'change' field.
field("change").abs()
Returns
Expression

A new Expression representing the numeric result of the absolute value operation.

add

fun add(second: Expression): Expression

Creates an expression that adds this numeric expression to another numeric expression.

// Add the value of the 'quantity' field and the 'reserve' field.
field("quantity").add(field("reserve"))
Parameters
second: Expression

Numeric expression to add.

Returns
Expression

A new Expression representing the addition operation.

add

fun add(second: Number): Expression

Creates an expression that adds this numeric expression to a constants.

// Add 5 to the value of the 'quantity' field.
field("quantity").add(5)
Parameters
second: Number

Constant to add.

Returns
Expression

A new Expression representing the addition operation.

alias

open fun alias(alias: String): Selectable

Assigns an alias to this expression.

Aliases are useful for renaming fields in the output of a stage or for giving meaningful names to calculated values.

Parameters
alias: String

The alias to assign to this expression.

Returns
Selectable

A new Selectable (typically an AliasedExpression) that wraps this expression and associates it with the provided alias.

arrayConcat

fun arrayConcat(secondArray: Any, vararg otherArrays: Any): Expression

Creates an expression that concatenates a field's array value with other arrays.

// Combine the 'items' array with a literal array.
field("items").arrayConcat(listOf("a", "b"))
Parameters
secondArray: Any

An array expression or array literal to concatenate.

vararg otherArrays: Any

Optional additional array expressions or array literals to concatenate.

Returns
Expression

A new Expression representing the arrayConcat operation.

arrayConcat

fun arrayConcat(secondArray: Expression, vararg otherArrays: Any): Expression

Creates an expression that concatenates a field's array value with other arrays.

// Combine the 'items' array with another array field.
field("items").arrayConcat(field("otherItems"))
Parameters
secondArray: Expression

An expression that evaluates to array to concatenate.

vararg otherArrays: Any

Optional additional array expressions or array literals to concatenate.

Returns
Expression

A new Expression representing the arrayConcat operation.

arrayContains

fun arrayContains(element: Any): BooleanExpression

Creates an expression that checks if array contains a specific element.

// Check if the 'colors' array contains "red"
field("colors").arrayContains("red")
Parameters
element: Any

The element to search for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContains operation.

arrayContains

fun arrayContains(element: Expression): BooleanExpression

Creates an expression that checks if array contains a specific element.

// Check if the 'sizes' array contains the value from the 'selectedSize' field
field("sizes").arrayContains(field("selectedSize"))
Parameters
element: Expression

The element to search for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContains operation.

arrayContainsAll

fun arrayContainsAll(arrayExpression: Expression): BooleanExpression

Creates an expression that checks if array contains all elements of arrayExpression.

// Check if the 'tags' array contains both of the values from field "tag1" and the literal value "tag2"
field("tags").arrayContainsAll(array(field("tag1"), "tag2"))
Parameters
arrayExpression: Expression

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAll operation.

arrayContainsAll

fun arrayContainsAll(values: List<Any>): BooleanExpression

Creates an expression that checks if array contains all the specified values.

// Check if the 'tags' array contains both the value in field "tag1" and the literal value "tag2"
field("tags").arrayContainsAll(listOf(field("tag1"), "tag2"))
Parameters
values: List<Any>

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAll operation.

arrayContainsAny

fun arrayContainsAny(arrayExpression: Expression): BooleanExpression

Creates an expression that checks if array contains any elements of arrayExpression.

// Check if the 'groups' array contains either the value from the 'userGroup' field
// or the value "guest"
field("groups").arrayContainsAny(array(field("userGroup"), "guest"))
Parameters
arrayExpression: Expression

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAny operation.

arrayContainsAny

fun arrayContainsAny(values: List<Any>): BooleanExpression

Creates an expression that checks if array contains any of the specified values.

// Check if the 'categories' array contains either values from field "cate1" or "cate2"
field("categories").arrayContainsAny(listOf(field("cate1"), field("cate2")))
Parameters
values: List<Any>

The elements to check for in the array.

Returns
BooleanExpression

A new BooleanExpression representing the arrayContainsAny operation.

arrayGet

fun arrayGet(offset: Expression): Expression

Creates an expression that indexes into an array from the beginning or end and return the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.

// Return the value in the tags field array at index specified by field 'favoriteTag'.
field("tags").arrayGet(field("favoriteTag"))
Parameters
offset: Expression

An Expression evaluating to the index of the element to return.

Returns
Expression

A new Expression representing the arrayOffset operation.

arrayGet

fun arrayGet(offset: Int): Expression

Creates an expression that indexes into an array from the beginning or end and return the element. If the offset exceeds the array length, an error is returned. A negative offset, starts from the end.

// Return the value in the 'tags' field array at index `1`.
field("tags").arrayGet(1)
Parameters
offset: Int

An Expression evaluating to the index of the element to return.

Returns
Expression

A new Expression representing the arrayOffset operation.

arrayLength

fun arrayLength(): Expression

Creates an expression that calculates the length of an array expression.

// Get the number of items in the 'cart' array
field("cart").arrayLength()
Returns
Expression

A new Expression representing the length of the array.

arrayReverse

fun arrayReverse(): Expression

Reverses the order of elements in the array.

// Reverse the value of the 'myArray' field.
field("myArray").arrayReverse()
Returns
Expression

A new Expression representing the arrayReverse operation.

arraySum

fun arraySum(): Expression

Creates an expression that returns the sum of the elements in this array expression.

// Get the sum of elements in the 'scores' array.
field("scores").arraySum()
Returns
Expression

A new Expression representing the sum of the array elements.

asBoolean

fun asBoolean(): BooleanExpression

Casts the expression to a BooleanExpression.

Returns
BooleanExpression

A BooleanExpression representing the same expression.

ascending

fun ascending(): Ordering

Create an Ordering that sorts documents in ascending order based on value of this expression

Returns
Ordering

A new Ordering object with ascending sort by this expression.

average

fun average(): AggregateFunction

Creates an aggregation that calculates the average (mean) of this numeric expression across multiple stage inputs.

Returns
AggregateFunction

A new AggregateFunction representing the average aggregation.

bitAnd

fun bitAnd(bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise AND operation with a constant.

// Bitwise AND the value of the 'flags' field with a constant mask.
field("flags").bitAnd(byteArrayOf(0b00001111))
Parameters
bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise AND operation.

bitAnd

fun bitAnd(bitsOther: Expression): Expression

Creates an expression that applies a bitwise AND operation with other expression.

// Bitwise AND the value of the 'flags' field with the value of the 'mask' field.
field("flags").bitAnd(field("mask"))
Parameters
bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise AND operation.

bitLeftShift

fun bitLeftShift(number: Int): Expression

Creates an expression that applies a bitwise left shift operation with a constant.

// Left shift the value of the 'bits' field by 2.
field("bits").bitLeftShift(2)
Parameters
number: Int

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise left shift operation.

bitLeftShift

fun bitLeftShift(numberExpr: Expression): Expression

Creates an expression that applies a bitwise left shift operation with an expression.

// Left shift the value of the 'bits' field by the value of the 'shift' field.
field("bits").bitLeftShift(field("shift"))
Parameters
numberExpr: Expression

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise left shift operation.

bitNot

fun bitNot(): Expression

Creates an expression that applies a bitwise NOT operation to this expression.

// Bitwise NOT the value of the 'flags' field.
field("flags").bitNot()
Returns
Expression

A new Expression representing the bitwise NOT operation.

bitOr

fun bitOr(bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise OR operation with a constant.

// Bitwise OR the value of the 'flags' field with a constant mask.
field("flags").bitOr(byteArrayOf(0b00001111))
Parameters
bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise OR operation.

bitOr

fun bitOr(bitsOther: Expression): Expression

Creates an expression that applies a bitwise OR operation with other expression.

// Bitwise OR the value of the 'flags' field with the value of the 'mask' field.
field("flags").bitOr(field("mask"))
Parameters
bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise OR operation.

bitRightShift

fun bitRightShift(number: Int): Expression

Creates an expression that applies a bitwise right shift operation with a constant.

// Right shift the value of the 'bits' field by 2.
field("bits").bitRightShift(2)
Parameters
number: Int

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise right shift operation.

bitRightShift

fun bitRightShift(numberExpr: Expression): Expression

Creates an expression that applies a bitwise right shift operation with an expression.

// Right shift the value of the 'bits' field by the value of the 'shift' field.
field("bits").bitRightShift(field("shift"))
Parameters
numberExpr: Expression

The number of bits to shift.

Returns
Expression

A new Expression representing the bitwise right shift operation.

bitXor

fun bitXor(bitsOther: ByteArray): Expression

Creates an expression that applies a bitwise XOR operation with a constant.

// Bitwise XOR the value of the 'flags' field with a constant mask.
field("flags").bitXor(byteArrayOf(0b00001111))
Parameters
bitsOther: ByteArray

A constant byte array.

Returns
Expression

A new Expression representing the bitwise XOR operation.

bitXor

fun bitXor(bitsOther: Expression): Expression

Creates an expression that applies a bitwise XOR operation with an expression.

// Bitwise XOR the value of the 'flags' field with the value of the 'mask' field.
field("flags").bitXor(field("mask"))
Parameters
bitsOther: Expression

An expression that returns bits when evaluated.

Returns
Expression

A new Expression representing the bitwise XOR operation.

byteLength

fun byteLength(): Expression

Creates an expression that calculates the length of a string in UTF-8 bytes, or just the length of a Blob.

// Calculate the length of the 'myString' field in bytes.
field("myString").byteLength()
Returns
Expression

A new Expression representing the length of the string in bytes.

ceil

fun ceil(): Expression

Creates an expression that returns the smallest integer that isn't less than this numeric expression.

// Compute the ceiling of the 'price' field.
field("price").ceil()
Returns
Expression

A new Expression representing an integer result from the ceil operation.

charLength

fun charLength(): Expression

Creates an expression that calculates the character length of this string expression in UTF8.

// Get the character length of the 'name' field in UTF-8.
field("name").charLength()
Returns
Expression

A new Expression representing the charLength operation.

collectionId

fun collectionId(): Expression

Creates an expression that returns the collection ID from this path expression.

// Get the collection ID from the 'path' field
field("path").collectionId()
Returns
Expression

A new Expression representing the collectionId operation.

concat

fun concat(second: Any, vararg others: Any): Expression

Creates an expression that concatenates this expression's value with others. The values must be all strings, all arrays, or all blobs. Types cannot be mixed.

// Concatenate a field with a literal string.
field("firstName").concat("lastName")
Parameters
second: Any

The second value to concatenate.

vararg others: Any

Additional values to concatenate.

Returns
Expression

A new Expression representing the concatenation.

concat

fun concat(second: Expression, vararg others: Any): Expression

Creates an expression that concatenates this expression's value with others. The values must be all strings, all arrays, or all blobs. Types cannot be mixed.

// Concatenate a field with another field.
field("firstName").concat(field("lastName"))
Parameters
second: Expression

The second expression to concatenate.

vararg others: Any

Additional expressions to concatenate.

Returns
Expression

A new Expression representing the concatenation.

cosineDistance

fun cosineDistance(vector: DoubleArray): Expression

Calculates the Cosine distance between this vector expression and a vector literal.

// Calculate the Cosine distance between the 'location' field and a target location
field("location").cosineDistance(doubleArrayOf(37.7749, -122.4194))
Parameters
vector: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

cosineDistance

fun cosineDistance(vector: Expression): Expression

Calculates the Cosine distance between this and another vector expressions.

// Calculate the cosine distance between the 'userVector' field and the 'itemVector' field
field("userVector").cosineDistance(field("itemVector"))
Parameters
vector: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

cosineDistance

fun cosineDistance(vector: VectorValue): Expression

Calculates the Cosine distance between this vector expression and a vector literal.

// Calculate the Cosine distance between the 'location' field and a target location
field("location").cosineDistance(VectorValue.from(listOf(37.7749, -122.4194)))
Parameters
vector: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the cosine distance between the two vectors.

count

fun count(): AggregateFunction

Creates an aggregation that counts the number of stage inputs with valid evaluations of the this expression.

Returns
AggregateFunction

A new AggregateFunction representing the count aggregation.

countDistinct

fun countDistinct(): AggregateFunction

Creates an aggregation that counts the number of distinct values of an expression across multiple stage inputs.

Returns
AggregateFunction

A new AggregateFunction representing the count distinct aggregation.

descending

fun descending(): Ordering

Create an Ordering that sorts documents in descending order based on value of this expression

Returns
Ordering

A new Ordering object with descending sort by this expression.

divide

fun divide(divisor: Expression): Expression

Creates an expression that divides this numeric expression by another numeric expression.

// Divide the 'total' field by the 'count' field
field("total").divide(field("count"))
Parameters
divisor: Expression

Numeric expression to divide this numeric expression by.

Returns
Expression

A new Expression representing the division operation.

divide

fun divide(divisor: Number): Expression

Creates an expression that divides this numeric expression by a constant.

// Divide the 'value' field by 10
field("value").divide(10)
Parameters
divisor: Number

Constant to divide this expression by.

Returns
Expression

A new Expression representing the division operation.

documentId

fun documentId(): Expression

Creates an expression that returns the document ID from this path expression.

// Get the document ID from the 'path' field
field("path").documentId()
Returns
Expression

A new Expression representing the documentId operation.

dotProduct

fun dotProduct(vector: DoubleArray): Expression

Calculates the dot product distance between this vector expression and a vector literal.

// Calculate the dot product between the 'vector' field and a constant vector
field("vector").dotProduct(doubleArrayOf(1.0, 2.0, 3.0))
Parameters
vector: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

dotProduct

fun dotProduct(vector: Expression): Expression

Calculates the dot product distance between this and another vector expression.

// Calculate the dot product between the 'userVector' field and the 'itemVector' field
field("userVector").dotProduct(field("itemVector"))
Parameters
vector: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

dotProduct

fun dotProduct(vector: VectorValue): Expression

Calculates the dot product distance between this vector expression and a vector literal.

// Calculate the dot product between the 'vector' field and a constant vector
field("vector").dotProduct(VectorValue.from(listOf(1.0, 2.0, 3.0)))
Parameters
vector: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the dot product distance between the two vectors.

endsWith

fun endsWith(suffix: Expression): BooleanExpression

Creates an expression that checks if this string expression ends with a given suffix.

// Check if the 'url' field ends with the value of the 'extension' field
field("url").endsWith(field("extension"))
Parameters
suffix: Expression

The suffix string expression to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'ends with' comparison.

endsWith

fun endsWith(suffix: String): BooleanExpression

Creates an expression that checks if this string expression ends with a given suffix.

// Check if the 'filename' field ends with ".txt"
field("filename").endsWith(".txt")
Parameters
suffix: String

The suffix string to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'ends with' comparison.

equal

fun equal(other: Expression): BooleanExpression

Creates an expression that checks if this and other expression are equal.

// Check if the 'age' field is equal to an expression
field("age").equal(field("minAge").add(10))
Parameters
other: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the equality comparison.

equal

fun equal(value: Any): BooleanExpression

Creates an expression that checks if this expression is equal to a value.

// Check if the 'age' field is equal to 21
field("age").equal(21)
Parameters
value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the equality comparison.

equalAny

fun equalAny(arrayExpression: Expression): BooleanExpression

Creates an expression that checks if this expression, when evaluated, is equal to any of the elements of arrayExpression.

// Check if the 'category' field is in the 'availableCategories' array field.
field("category").equalAny(field("availableCategories"))
Parameters
arrayExpression: Expression

An expression that evaluates to an array, whose elements to check for equality to the input.

Returns
BooleanExpression

A new BooleanExpression representing the 'IN' comparison.

equalAny

fun equalAny(values: List<Any>): BooleanExpression

Creates an expression that checks if this expression, when evaluated, is equal to any of the provided values.

// Check if the 'category' field is either "Electronics" or the value of the 'primaryType' field.
field("category").equalAny(listOf("Electronics", field("primaryType")))
Parameters
values: List<Any>

The values to check against.

Returns
BooleanExpression

A new BooleanExpression representing the 'IN' comparison.

euclideanDistance

fun euclideanDistance(vector: DoubleArray): Expression

Calculates the Euclidean distance between this vector expression and a vector literal.

// Calculate the Euclidean distance between the 'vector' field and a constant vector
field("vector").euclideanDistance(doubleArrayOf(1.0, 2.0, 3.0))
Parameters
vector: DoubleArray

The other vector (as an array of doubles) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

euclideanDistance

fun euclideanDistance(vector: Expression): Expression

Calculates the Euclidean distance between this and another vector expression.

// Calculate the Euclidean distance between the 'userVector' field and the 'itemVector' field
field("userVector").euclideanDistance(field("itemVector"))
Parameters
vector: Expression

The other vector (represented as an Expression) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

euclideanDistance

fun euclideanDistance(vector: VectorValue): Expression

Calculates the Euclidean distance between this vector expression and a vector literal.

// Calculate the Euclidean distance between the 'vector' field and a constant vector
field("vector").euclideanDistance(VectorValue.from(listOf(1.0, 2.0, 3.0)))
Parameters
vector: VectorValue

The other vector (represented as an VectorValue) to compare against.

Returns
Expression

A new Expression representing the Euclidean distance between the two vectors.

exists

fun exists(): BooleanExpression

Creates an expression that checks if this expression evaluates to a name of the field that exists.

Returns
BooleanExpression

A new Expression representing the exists check.

exp

fun exp(): Expression

Creates an expression that returns Euler's number e raised to the power of this expression.

// Compute e to the power of the 'value' field.
field("value").exp()
Returns
Expression

A new Expression representing the numeric result of the exponentiation.

floor

fun floor(): Expression

Creates an expression that returns the largest integer that is not greater than this numeric expression.

// Compute the floor of the 'price' field.
field("price").floor()
Returns
Expression

A new Expression representing an integer result from the floor operation.

greaterThan

fun greaterThan(other: Expression): BooleanExpression

Creates an expression that checks if this expression is greater than the other expression.

// Check if the 'age' field is greater than the 'limit' field
field("age").greaterThan(field("limit"))
Parameters
other: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than comparison.

greaterThan

fun greaterThan(value: Any): BooleanExpression

Creates an expression that checks if this expression is greater than a value.

// Check if the 'price' field is greater than 100
field("price").greaterThan(100)
Parameters
value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than comparison.

greaterThanOrEqual

fun greaterThanOrEqual(other: Expression): BooleanExpression

Creates an expression that checks if this expression is greater than or equal to the other expression.

// Check if the 'quantity' field is greater than or equal to field 'requirement' plus 1
field("quantity").greaterThanOrEqual(field("requirement").add(1))
Parameters
other: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than or equal to comparison.

greaterThanOrEqual

fun greaterThanOrEqual(value: Any): BooleanExpression

Creates an expression that checks if this expression is greater than or equal to a value.

// Check if the 'score' field is greater than or equal to 80
field("score").greaterThanOrEqual(80)
Parameters
value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the greater than or equal to comparison.

ifAbsent

fun ifAbsent(elseExpr: Expression): Expression

Creates an expression that returns the elseExpr argument if this expression is absent, else return the result of this expression.

// Returns the value of the optional field 'optional_field', or returns 'default_value'
// if the field is absent.
field("optional_field").ifAbsent("default_value")
Parameters
elseExpr: Expression

The expression that will be evaluated and returned if this expression is absent.

Returns
Expression

A new Expression representing the ifAbsent operation.

ifAbsent

fun ifAbsent(elseValue: Any): Expression

Creates an expression that returns the elseValue argument if this expression is absent, else return the result of this expression.

// Returns the value of the optional field 'optional_field', or returns 'default_value'
// if the field is absent.
field("optional_field").ifAbsent("default_value")
Parameters
elseValue: Any

The value that will be returned if this expression is absent.

Returns
Expression

A new Expression representing the ifAbsent operation.

ifError

fun ifError(catchExpr: Expression): Expression

Creates an expression that returns the catchExpr argument if there is an error, else return the result of this expression.

// Returns the first item in the title field arrays, or returns
// the entire title field if the array is empty or the field is another type.
arrayGet(field("title"), 0).ifError(field("title"))
Parameters
catchExpr: Expression

The catch expression that will be evaluated and returned if the this expression produces an error.

Returns
Expression

A new Expression representing the ifError operation.

ifError

fun ifError(catchValue: Any): Expression

Creates an expression that returns the catchValue argument if there is an error, else return the result of this expression.

// Returns the first item in the title field arrays, or returns "Default Title"
arrayGet(field("title"), 0).ifError("Default Title")
Parameters
catchValue: Any

The value that will be returned if this expression produces an error.

Returns
Expression

A new Expression representing the ifError operation.

isAbsent

fun isAbsent(): BooleanExpression

Creates an expression that returns true if the result of this expression is absent. Otherwise, returns false even if the value is null.

// Check if the field `value` is absent.
field("value").isAbsent()
Returns
BooleanExpression

A new BooleanExpression representing the isAbsent operation.

isError

fun isError(): BooleanExpression

Creates an expression that checks if this expression produces an error.

// Check if the result of a calculation is an error
arrayContains(field("title"), 1).isError()
Returns
BooleanExpression

A new BooleanExpression representing the isError check.

join

fun join(delimiter: String): Expression

Creates an expression that joins the elements of an array into a string.

// Join the elements of the 'tags' field with a comma and space.
field("tags").join(", ")
Parameters
delimiter: String

The string to use as a delimiter.

Returns
Expression

A new Expression representing the join operation.

join

fun join(delimiterExpression: Expression): Expression

Creates an expression that joins the elements of an array into a string.

// Join the elements of the 'tags' field with the delimiter from the 'separator' field.
field("tags").join(field("separator"))
Parameters
delimiterExpression: Expression

The expression that evaluates to the delimiter string.

Returns
Expression

A new Expression representing the join operation.

length

fun length(): Expression

Creates an expression that calculates the length of a string, array, map, vector, or blob expression.

// Get the length of the 'value' field where the value type can be any of a string, array, map, vector or blob.
field("value").length()
Returns
Expression

A new Expression representing the length operation.

lessThan

fun lessThan(other: Expression): BooleanExpression

Creates an expression that checks if this expression is less than the other expression.

// Check if the 'age' field is less than 'limit'
field("age").lessThan(field("limit"))
Parameters
other: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than comparison.

lessThan

fun lessThan(value: Any): BooleanExpression

Creates an expression that checks if this expression is less than a value.

// Check if the 'price' field is less than 50
field("price").lessThan(50)
Parameters
value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than comparison.

lessThanOrEqual

fun lessThanOrEqual(other: Expression): BooleanExpression

Creates an expression that checks if this expression is less than or equal to the other expression.

// Check if the 'quantity' field is less than or equal to 20
field("quantity").lessThanOrEqual(constant(20))
Parameters
other: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than or equal to comparison.

lessThanOrEqual

fun lessThanOrEqual(value: Any): BooleanExpression

Creates an expression that checks if this expression is less than or equal to a value.

// Check if the 'score' field is less than or equal to 70
field("score").lessThanOrEqual(70)
Parameters
value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the less than or equal to comparison.

like

fun like(pattern: Expression): BooleanExpression

Creates an expression that performs a case-sensitive wildcard string comparison.

// Check if the 'title' field contains the string "guide"
field("title").like("%guide%")
Parameters
pattern: Expression

The pattern to search for. You can use "%" as a wildcard character.

Returns
BooleanExpression

A new BooleanExpression representing the like operation.

like

fun like(pattern: String): BooleanExpression

Creates an expression that performs a case-sensitive wildcard string comparison.

// Check if the 'title' field contains the string "guide"
field("title").like("%guide%")
Parameters
pattern: String

The pattern to search for. You can use "%" as a wildcard character.

Returns
BooleanExpression

A new BooleanExpression representing the like operation.

ln

fun ln(): Expression

Creates an expression that returns the natural logarithm of this numeric expression.

// compute the natural logarithm of the 'value' field.
field("value").ln()
Returns
Expression

A new Expression representing the numeric result of the natural logarithm operation.

log10

fun log10(): Expression

Creates an expression that returns the base-10 logarithm of this numeric expression.

// compute the base-10 logarithm of the 'value' field.
field("value").log10()
Returns
Expression

A new Expression representing the numeric result of the base-10 logarithm operation.

logicalMaximum

fun logicalMaximum(vararg others: Any): Expression

Creates an expression that returns the largest value between multiple input expressions or literal values. Based on Firestore's value type ordering.

// Returns the larger value between the 'timestamp' field and the current timestamp.
field("timestamp").logicalMaximum(currentTimestamp())
Parameters
vararg others: Any

Expressions or literals.

Returns
Expression

A new Expression representing the logical maximum operation.

logicalMaximum

fun logicalMaximum(vararg others: Expression): Expression

Creates an expression that returns the largest value between multiple input expressions or literal values. Based on Firestore's value type ordering.

// Returns the larger value between the 'timestamp' field and the current timestamp.
field("timestamp").logicalMaximum(currentTimestamp())
Parameters
vararg others: Expression

Expressions or literals.

Returns
Expression

A new Expression representing the logical maximum operation.

logicalMinimum

fun logicalMinimum(vararg others: Any): Expression

Creates an expression that returns the smallest value between multiple input expressions or literal values. Based on Firestore's value type ordering.

// Returns the smaller value between the 'timestamp' field and the current timestamp.
field("timestamp").logicalMinimum(currentTimestamp())
Parameters
vararg others: Any

Expressions or literals.

Returns
Expression

A new Expression representing the logical minimum operation.

logicalMinimum

fun logicalMinimum(vararg others: Expression): Expression

Creates an expression that returns the smallest value between multiple input expressions or literal values. Based on Firestore's value type ordering.

// Returns the smaller value between the 'timestamp' field and the current timestamp.
field("timestamp").logicalMinimum(currentTimestamp())
Parameters
vararg others: Expression

Expressions or literals.

Returns
Expression

A new Expression representing the logical minimum operation.

mapGet

fun mapGet(key: String): Expression

Accesses a map (object) value using the provided key.

// Get the 'city' value from the 'address' map field
field("address").mapGet("city")
Parameters
key: String

The key to access in the map.

Returns
Expression

A new Expression representing the value associated with the given key in the map.

mapGet

fun mapGet(keyExpression: Expression): Expression

Accesses a map (object) value using the provided keyExpression.

// Get the value from the 'address' map field, using the key from the 'keyField' field
field("address").mapGet(field("keyField"))
Parameters
keyExpression: Expression

The name of the key to remove from this map expression.

Returns
Expression

A new Expression representing the value associated with the given key in the map.

mapMerge

fun mapMerge(mapExpr: Expression, vararg otherMaps: Expression): Expression

Creates an expression that merges multiple maps into a single map. If multiple maps have the same key, the later value is used.

// Merges the map in the settings field with, a map literal, and a map in
// that is conditionally returned by another expression
field("settings").mapMerge(
map(mapOf("enabled" to true)),
conditional(
field("isAdmin").equal(true),
map(mapOf("admin" to true)),
map(emptyMap<String, Any>())
)
)
Parameters
mapExpr: Expression

Map expression that will be merged.

vararg otherMaps: Expression

Additional maps to merge.

Returns
Expression

A new Expression representing the mapMerge operation.

mapRemove

fun mapRemove(key: String): Expression

Creates an expression that removes a key from this map expression.

// Removes the key 'baz' from the input map.
map(mapOf("foo" to "bar", "baz" to true)).mapRemove("baz")
Parameters
key: String

The name of the key to remove from this map expression.

Returns
Expression

A new Expression that evaluates to a modified map.

mapRemove

fun mapRemove(keyExpression: Expression): Expression

Creates an expression that removes a key from this map expression.

// Removes the key 'baz' from the input map.
map(mapOf("foo" to "bar", "baz" to true)).mapRemove(constant("baz"))
Parameters
keyExpression: Expression

The name of the key to remove from this map expression.

Returns
Expression

A new Expression that evaluates to a modified map.

maximum

fun maximum(): AggregateFunction

Creates an aggregation that finds the maximum value of this expression across multiple stage inputs.

Returns
AggregateFunction

A new AggregateFunction representing the maximum aggregation.

minimum

fun minimum(): AggregateFunction

Creates an aggregation that finds the minimum value of this expression across multiple stage inputs.

Returns
AggregateFunction

A new AggregateFunction representing the minimum aggregation.

mod

fun mod(divisor: Expression): Expression

Creates an expression that calculates the modulo (remainder) of dividing this numeric expressions by another numeric expression.

// Calculate the remainder of dividing the 'value' field by the 'divisor' field
field("value").mod(field("divisor"))
Parameters
divisor: Expression

The numeric expression to divide this expression by.

Returns
Expression

A new Expression representing the modulo operation.

mod

fun mod(divisor: Number): Expression

Creates an expression that calculates the modulo (remainder) of dividing this numeric expressions by a constant.

// Calculate the remainder of dividing the 'value' field by 3.
field("value").mod(3)
Parameters
divisor: Number

The constant to divide this expression by.

Returns
Expression

A new Expression representing the modulo operation.

multiply

fun multiply(second: Expression): Expression

Creates an expression that multiplies this numeric expression with another numeric expression.

// Multiply the 'quantity' field by the 'price' field
field("quantity").multiply(field("price"))
Parameters
second: Expression

Numeric expression to multiply.

Returns
Expression

A new Expression representing the multiplication operation.

multiply

fun multiply(second: Number): Expression

Creates an expression that multiplies this numeric expression with a constant.

// Multiply the 'quantity' field by 1.1.
field("quantity").multiply(1.1)
Parameters
second: Number

Constant to multiply.

Returns
Expression

A new Expression representing the multiplication operation.

notEqual

fun notEqual(other: Expression): BooleanExpression

Creates an expression that checks if this expressions is not equal to the other expression.

// Check if the 'status' field is not equal to the value of the 'otherStatus' field
field("status").notEqual(field("otherStatus"))
Parameters
other: Expression

The expression to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the inequality comparison.

notEqual

fun notEqual(value: Any): BooleanExpression

Creates an expression that checks if this expression is not equal to a value.

// Check if the 'status' field is not equal to "completed"
field("status").notEqual("completed")
Parameters
value: Any

The value to compare to.

Returns
BooleanExpression

A new BooleanExpression representing the inequality comparison.

notEqualAny

fun notEqualAny(arrayExpression: Expression): BooleanExpression

Creates an expression that checks if this expression, when evaluated, is not equal to all the elements of arrayExpression.

// Check if the 'status' field is not in the 'inactiveStatuses' array field.
field("status").notEqualAny(field("inactiveStatuses"))
Parameters
arrayExpression: Expression

An expression that evaluates to an array, whose elements to check for equality to the input.

Returns
BooleanExpression

A new BooleanExpression representing the 'NOT IN' comparison.

notEqualAny

fun notEqualAny(values: List<Any>): BooleanExpression

Creates an expression that checks if this expression, when evaluated, is not equal to all the provided values.

// Check if the 'status' field is neither "pending" nor the value of the 'rejectedStatus' field.
field("status").notEqualAny(listOf("pending", field("rejectedStatus")))
Parameters
values: List<Any>

The values to check against.

Returns
BooleanExpression

A new BooleanExpression representing the 'NOT IN' comparison.

pow

fun pow(exponent: Expression): Expression

Creates an expression that returns this numeric expression raised to the power of the exponent. Returns infinity on overflow and zero on underflow.

// Raise the value of the 'base' field to the power of the 'exponent' field.
field("base").pow(field("exponent"))
Parameters
exponent: Expression

The numeric power to raise this numeric expression.

Returns
Expression

A new Expression representing a numeric result from raising this numeric expression to the power of exponent.

pow

fun pow(exponent: Number): Expression

Creates an expression that returns this numeric expression raised to the power of the exponent. Returns infinity on overflow and zero on underflow.

// Raise the value of the 'base' field to the power of 2.
field("base").pow(2)
Parameters
exponent: Number

The numeric power to raise this numeric expression.

Returns
Expression

A new Expression representing a numeric result from raising this numeric expression to the power of exponent.

regexContains

fun regexContains(pattern: Expression): BooleanExpression

Creates an expression that checks if this string expression contains a specified regular expression as a substring.

// Check if the 'description' field contains "example" (case-insensitive)
field("description").regexContains("(?i)example")
Parameters
pattern: Expression

The regular expression to use for the search.

Returns
BooleanExpression

A new BooleanExpression representing the contains regular expression comparison.

regexContains

fun regexContains(pattern: String): BooleanExpression

Creates an expression that checks if this string expression contains a specified regular expression as a substring.

// Check if the 'description' field contains "example" (case-insensitive)
field("description").regexContains("(?i)example")
Parameters
pattern: String

The regular expression to use for the search.

Returns
BooleanExpression

A new BooleanExpression representing the contains regular expression comparison.

regexMatch

fun regexMatch(pattern: Expression): BooleanExpression

Creates an expression that checks if this string expression matches a specified regular expression.

// Check if the 'email' field matches a valid email pattern
field("email").regexMatch("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}")
Parameters
pattern: Expression

The regular expression to use for the match.

Returns
BooleanExpression

A new BooleanExpression representing the regular expression match comparison.

regexMatch

fun regexMatch(pattern: String): BooleanExpression

Creates an expression that checks if this string expression matches a specified regular expression.

// Check if the 'email' field matches a valid email pattern
field("email").regexMatch("[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}")
Parameters
pattern: String

The regular expression to use for the match.

Returns
BooleanExpression

A new BooleanExpression representing the regular expression match comparison.

reverse

fun reverse(): Expression

Creates an expression that reverses this string expression.

// Reverse the value of the 'myString' field.
field("myString").reverse()
Returns
Expression

A new Expression representing the reversed string.

round

fun round(): Expression

Creates an expression that rounds this numeric expression to nearest integer.

// Round the value of the 'price' field.
field("price").round()

Rounds away from zero in halfway cases.

Returns
Expression

A new Expression representing an integer result from the round operation.

roundToPrecision

fun roundToPrecision(decimalPlace: Expression): Expression

Creates an expression that rounds off this numeric expression to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative. Rounds away from zero in halfway cases.

// Round the value of the 'price' field to the number of decimal places specified in the
// 'precision' field.
field("price").roundToPrecision(field("precision"))
Parameters
decimalPlace: Expression

The number of decimal places to round.

Returns
Expression

A new Expression representing the round operation.

roundToPrecision

fun roundToPrecision(decimalPlace: Int): Expression

Creates an expression that rounds off this numeric expression to decimalPlace decimal places if decimalPlace is positive, rounds off digits to the left of the decimal point if decimalPlace is negative. Rounds away from zero in halfway cases.

// Round the value of the 'price' field to 2 decimal places.
field("price").roundToPrecision(2)
Parameters
decimalPlace: Int

The number of decimal places to round.

Returns
Expression

A new Expression representing the round operation.

split

fun split(delimiter: Blob): Expression

Creates an expression that splits this blob expression by a blob delimiter.

// Split the 'data' field by a delimiter
field("data").split(Blob.fromBytes(byteArrayOf(0x0a)))
Parameters
delimiter: Blob

The blob delimiter to split by.

Returns
Expression

A new Expression that evaluates to an array of segments.

split

fun split(delimiter: Expression): Expression

Creates an expression that splits this string or blob expression by a delimiter.

// Split the 'tags' field by a comma
field("tags").split(field("delimiter"))
Parameters
delimiter: Expression

The delimiter to split by.

Returns
Expression

A new Expression that evaluates to an array of segments.

split

fun split(delimiter: String): Expression

Creates an expression that splits this string or blob expression by a string delimiter.

// Split the 'tags' field by a comma
field("tags").split(",")
Parameters
delimiter: String

The string delimiter to split by.

Returns
Expression

A new Expression that evaluates to an array of segments.

sqrt

fun sqrt(): Expression

Creates an expression that returns the square root of this numeric expression.

// Compute the square root of the 'value' field.
field("value").sqrt()
Returns
Expression

A new Expression representing the numeric result of the square root operation.

startsWith

fun startsWith(prefix: Expression): BooleanExpression

Creates an expression that checks if this string expression starts with a given prefix.

// Check if the 'fullName' field starts with the value of the 'firstName' field
field("fullName").startsWith(field("firstName"))
Parameters
prefix: Expression

The prefix string expression to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'starts with' comparison.

startsWith

fun startsWith(prefix: String): BooleanExpression

Creates an expression that checks if this string expression starts with a given prefix.

// Check if the 'name' field starts with "Mr."
field("name").startsWith("Mr.")
Parameters
prefix: String

The prefix string to check for.

Returns
BooleanExpression

A new BooleanExpression representing the 'starts with' comparison.

stringConcat

fun stringConcat(vararg stringExpressions: Expression): Expression

Creates an expression that concatenates string expressions together.

// Combine the 'firstName', " ", and 'lastName' fields into a single string
field("firstName").stringConcat(constant(" "), field("lastName"))
Parameters
vararg stringExpressions: Expression

The string expressions to concatenate.

Returns
Expression

A new Expression representing the concatenated string.

stringConcat

fun stringConcat(vararg strings: Any): Expression

Creates an expression that concatenates string expressions and string constants together.

// Combine the 'firstName', " ", and 'lastName' fields into a single string
field("firstName").stringConcat(" ", field("lastName"))
Parameters
vararg strings: Any

The string expressions or string constants to concatenate.

Returns
Expression

A new Expression representing the concatenated string.

stringConcat

fun stringConcat(vararg strings: String): Expression

Creates an expression that concatenates this string expression with string constants.

// Combine the 'firstName', " ", and 'lastName' fields into a single string
field("firstName").stringConcat(" ", "lastName")
Parameters
vararg strings: String

The string constants to concatenate.

Returns
Expression

A new Expression representing the concatenated string.

stringContains

fun stringContains(substring: Expression): BooleanExpression

Creates an expression that checks if this string expression contains a specified substring.

// Check if the 'description' field contains the value of the 'keyword' field.
field("description").stringContains(field("keyword"))
Parameters
substring: Expression

The expression representing the substring to search for.

Returns
BooleanExpression

A new BooleanExpression representing the contains comparison.

stringContains

fun stringContains(substring: String): BooleanExpression

Creates an expression that checks if this string expression contains a specified substring.

// Check if the 'description' field contains "example".
field("description").stringContains("example")
Parameters
substring: String

The substring to search for.

Returns
BooleanExpression

A new BooleanExpression representing the contains comparison.

stringReverse

fun stringReverse(): Expression

Creates an expression that performs a reverse operation on this string expression.

// reverse the field "filename": "abc.txt" => "txt.cba"
field("filename").stringReverse()
Returns
Expression

A new Expression representing the 'stringReverse' operation.

substring

fun substring(start: Expression, length: Expression): Expression

Creates an expression that returns a substring of the given string.

// Get a substring of the 'message' field starting at index 5 with length 10.
field("message").substring(constant(5), constant(10))
Parameters
start: Expression

The starting index of the substring.

length: Expression

The length of the substring.

Returns
Expression

A new Expression representing the substring.

substring

fun substring(start: Int, length: Int): Expression

Creates an expression that returns a substring of the given string.

// Get a substring of the 'message' field starting at index 5 with length 10.
field("message").substring(5, 10)
Parameters
start: Int

The starting index of the substring.

length: Int

The length of the substring.

Returns
Expression

A new Expression representing the substring.

subtract

fun subtract(subtrahend: Expression): Expression

Creates an expression that subtracts a constant from this numeric expression.

// Subtract the 'discount' field from the 'price' field
field("price").subtract(field("discount"))
Parameters
subtrahend: Expression

Numeric expression to subtract.

Returns
Expression

A new Expression representing the subtract operation.

subtract

fun subtract(subtrahend: Number): Expression

Creates an expression that subtracts a numeric expressions from this numeric expression.

// Subtract 10 from the 'price' field.
field("price").subtract(10)
Parameters
subtrahend: Number

Constant to subtract.

Returns
Expression

A new Expression representing the subtract operation.

sum

fun sum(): AggregateFunction

Creates an aggregation that calculates the sum of this numeric expression across multiple stage inputs.

Returns
AggregateFunction

A new AggregateFunction representing the sum aggregation.

timestampAdd

fun timestampAdd(unit: Expression, amount: Expression): Expression

Creates an expression that adds a specified amount of time to this timestamp expression.

// Add some duration determined by field 'unit' and 'amount' to the 'timestamp' field.
field("timestamp").timestampAdd(field("unit"), field("amount"))
Parameters
unit: Expression

The expression representing the unit of time to add. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Expression

The expression representing the amount of time to add.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampAdd

fun timestampAdd(unit: String, amount: Long): Expression

Creates an expression that adds a specified amount of time to this timestamp expression.

// Add 1 day to the 'timestamp' field.
field("timestamp").timestampAdd("day", 1)
Parameters
unit: String

The unit of time to add. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Long

The amount of time to add.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampSubtract

fun timestampSubtract(unit: Expression, amount: Expression): Expression

Creates an expression that subtracts a specified amount of time to this timestamp expression.

// Subtract some duration determined by field 'unit' and 'amount' from the 'timestamp' field.
field("timestamp").timestampSubtract(field("unit"), field("amount"))
Parameters
unit: Expression

The expression representing the unit of time to subtract. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Expression

The expression representing the amount of time to subtract.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampSubtract

fun timestampSubtract(unit: String, amount: Long): Expression

Creates an expression that subtracts a specified amount of time to this timestamp expression.

// Subtract 1 day from the 'timestamp' field.
field("timestamp").timestampSubtract("day", 1)
Parameters
unit: String

The unit of time to subtract. Valid units include "microsecond", "millisecond", "second", "minute", "hour" and "day".

amount: Long

The amount of time to subtract.

Returns
Expression

A new Expression representing the resulting timestamp.

timestampToUnixMicros

fun timestampToUnixMicros(): Expression

Creates an expression that converts this timestamp expression to the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to microseconds since epoch.
field("timestamp").timestampToUnixMicros()
Returns
Expression

A new Expression representing the number of microseconds since epoch.

timestampToUnixMillis

fun timestampToUnixMillis(): Expression

Creates an expression that converts this timestamp expression to the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to milliseconds since epoch.
field("timestamp").timestampToUnixMillis()
Returns
Expression

A new Expression representing the number of milliseconds since epoch.

timestampToUnixSeconds

fun timestampToUnixSeconds(): Expression

Creates an expression that converts this timestamp expression to the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC).

// Convert the 'timestamp' field to seconds since epoch.
field("timestamp").timestampToUnixSeconds()
Returns
Expression

A new Expression representing the number of seconds since epoch.

timestampTruncate

fun timestampTruncate(granularity: Expression): Expression

Creates an expression that truncates this timestamp expression to a specified granularity.

// Truncate the 'createdAt' timestamp to the beginning of the day.
field("createdAt").timestampTruncate(field("granularity"))
Parameters
granularity: Expression

The granularity expression to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

Returns
Expression

A new Expression representing the truncated timestamp.

timestampTruncate

fun timestampTruncate(granularity: String): Expression

Creates an expression that truncates this timestamp expression to a specified granularity.

// Truncate the 'createdAt' timestamp to the beginning of the day.
field("createdAt").timestampTruncate("day")
Parameters
granularity: String

The granularity to truncate to. Valid values are "microsecond", "millisecond", "second", "minute", "hour", "day", "week", "week(monday)", "week(tuesday)", "week(wednesday)", "week(thursday)", "week(friday)", "week(saturday)", "week(sunday)", "isoweek", "month", "quarter", "year", and "isoyear".

Returns
Expression

A new Expression representing the truncated timestamp.

toLower

fun toLower(): Expression

Creates an expression that converts this string expression to lowercase.

// Convert the 'name' field to lowercase
field("name").toLower()
Returns
Expression

A new Expression representing the lowercase string.

toUpper

fun toUpper(): Expression

Creates an expression that converts this string expression to uppercase.

// Convert the 'title' field to uppercase
field("title").toUpper()
Returns
Expression

A new Expression representing the uppercase string.

trim

fun trim(): Expression

Creates an expression that removes leading and trailing whitespace from this string expression.

// Trim whitespace from the 'userInput' field
field("userInput").trim()
Returns
Expression

A new Expression representing the trimmed string.

trimValue

fun trimValue(valueToTrim: Expression): Expression

Creates an expression that removes leading and trailing value from this expression. The accepted types are string and blob.

// Trim specified characters from the 'userInput' field
field("userInput").trimValue(field("trimChars"))
Parameters
valueToTrim: Expression

The expression representing the characters to trim from the string.

Returns
Expression

A new Expression representing the trimmed string.

trimValue

fun trimValue(valueToTrim: String): Expression

Creates an expression that removes leading and trailing characters from this string expression.

// Trim '_' and '-' from the 'userInput' field
field("userInput").trimValue("-_")
Parameters
valueToTrim: String

The characters to trim from the string.

Returns
Expression

A new Expression representing the trimmed string.

type

fun type(): Expression

Creates an expression that returns a string indicating the type of the value this expression evaluates to.

// Get the type of the 'value' field.
field("value").type()
Returns
Expression

A new Expression representing the type operation.

unixMicrosToTimestamp

fun unixMicrosToTimestamp(): Expression

Creates an expression that interprets this expression as the number of microseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'microseconds' field as microseconds since epoch.
field("microseconds").unixMicrosToTimestamp()
Returns
Expression

A new Expression representing the timestamp.

unixMillisToTimestamp

fun unixMillisToTimestamp(): Expression

Creates an expression that interprets this expression as the number of milliseconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'milliseconds' field as milliseconds since epoch.
field("milliseconds").unixMillisToTimestamp()
Returns
Expression

A new Expression representing the timestamp.

unixSecondsToTimestamp

fun unixSecondsToTimestamp(): Expression

Creates an expression that interprets this expression as the number of seconds since the Unix epoch (1970-01-01 00:00:00 UTC) and returns a timestamp.

// Interpret the 'seconds' field as seconds since epoch.
field("seconds").unixSecondsToTimestamp()
Returns
Expression

A new Expression representing the timestamp.

vectorLength

fun vectorLength(): Expression

Creates an expression that calculates the length (dimension) of a Firestore Vector.

// Get the vector length (dimension) of the field 'embedding'.
field("embedding").vectorLength()
Returns
Expression

A new Expression representing the length (dimension) of the vector.