Package ai.rapids.cudf
Class Scalar
java.lang.Object
ai.rapids.cudf.Scalar
- All Implemented Interfaces:
BinaryOperable
,AutoCloseable
A single scalar value.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbinaryOp
(BinaryOp op, BinaryOperable rhs, DType outType) Multiple different binary operations.void
close()
Free the memory associated with a scalar.static Scalar
durationDaysFromInt
(int value) Returns a DURATION_DAYS scalarstatic Scalar
durationDaysFromInt
(Integer value) Returns a DURATION_DAYS scalarstatic Scalar
durationFromLong
(DType type, long value) Returns a duration scalar based on the type parameter.static Scalar
durationFromLong
(DType type, Long value) Returns a duration scalar based on the type parameter.boolean
static Scalar
fromBool
(boolean value) static Scalar
static Scalar
fromByte
(byte value) static Scalar
static Scalar
fromDecimal
(int scale, int unscaledValue) static Scalar
fromDecimal
(int scale, long unscaledValue) static Scalar
fromDecimal
(int scale, BigInteger unscaledValue) static Scalar
fromDecimal
(BigDecimal value) static Scalar
fromDecimal
(BigInteger unscaledValue, DType dt) static Scalar
fromDouble
(double value) static Scalar
fromDouble
(Double value) static Scalar
fromFloat
(float value) static Scalar
static Scalar
fromInt
(int value) static Scalar
static Scalar
fromLong
(long value) static Scalar
static Scalar
static Scalar
fromShort
(short value) static Scalar
static Scalar
fromString
(String value) static Scalar
fromUnsignedByte
(byte value) static Scalar
fromUnsignedByte
(Byte value) static Scalar
fromUnsignedInt
(int value) static Scalar
fromUnsignedInt
(Integer value) static Scalar
fromUnsignedLong
(long value) static Scalar
fromUnsignedLong
(Long value) static Scalar
fromUnsignedShort
(short value) static Scalar
fromUnsignedShort
(Short value) static Scalar
fromUTF8String
(byte[] value) Creates a String scalar from an array of UTF8 bytes.Returns the scalar value as a BigDecimal.byte[]
Returns the BigDecimal unscaled scalar value as a byte array.boolean
Returns the scalar value as a boolean.byte
getByte()
Returns the scalar value as a byte.Fetches views of children columns from struct scalar.double
Returns the scalar value as a double.float
getFloat()
Returns the scalar value as a float.int
getInt()
Returns the scalar value as an int.Returns the scalar value as a Java string.Returns the scalar value as a ColumnView.long
getLong()
Returns the scalar value as a long.long
Get the native handle (native pointer address) for the scalar.short
getShort()
Returns the scalar value as a short.getType()
Get the type of this data.byte[]
getUTF8()
Returns the scalar value as UTF-8 data.int
hashCode()
Increment the reference count for this scalar.boolean
isValid()
static Scalar
listFromColumnView
(ColumnView list) Creates a scalar of list from a ColumnView.static Scalar
listFromNull
(HostColumnVector.DataType elementType) Creates a null scalar of list type.repeatString
(int repeatTimes) Repeat the given string scalar a number of times specified by therepeatTimes
parameter.static Scalar
structFromColumnViews
(ColumnView... columns) Creates a scalar of struct from a ColumnView.static Scalar
structFromNull
(HostColumnVector.DataType... elementTypes) Creates a null scalar of struct type.static Scalar
timestampDaysFromInt
(int value) static Scalar
timestampDaysFromInt
(Integer value) static Scalar
timestampFromLong
(DType type, long value) static Scalar
timestampFromLong
(DType type, Long value) toString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface ai.rapids.cudf.BinaryOperable
add, add, and, and, arctan2, arctan2, bitAnd, bitAnd, bitOr, bitOr, bitXor, bitXor, div, div, equalTo, equalTo, equalToNullAware, equalToNullAware, floorDiv, floorDiv, greaterOrEqualTo, greaterOrEqualTo, greaterThan, greaterThan, lessOrEqualTo, lessOrEqualTo, lessThan, lessThan, log, log, maxNullAware, maxNullAware, minNullAware, minNullAware, mod, mod, mul, mul, notEqualTo, notEqualTo, notEqualToNullAware, notEqualToNullAware, or, or, pmod, pmod, pow, pow, shiftLeft, shiftLeft, shiftRight, shiftRight, shiftRightUnsigned, shiftRightUnsigned, sub, sub, trueDiv, trueDiv
-
Constructor Details
-
Scalar
Constructor to create a scalar from a native handle and a type.- Parameters:
type
- The type of the scalarscalarHandle
- The native handle (pointer address) to the scalar data
-
-
Method Details
-
fromNull
-
fromBool
-
fromBool
-
fromByte
-
fromByte
-
fromUnsignedByte
-
fromUnsignedByte
-
fromShort
-
fromShort
-
fromUnsignedShort
-
fromUnsignedShort
-
durationDaysFromInt
Returns a DURATION_DAYS scalar- Parameters:
value
- - days- Returns:
- - Scalar value
-
durationDaysFromInt
Returns a DURATION_DAYS scalar- Parameters:
value
- - days- Returns:
- - Scalar value
-
fromInt
-
fromInt
-
fromUnsignedInt
-
fromUnsignedInt
-
fromLong
-
fromLong
-
fromUnsignedLong
-
fromUnsignedLong
-
fromFloat
-
fromDecimal
-
fromDecimal
-
fromDecimal
-
fromFloat
-
fromDouble
-
fromDouble
-
fromDecimal
-
fromDecimal
-
timestampDaysFromInt
-
timestampDaysFromInt
-
durationFromLong
Returns a duration scalar based on the type parameter.- Parameters:
type
- - dtype of scalar to be returnedvalue
- - corresponding value for the scalar- Returns:
- - Scalar of the respective type
-
durationFromLong
Returns a duration scalar based on the type parameter.- Parameters:
type
- - dtype of scalar to be returnedvalue
- - corresponding value for the scalar- Returns:
- - Scalar of the respective type
-
timestampFromLong
-
timestampFromLong
-
fromString
-
fromUTF8String
Creates a String scalar from an array of UTF8 bytes.- Parameters:
value
- the array of UTF8 bytes- Returns:
- a String scalar
-
listFromNull
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
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
Creates a null scalar of struct type.- Parameters:
elementTypes
- data types of children in the struct- Returns:
- a null scalar of struct type
-
structFromColumnViews
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
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 interfaceAutoCloseable
-
getType
Description copied from interface:BinaryOperable
Get the type of this data.- Specified by:
getType
in interfaceBinaryOperable
-
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
Returns the scalar value as a BigDecimal. -
getJavaString
Returns the scalar value as a Java string. -
getUTF8
public byte[] getUTF8()Returns the scalar value as UTF-8 data. -
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
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
Description copied from interface:BinaryOperable
Multiple different binary operations.- Specified by:
binaryOp
in interfaceBinaryOperable
- Parameters:
op
- the operation to performrhs
- the rhs of the operationoutType
- the type of output you want.- Returns:
- the result
-
equals
-
hashCode
public int hashCode() -
toString
-
repeatString
Repeat the given string scalar a number of times specified by therepeatTimes
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 ofrepeatTimes
.- 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.
-