Enum Class Primitive

java.lang.Object
java.lang.Enum<Primitive>
com.linkedin.feathr.common.tensor.Primitive
All Implemented Interfaces:
Representable, Serializable, Comparable<Primitive>, Constable

public enum Primitive extends Enum<Primitive> implements Serializable, Representable
Supported primitive types. They serve as basis for scalars - dimensions and values. Note: String types should only be used when the dimension is an actual text snippet.
  • Enum Constant Details

  • Method Details

    • values

      public static Primitive[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static Primitive valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • getRepresentation

      public Primitive getRepresentation()
      Specified by:
      getRepresentation in interface Representable
    • toInt

      public abstract int toInt(ReadableTuple tuple, int column)
    • toLong

      public abstract long toLong(ReadableTuple tuple, int column)
    • toFloat

      public abstract float toFloat(ReadableTuple tuple, int column)
    • toDouble

      public abstract double toDouble(ReadableTuple tuple, int column)
    • toBoolean

      public abstract boolean toBoolean(ReadableTuple tuple, int column)
    • toString

      public abstract String toString(ReadableTuple tuple, int column)
    • toBytes

      public abstract byte[] toBytes(ReadableTuple tuple, int column)
      Returns value serialized into a byte[].

      For numeric types (int, long, float, double), BIG_ENDIAN byte order is preserved.

      For string type, a UTF-8 charset is used to get bytes.

      For booleans, a single byte is returned in the array.

      Parameters:
      tuple - Input tuple
      column - Column index
      Returns:
      Value in byte[]
    • toObject

      public abstract Object toObject(ReadableTuple tuple, int column)
    • from

      public void from(Object value, WriteableTuple tuple, int column)
    • from

      public abstract void from(Number value, WriteableTuple tuple, int column)
    • from

      public abstract void from(int value, WriteableTuple tuple, int column)
    • from

      public abstract void from(long value, WriteableTuple tuple, int column)
    • from

      public abstract void from(float value, WriteableTuple tuple, int column)
    • from

      public abstract void from(double value, WriteableTuple tuple, int column)
    • from

      public abstract void from(boolean value, WriteableTuple tuple, int column)
    • from

      public abstract void from(String value, WriteableTuple tuple, int column)
    • from

      public abstract void from(byte[] value, WriteableTuple tuple, int column)
      Stores value from its byte[] serialization in the input tuple.

      For numeric types (int, long, float, double), BIG_ENDIAN byte order is expected.

      For string type, a UTF-8 charset is used to construct the string.

      For booleans, only the leading byte of the array is checked.

      Parameters:
      value - Input value
      tuple - Input tuple to store the value
      column - Column index
    • copy

      public abstract void copy(ReadableTuple fromTuple, int fromColumn, WriteableTuple toTuple, int toColumn)
      Copies data from fromTuple[fromColumn] to toTuple[toColumn] Note: The representation of both fromColumn and toColumn is assumed to be the same as this No validation on representation is performed
      Parameters:
      fromTuple - ReadableTuple from which to copy
      fromColumn - column in fromTuple to copy
      toTuple - WriteableTuple where the data would be copied
      toColumn - column in toTuple where the data would be copied
    • equals

      public abstract boolean equals(ReadableTuple leftTuple, int leftColumn, ReadableTuple rightTuple, int rightColumn)
      Matches data at leftTuple[leftColumn] with data at rightTuple[rightColumn] Note: The representation of both leftColumn and rightColumn is assumed to be the same as this No validation on representation is performed
      Parameters:
      leftTuple - left tuple from which a column will be matched
      leftColumn - column in leftTuple that will be matched
      rightTuple - right tuple from which a column will be matched
      rightColumn - column in right tuple that will be matched
      Returns:
      true if data is equal, false otherwise
    • compare

      public abstract int compare(ReadableTuple leftTuple, int leftColumn, ReadableTuple rightTuple, int rightColumn)
      Compares data at leftTuple[leftColumn] with data at rightTuple[rightColumn] Note: The representation of both leftColumn and rightColumn is assumed to be the same as this No validation on representation is performed
      Parameters:
      leftTuple - left tuple from which a column will be compared
      leftColumn - column in leftTuple that will be compared
      rightTuple - right tuple from which a column will be compared
      rightColumn - column in right tuple that will be compared
      Returns:
      -1 if lefttuple[leftColumn] < rightTuple[rightColumn], 0 if lefttuple[leftColumn] == rightTuple[rightColumn], 1 if lefttuple[leftColumn] > rightTuple[rightColumn]
    • canBeDenseDimension

      public abstract boolean canBeDenseDimension()
      Returns:
      if this primitive type can be used as a dimension in dense tensors. In other words, is this type integral. If true, the type MUST support toInt(com.linkedin.feathr.common.tensor.ReadableTuple, int), toLong(com.linkedin.feathr.common.tensor.ReadableTuple, int), and from(java.lang.Object, com.linkedin.feathr.common.tensor.WriteableTuple, int) with both int and long value.
    • canBeValue

      public abstract boolean canBeValue()
      This method is called to check if the column Type of the value can be of the specified Primitive.
      Returns:
      the Primitive of the column type
    • isInstance

      public abstract boolean isInstance(Object obj)
      check whether the input object is of the primitive type without coercion.