Class Scalar

java.lang.Object
ai.rapids.cudf.Scalar
All Implemented Interfaces:
BinaryOperable, AutoCloseable

public final class Scalar extends Object implements AutoCloseable, BinaryOperable
A single scalar value.
  • Constructor Details

    • Scalar

      public Scalar(DType type, long scalarHandle)
      Constructor to create a scalar from a native handle and a type.
      Parameters:
      type - The type of the scalar
      scalarHandle - The native handle (pointer address) to the scalar data
  • Method Details

    • fromNull

      public static Scalar fromNull(DType type)
    • fromBool

      public static Scalar fromBool(boolean value)
    • fromBool

      public static Scalar fromBool(Boolean value)
    • fromByte

      public static Scalar fromByte(byte value)
    • fromByte

      public static Scalar fromByte(Byte value)
    • fromUnsignedByte

      public static Scalar fromUnsignedByte(byte value)
    • fromUnsignedByte

      public static Scalar fromUnsignedByte(Byte value)
    • fromShort

      public static Scalar fromShort(short value)
    • fromShort

      public static Scalar fromShort(Short value)
    • fromUnsignedShort

      public static Scalar fromUnsignedShort(short value)
    • fromUnsignedShort

      public static Scalar fromUnsignedShort(Short value)
    • durationDaysFromInt

      public static Scalar durationDaysFromInt(int value)
      Returns a DURATION_DAYS scalar
      Parameters:
      value - - days
      Returns:
      - Scalar value
    • durationDaysFromInt

      public static Scalar durationDaysFromInt(Integer value)
      Returns a DURATION_DAYS scalar
      Parameters:
      value - - days
      Returns:
      - Scalar value
    • fromInt

      public static Scalar fromInt(int value)
    • fromInt

      public static Scalar fromInt(Integer value)
    • fromUnsignedInt

      public static Scalar fromUnsignedInt(int value)
    • fromUnsignedInt

      public static Scalar fromUnsignedInt(Integer value)
    • fromLong

      public static Scalar fromLong(long value)
    • fromLong

      public static Scalar fromLong(Long value)
    • fromUnsignedLong

      public static Scalar fromUnsignedLong(long value)
    • fromUnsignedLong

      public static Scalar fromUnsignedLong(Long value)
    • fromFloat

      public static Scalar fromFloat(float value)
    • fromDecimal

      public static Scalar fromDecimal(int scale, int unscaledValue)
    • fromDecimal

      public static Scalar fromDecimal(int scale, long unscaledValue)
    • fromDecimal

      public static Scalar fromDecimal(int scale, BigInteger unscaledValue)
    • fromFloat

      public static Scalar fromFloat(Float value)
    • fromDouble

      public static Scalar fromDouble(double value)
    • fromDouble

      public static Scalar fromDouble(Double value)
    • fromDecimal

      public static Scalar fromDecimal(BigDecimal value)
    • fromDecimal

      public static Scalar fromDecimal(BigInteger unscaledValue, DType dt)
    • timestampDaysFromInt

      public static Scalar timestampDaysFromInt(int value)
    • timestampDaysFromInt

      public static Scalar timestampDaysFromInt(Integer value)
    • durationFromLong

      public static Scalar durationFromLong(DType type, long value)
      Returns a duration scalar based on the type parameter.
      Parameters:
      type - - dtype of scalar to be returned
      value - - corresponding value for the scalar
      Returns:
      - Scalar of the respective type
    • durationFromLong

      public static Scalar durationFromLong(DType type, Long value)
      Returns a duration scalar based on the type parameter.
      Parameters:
      type - - dtype of scalar to be returned
      value - - corresponding value for the scalar
      Returns:
      - Scalar of the respective type
    • timestampFromLong

      public static Scalar timestampFromLong(DType type, long value)
    • timestampFromLong

      public static Scalar timestampFromLong(DType type, Long value)
    • fromString

      public static Scalar fromString(String value)
    • fromUTF8String

      public static Scalar fromUTF8String(byte[] value)
      Creates a String scalar from an array of UTF8 bytes.
      Parameters:
      value - the array of UTF8 bytes
      Returns:
      a String scalar
    • listFromNull

      public static Scalar listFromNull(HostColumnVector.DataType elementType)
      Creates a null scalar of list type. Having this special API because the element type is required to build an empty nested column as the underlying column of the list scalar.
      Parameters:
      elementType - the data type of the element in the list.
      Returns:
      a null scalar of list type
    • listFromColumnView

      public static Scalar listFromColumnView(ColumnView list)
      Creates a scalar of list from a ColumnView. All the rows in the ColumnView will be copied into the Scalar. So the ColumnView can be closed after this call completes.
    • structFromNull

      public static Scalar structFromNull(HostColumnVector.DataType... elementTypes)
      Creates a null scalar of struct type.
      Parameters:
      elementTypes - data types of children in the struct
      Returns:
      a null scalar of struct type
    • structFromColumnViews

      public static Scalar structFromColumnViews(ColumnView... columns)
      Creates a scalar of struct from a ColumnView.
      Parameters:
      columns - children columns of struct
      Returns:
      a Struct scalar
    • getScalarHandle

      public long getScalarHandle()
      Get the native handle (native pointer address) for the scalar.
      Returns:
      The native handle
    • incRefCount

      public Scalar incRefCount()
      Increment the reference count for this scalar. You need to call close on this to decrement the reference count again.
    • close

      public void close()
      Free the memory associated with a scalar.
      Specified by:
      close in interface AutoCloseable
    • getType

      public DType getType()
      Description copied from interface: BinaryOperable
      Get the type of this data.
      Specified by:
      getType in interface BinaryOperable
    • isValid

      public boolean isValid()
    • getBoolean

      public boolean getBoolean()
      Returns the scalar value as a boolean.
    • getByte

      public byte getByte()
      Returns the scalar value as a byte.
    • getShort

      public short getShort()
      Returns the scalar value as a short.
    • getInt

      public int getInt()
      Returns the scalar value as an int.
    • getLong

      public long getLong()
      Returns the scalar value as a long.
    • getBigInteger

      public byte[] getBigInteger()
      Returns the BigDecimal unscaled scalar value as a byte array.
    • getFloat

      public float getFloat()
      Returns the scalar value as a float.
    • getDouble

      public double getDouble()
      Returns the scalar value as a double.
    • getBigDecimal

      public BigDecimal getBigDecimal()
      Returns the scalar value as a BigDecimal.
    • getJavaString

      public String getJavaString()
      Returns the scalar value as a Java string.
    • getUTF8

      public byte[] getUTF8()
      Returns the scalar value as UTF-8 data.
    • getListAsColumnView

      public ColumnView getListAsColumnView()
      Returns the scalar value as a ColumnView. Callers should close the returned ColumnView to avoid memory leak. The returned ColumnView is only valid as long as the Scalar remains valid. If the Scalar is closed before this ColumnView is closed, using this ColumnView will result in undefined behavior.
    • getChildrenFromStructScalar

      public ColumnView[] getChildrenFromStructScalar()
      Fetches views of children columns from struct scalar. The returned ColumnViews should be closed appropriately. Otherwise, a native memory leak will occur.
      Returns:
      array of column views refer to children of struct scalar
    • binaryOp

      public ColumnVector binaryOp(BinaryOp op, BinaryOperable rhs, DType outType)
      Description copied from interface: BinaryOperable
      Multiple different binary operations.
      Specified by:
      binaryOp in interface BinaryOperable
      Parameters:
      op - the operation to perform
      rhs - the rhs of the operation
      outType - the type of output you want.
      Returns:
      the result
    • equals

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

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

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

      public Scalar repeatString(int repeatTimes)
      Repeat the given string scalar a number of times specified by the repeatTimes parameter. If that parameter has a non-positive value, an empty (valid) string scalar will be returned. An invalid input scalar will always result in an invalid output scalar regardless of the value of repeatTimes.
      Parameters:
      repeatTimes - The number of times the input string is copied to the output.
      Returns:
      The resulting scalar containing repeated result of the current string.