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

public abstract class Literal<T> extends Object implements 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.

  • Method Details

    • parse

      public static Literal<?> parse(byte[] metadata, List<Expression> children)
      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 bytes
      children - 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

      public T getValue()
      Returns the value of this literal.
      Returns:
      the literal value, may be null for null literals
    • id

      public String id()
      Description copied from interface: Expression
      The globally unique identifier for this type of expression.
      Specified by:
      id in interface Expression
    • children

      public List<Expression> children()
      Description copied from interface: Expression
      Returns the children of this expression.
      Specified by:
      children in interface Expression
    • metadata

      public Optional<byte[]> metadata()
      Description copied from interface: Expression
      Returns the serialized metadata for this expression, or empty if serialization is not supported.
      Specified by:
      metadata in interface Expression
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • nullLit

      public static Literal<Void> nullLit()
      Creates a null literal.
      Returns:
      a literal representing null
    • bool

      public static Literal<Boolean> bool(Boolean value)
      Creates a boolean literal.
      Parameters:
      value - the boolean value, may be null
      Returns:
      a boolean literal
    • int8

      public static Literal<Byte> int8(Byte value)
      Creates an 8-bit signed integer literal.
      Parameters:
      value - the byte value, may be null
      Returns:
      an int8 literal
    • int16

      public static Literal<Short> int16(Short value)
      Creates a 16-bit signed integer literal.
      Parameters:
      value - the short value, may be null
      Returns:
      an int16 literal
    • int32

      public static Literal<Integer> int32(Integer value)
      Creates a 32-bit signed integer literal.
      Parameters:
      value - the integer value, may be null
      Returns:
      an int32 literal
    • int64

      public static Literal<Long> int64(Long value)
      Creates a 64-bit signed integer literal.
      Parameters:
      value - the long value, may be null
      Returns:
      an int64 literal
    • float32

      public static Literal<Float> float32(Float value)
      Creates a 32-bit floating-point literal.
      Parameters:
      value - the float value, may be null
      Returns:
      a float32 literal
    • float64

      public static Literal<Double> float64(Double value)
      Creates a 64-bit floating-point literal.
      Parameters:
      value - the double value, may be null
      Returns:
      a float64 literal
    • decimal

      public static Literal<BigDecimal> decimal(BigDecimal value, int precision, int scale)
      Creates a decimal literal with specified precision and scale.
      Parameters:
      value - the decimal value, may be null
      precision - the total number of digits
      scale - 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

      public static Literal<String> string(String value)
      Creates a string literal.
      Parameters:
      value - the string value, may be null
      Returns:
      a string literal
    • bytes

      public static Literal<byte[]> bytes(byte[] value)
      Creates a byte array literal.
      Parameters:
      value - the byte array value, may be null
      Returns:
      a bytes literal
    • timeSeconds

      public static Literal<Integer> timeSeconds(Integer value)
      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

      public static Literal<Integer> timeMillis(Integer value)
      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

      public static Literal<Long> timeMicros(Long value)
      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

      public static Literal<Long> timeNanos(Long value)
      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

      public static Literal<Integer> dateDays(Integer value)
      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

      public static Literal<Long> dateMillis(Long value)
      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

      public static Literal<Long> timestampMillis(Long value, Optional<String> timeZone)
      Creates a timestamp literal with millisecond precision.
      Parameters:
      value - the timestamp value in milliseconds since Unix epoch, may be null
      timeZone - the time zone identifier (e.g., "UTC", "America/New_York"), optional
      Returns:
      a timestamp literal with millisecond precision
    • timestampMicros

      public static Literal<Long> timestampMicros(Long value, Optional<String> timeZone)
      Creates a timestamp literal with microsecond precision.
      Parameters:
      value - the timestamp value in microseconds since Unix epoch, may be null
      timeZone - the time zone identifier (e.g., "UTC", "America/New_York"), optional
      Returns:
      a timestamp literal with microsecond precision
    • timestampNanos

      public static Literal<Long> timestampNanos(Long value, Optional<String> timeZone)
      Creates a timestamp literal with nanosecond precision.
      Parameters:
      value - the timestamp value in nanoseconds since Unix epoch, may be null
      timeZone - the time zone identifier (e.g., "UTC", "America/New_York"), optional
      Returns:
      a timestamp literal with nanosecond precision
    • accept

      public <R> R accept(Expression.Visitor<R> visitor)
      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 interface Expression
      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

      public abstract <U> U acceptLiteralVisitor(Literal.LiteralVisitor<U> visitor)
      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