Expressions
NebulaStream supports use-provided expressions, which can be used in map and filter operators. These expressions allow the access and the modification of individual record attributes. Furthermore, expressions are evaluated in a tuple-at-a-time fashion.
Attribute Accesses
Records in a data stream always follow a specific schema, which defines a set of record attributes. The attribute access expression allows access to a specific attribute by name.
// Accesses a record attribute by its name.
Attribute("attributeName")
// Accesses a record attribute by its name.
attribute("attributeName")
Attribute Assignment
The attribute assignment expression enables the modification of individual attributes, e.g., in a map operator. To this end, the expression assigns a result value of an expression to already existing attributes or creates new attributes. If the attribute already exists, the result data types of the expression has to be compatible with the attribute data type. If the attribute dose not exists, NebulaStream infers the data type by the expression and adds the new attribute with a sutable data type to the schema.
💡 Currently, NebulaStream only supports the modification of single attributes at a time.
💡 Attribute assignment is a feature of the C++ client. In the Java client, the first parameter of the map operator specifies the target attribute name.
// Introduces a new attribute Y and assignes the value of attribute X
stream.map(Attribute("Y") = Attribute("X"))
// Modifies the value of attribute X
stream.map(Attribute("X") = Attribute("X") * 2)
// Introduces a new attribute Y and assignes the value of attribute X
stream.map("Y", attribute("X"))
// Modifies the value of attribute X
stream.map("X", attribute("X").multiply(2))
Logical Expressions
NebulaStream supports a set of common logical expressions to compare individual attributes.
This is mainly used by the filter operator.
In general, logical expressions evaluate to boolean values, i.e., either true
or false
.
And
Binary expression that performs a logical and
between two boolean values or expressions.
Bool
AND Bool
–> Bool
.
Attribute("fieldX") && Attribute("fieldY")
attribute("fieldX").and(attribute("fieldY"))
Or
Binary expression that performs a logical or
between two boolean expressions.
Bool
OR Bool
–> Bool
.
Attribute("fieldX") || Attribute("fieldY")
attribute("fieldX").or(attribute("fieldY"))
Equals
Binary expression that compares two expressions and returns true
if both values are equal.
💡 Both expressions have to be defined in a compatible data type.
X
EQUALS Y
–> Bool
.
// Compare two fields
Attribute("fieldX") == Attribute("fieldY")
// Compare field with constant
Attribute("fieldZ") == 10
// Compare two fields
attribute("fieldX").equalTo(attribute("fieldY"))
// Compare field with constant
attribute("fieldX").equalTo(10)
Not Equals
Binary expression that compares two expressions and returns true
if both values are not equal.
💡 Both expressions have to be defined in a compatible data type.
X
NOT EQUALS Y
–> Bool
.
// Compare two fields
Attribute("fieldX") != Attribute("fieldY")
// Compare field with constant
Attribute("fieldZ") != 10
// Compare two fields
attribute("fieldX").notEqualTo(attribute("fieldY"))
// Compare field with constant
attribute("fieldX").notEqualTo(10)
Less Equals
Binary expression that compares two expressions and returns true
if the value of the left expression is less or equal to the value of the right expression.
💡 This expression is currently only defined of integer and floating point data types.
X
LESS EQUALS Y
–> Bool
.
Attribute("fieldX") <= Attribute("fieldY")
attribute("fieldX").lessThanOrEqual(attribute("fieldY"))
Greater Equals
Binary expression that compares two expressions and returns true
if the value of the left expression is greater or equal to the value of the right expression.
💡 This expression is currently only defined of integer and floating point data types.
X
GREATER EQUALS Y
–> Bool
.
Attribute("fieldX") >= Attribute("fieldY")
attribute("fieldX").greaterThanOrEqual(attribute("fieldY"))
Less Than
Binary expression that compares two expressions and returns true
if the value of the left expression is less to the value of the right expression.
💡 This expression is currently only defined of integer and floating point data types.
X
LESS Y
–> Bool
.
Attribute("fieldX") < Attribute("fieldY")
attribute("fieldX").lessThan(attribute("fieldY"))
Greater Than
Binary expression that compares two expressions and returns true
if the value of the left expression is greater to the value of the right expression.
💡 This expression is currently only defined of integer and floating point data types.
X
GREATER Y
–> Bool
.
Attribute("fieldX") > Attribute("fieldY")
attribute("fieldX").greaterThan(attribute("fieldY"))
Negate
Unary expression that negates the value of a boolean value.
💡 This expression is only supported on attributes or expressions that return a boolean value.
NEGATE Bool
–> Bool
.
// Negates a boolean attribute
!Attribute("boolAttribute")
// Negates the result of a logical expression
!(Attribute("fieldX") == Attribute("fieldY"))
// Negates a boolean attribute
Expressions.not(attribute("boolAttribute"))
// Negates the result of a logical expression
Expressions.not(attribute("fieldX").equalTo(attribute("fieldY")))
Arithmetical Expressions
NebulaStream supports a set of common binary arithmetical expression, i.e., ADDITON, SUBSTRACTION, MULTIPLICATION, DIVISON, MODULO.
💡 These expressions are only supported on numeric types, i.e., integer and floating point data types.
Numeric
EXPRESSION Numeric
–> Numeric
.
Attribute("attributeX") + Attribute("attributeY")
Attribute("attributeX") - Attribute("attributeY")
Attribute("attributeX") * Attribute("attributeY")
Attribute("attributeX") / Attribute("attributeY")
Attribute("attributeX") % Attribute("attributeY")
attribute("attributeX").add(attribute("attributeY"))
attribute("attributeX").subtract(attribute("attributeY"))
attribute("attributeX").multiply(attribute("attributeY"))
attribute("attributeX").divide(attribute("attributeY"))
attribute("attributeX").remainder(attribute("attributeY"))
Functions
NebulaStream supports different functions to express special purpose operations.
Mod
The MOD function is an alias for the MODULO operator.
MOD(Numeric
,Numeric
) –> Numeric
.
MOD(Attribute("attributeX"), Attribute("attributeY"))
currently not supported
Power
POWER(Numeric
,Numeric
) –> Numeric
.
POWER(Attribute("attributeX"), Attribute("attributeY"))
Expressions.power(attribute("attributeX"), attribute("attributeY"))
Absolut
Calculates the absolute value from a numeric expression or value.
ABS(Numeric
) –> Numeric
.
ABS(Attribute("attributeX"))
Expressions.abs(attribute("attributeX"))
Square Root
Calculates the square root value from an numeric expression or value.
SQRT(Numeric
) –> Numeric
.
SQRT(Attribute("attributeX"))
Expressions.sqrt(attribute("attributeX"))
Exponential Function
EXP(Numeric
) –> Numeric
.
EXP(Attribute("attributeX"))
Expressions.exp(attribute("attributeX"))
Logarithmic Functions
NebulaStream supports the common logarithmic function to the base n
and 10
.
LOGN(Numeric
) –> Numeric
.
LOGN(Attribute("attributeX"))
Expressions.logN(attribute("attributeX"))
LOG10(Numeric
) –> Numeric
.
LOG10(Attribute("attributeX"))
Expressions.log10(attribute("attributeX"))
Rounding
NebulaStream supports three types of rounding for numeric values, i.e., ROUND, CEIL, and FLOOR.
Round
Computes the nearest integer value to the given attribute or expression (in floating-point format), rounding halfway cases away from zero, regardless of the current rounding mode.
ROUND(Numeric
) –> Numeric
.
ROUND(Attribute("attributeX"))
Expressions.round(attribute("attributeX"))
Ceil
Computes the smallest integer value not less than the given attribute or expression.
CEIL(Numeric
) –> Numeric
.
ROUND(Attribute("attributeX"))
Expressions.ceil(attribute("attributeX"))
Floor
) Computes the largest integer value not greater than the given attribute or expression.
FLOOR(Numeric
) –> Numeric
.
FLOOR(Attribute("attributeX"))
Expressions.floor(attribute("attributeX"))