Class Literal

Object
io.delta.kernel.expressions.Literal
All Implemented Interfaces:
Expression

@Evolving public final class Literal extends Object implements Expression
A literal value.

Definition:

Since:
3.0.0
  • Method Details

    • ofBoolean

      public static Literal ofBoolean(boolean value)
      Create a boolean type literal expression.
      Parameters:
      value - literal value
      Returns:
      a Literal of type BooleanType
    • ofByte

      public static Literal ofByte(byte value)
      Create a byte type literal expression.
      Parameters:
      value - literal value
      Returns:
      a Literal of type ByteType
    • ofShort

      public static Literal ofShort(short value)
      Create a short type literal expression.
      Parameters:
      value - literal value
      Returns:
      a Literal of type ShortType
    • ofInt

      public static Literal ofInt(int value)
      Create a integer type literal expression.
      Parameters:
      value - literal value
      Returns:
      a Literal of type IntegerType
    • ofLong

      public static Literal ofLong(long value)
      Create a long type literal expression.
      Parameters:
      value - literal value
      Returns:
      a Literal of type LongType
    • ofFloat

      public static Literal ofFloat(float value)
      Create a float type literal expression.
      Parameters:
      value - literal value
      Returns:
      a Literal of type FloatType
    • ofDouble

      public static Literal ofDouble(double value)
      Create a double type literal expression.
      Parameters:
      value - literal value
      Returns:
      a Literal of type DoubleType
    • ofString

      public static Literal ofString(String value)
      Create a string type literal expression.
      Parameters:
      value - literal value
      Returns:
      a Literal of type StringType
    • ofString

      public static Literal ofString(String value, CollationIdentifier collationIdentifier)
      Create a string type literal expression with collated StringType.
      Parameters:
      value - literal value
      collationIdentifier - collation identifier for the string literal
      Returns:
      a Literal of type StringType with the given collation
    • ofBinary

      public static Literal ofBinary(byte[] value)
      Create a binary type literal expression.
      Parameters:
      value - binary literal value as an array of bytes
      Returns:
      a Literal of type BinaryType
    • ofDate

      public static Literal ofDate(int daysSinceEpochUTC)
      Create a date type literal expression.
      Parameters:
      daysSinceEpochUTC - number of days since the epoch in UTC timezone.
      Returns:
      a Literal of type DateType
    • ofTimestamp

      public static Literal ofTimestamp(long microsSinceEpochUTC)
      Create a timestamp type literal expression.
      Parameters:
      microsSinceEpochUTC - microseconds since epoch time in UTC timezone.
      Returns:
      a Literal with data type TimestampType
    • ofTimestampNtz

      public static Literal ofTimestampNtz(long microSecondsEpoch)
      Create a timestamp_ntz type literal expression.
      Parameters:
      microSecondsEpoch - Microseconds since epoch with no timezone.
      Returns:
      a Literal with data type TimestampNTZType
    • ofDecimal

      public static Literal ofDecimal(BigDecimal value, int precision, int scale)
      Create a decimal type literal expression.
      Parameters:
      value - decimal literal value
      precision - precision of the decimal literal
      scale - scale of the decimal literal
      Returns:
      a Literal with data type DecimalType with given precision and scale.
    • ofGeospatialWKT

      public static Literal ofGeospatialWKT(String wkt, DataType dataType)
      Create a geospatial Well-Known Text (WKT) literal with the given data type. This factory only enforces the type contract (GeometryType or GeographyType). Callers are responsible for WKT content validation, as different engines may support different geometry types beyond POINT.
      Parameters:
      wkt - WKT string value
      dataType - must be GeometryType or GeographyType
      Returns:
      a Literal with the given geospatial type and String value
    • ofNull

      public static Literal ofNull(DataType dataType)
      Create null value literal.
      Parameters:
      dataType - DataType of the null literal.
      Returns:
      a null Literal with the given data type
    • getValue

      public Object getValue()
      Get the literal value. If the value is null a null is returned. For non-null literal the returned value is one of the following types based on the literal data type.
      • BOOLEAN: Boolean
      • BYTE: Byte
      • SHORT: Short
      • INTEGER: Integer
      • LONG: Long
      • FLOAT: Float
      • DOUBLE: Double
      • DATE: Integer represents the number of days since epoch in UTC
      • TIMESTAMP: Long represents the microseconds since epoch in UTC
      • TIMESTAMP_NTZ: Long represents the microseconds since epoch with no timezone
      • DECIMAL: BigDecimal.Use getDataType() to find the precision and scale
      • GEOMETRY: String WKT (Well-Known Text) representation
      • GEOGRAPHY: String WKT (Well-Known Text) representation
      Returns:
      Literal value.
    • getDataType

      public DataType getDataType()
      Get the datatype of the literal object. Datatype lets the caller interpret the value of the literal object returned by getValue()
      Returns:
      Datatype of the literal object.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getChildren

      public List<Expression> getChildren()
      Specified by:
      getChildren in interface Expression
      Returns:
      a list of expressions that are input to this expression.
    • equals

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