Package dev.vortex.api.expressions
Class Literal<T>
java.lang.Object
dev.vortex.api.expressions.Literal<T>
- Type Parameters:
T
- the Java type of the literal value
- All Implemented Interfaces:
Expression
Represents a literal value expression in the Vortex query system.
A literal is a constant value of a specific type that can be used in expressions. This class provides factory methods for creating literals of various types including primitives (boolean, integers, floats), temporal types (dates, times, timestamps), and complex types (strings, bytes, decimals).
Literals are immutable and implement the visitor pattern for type-safe processing.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Visitor interface for processing literals in a type-safe manner.Nested classes/interfaces inherited from interface dev.vortex.api.Expression
Expression.Visitor<T>
-
Method Summary
Modifier and TypeMethodDescription<R> R
accept
(Expression.Visitor<R> visitor) Accepts a visitor and dispatches to the appropriate visit method based on the expression type.abstract <U> U
acceptLiteralVisitor
(Literal.LiteralVisitor<U> visitor) Accepts a literal visitor to process this literal in a type-safe manner.Creates a boolean literal.static Literal<byte[]>
bytes
(byte[] value) Creates a byte array literal.children()
Returns the children of this expression.Creates a date literal representing date as days since epoch.dateMillis
(Long value) Creates a date literal representing date as milliseconds since epoch.static Literal<BigDecimal>
decimal
(BigDecimal value, int precision, int scale) Creates a decimal literal with specified precision and scale.boolean
Creates a 32-bit floating-point literal.Creates a 64-bit floating-point literal.getValue()
Returns the value of this literal.int
hashCode()
id()
The globally unique identifier for this type of expression.Creates a 16-bit signed integer literal.Creates a 32-bit signed integer literal.Creates a 64-bit signed integer literal.Creates an 8-bit signed integer literal.Optional<byte[]>
metadata()
Returns the serialized metadata for this expression, or empty if serialization is not supported.nullLit()
Creates a null literal.static Literal<?>
parse
(byte[] metadata, List<Expression> children) Parses a literal from serialized metadata and child expressions.Creates a string literal.timeMicros
(Long value) Creates a time literal representing time of day in microseconds.timeMillis
(Integer value) Creates a time literal representing time of day in milliseconds.Creates a time literal representing time of day in nanoseconds.timeSeconds
(Integer value) Creates a time literal representing time of day in seconds.timestampMicros
(Long value, Optional<String> timeZone) Creates a timestamp literal with microsecond precision.timestampMillis
(Long value, Optional<String> timeZone) Creates a timestamp literal with millisecond precision.timestampNanos
(Long value, Optional<String> timeZone) Creates a timestamp literal with nanosecond precision.
-
Method Details
-
parse
Parses a literal from serialized metadata and child expressions.This method deserializes a literal expression from its protocol buffer representation. Literal expressions must have no children.
- Parameters:
metadata
- the serialized literal metadata as byteschildren
- the list of child expressions (must be empty for literals)- Returns:
- the parsed literal expression
- Throws:
RuntimeException
- if children is not empty or if metadata cannot be parsed
-
getValue
Returns the value of this literal.- Returns:
- the literal value, may be null for null literals
-
id
Description copied from interface:Expression
The globally unique identifier for this type of expression.- Specified by:
id
in interfaceExpression
-
children
Description copied from interface:Expression
Returns the children of this expression.- Specified by:
children
in interfaceExpression
-
metadata
Description copied from interface:Expression
Returns the serialized metadata for this expression, or empty if serialization is not supported.- Specified by:
metadata
in interfaceExpression
-
hashCode
public int hashCode() -
equals
-
nullLit
Creates a null literal.- Returns:
- a literal representing null
-
bool
Creates a boolean literal.- Parameters:
value
- the boolean value, may be null- Returns:
- a boolean literal
-
int8
Creates an 8-bit signed integer literal.- Parameters:
value
- the byte value, may be null- Returns:
- an int8 literal
-
int16
Creates a 16-bit signed integer literal.- Parameters:
value
- the short value, may be null- Returns:
- an int16 literal
-
int32
Creates a 32-bit signed integer literal.- Parameters:
value
- the integer value, may be null- Returns:
- an int32 literal
-
int64
Creates a 64-bit signed integer literal.- Parameters:
value
- the long value, may be null- Returns:
- an int64 literal
-
float32
Creates a 32-bit floating-point literal.- Parameters:
value
- the float value, may be null- Returns:
- a float32 literal
-
float64
Creates a 64-bit floating-point literal.- Parameters:
value
- the double value, may be null- Returns:
- a float64 literal
-
decimal
Creates a decimal literal with specified precision and scale.- Parameters:
value
- the decimal value, may be nullprecision
- the total number of digitsscale
- the number of digits after the decimal point- Returns:
- a decimal literal
- Throws:
RuntimeException
- if the value's scale doesn't match the specified scale
-
string
Creates a string literal.- Parameters:
value
- the string value, may be null- Returns:
- a string literal
-
bytes
Creates a byte array literal.- Parameters:
value
- the byte array value, may be null- Returns:
- a bytes literal
-
timeSeconds
Creates a time literal representing time of day in seconds.- Parameters:
value
- the time value in seconds since midnight, may be null- Returns:
- a time literal with second precision
-
timeMillis
Creates a time literal representing time of day in milliseconds.- Parameters:
value
- the time value in milliseconds since midnight, may be null- Returns:
- a time literal with millisecond precision
-
timeMicros
Creates a time literal representing time of day in microseconds.- Parameters:
value
- the time value in microseconds since midnight, may be null- Returns:
- a time literal with microsecond precision
-
timeNanos
Creates a time literal representing time of day in nanoseconds.- Parameters:
value
- the time value in nanoseconds since midnight, may be null- Returns:
- a time literal with nanosecond precision
-
dateDays
Creates a date literal representing date as days since epoch.- Parameters:
value
- the number of days since Unix epoch (1970-01-01), may be null- Returns:
- a date literal with day precision
-
dateMillis
Creates a date literal representing date as milliseconds since epoch.- Parameters:
value
- the number of milliseconds since Unix epoch, may be null- Returns:
- a date literal with millisecond precision
-
timestampMillis
Creates a timestamp literal with millisecond precision.- Parameters:
value
- the timestamp value in milliseconds since Unix epoch, may be nulltimeZone
- the time zone identifier (e.g., "UTC", "America/New_York"), optional- Returns:
- a timestamp literal with millisecond precision
-
timestampMicros
Creates a timestamp literal with microsecond precision.- Parameters:
value
- the timestamp value in microseconds since Unix epoch, may be nulltimeZone
- the time zone identifier (e.g., "UTC", "America/New_York"), optional- Returns:
- a timestamp literal with microsecond precision
-
timestampNanos
Creates a timestamp literal with nanosecond precision.- Parameters:
value
- the timestamp value in nanoseconds since Unix epoch, may be nulltimeZone
- the time zone identifier (e.g., "UTC", "America/New_York"), optional- Returns:
- a timestamp literal with nanosecond precision
-
accept
Description copied from interface:Expression
Accepts a visitor and dispatches to the appropriate visit method based on the expression type. This method implements the visitor pattern, allowing different operations to be performed on expressions without modifying the expression classes themselves.- Specified by:
accept
in interfaceExpression
- Type Parameters:
R
- the return type of the visitor- Parameters:
visitor
- the visitor to accept- Returns:
- the result of the visitor's operation on this expression
-
acceptLiteralVisitor
Accepts a literal visitor to process this literal in a type-safe manner.This method implements the visitor pattern, allowing different operations to be performed on literals based on their specific type.
- Type Parameters:
U
- the return type of the visitor operation- Parameters:
visitor
- the visitor to accept- Returns:
- the result of the visitor operation
-