Scalar#

public final class Scalar implements AutoCloseable, BinaryOperable#

A single scalar value.

Constructor Summary

Scalar(DType type, long scalarHandle)

Constructor to create a scalar from a native handle and a type.

Method Summary

binaryOp(BinaryOp op, BinaryOperable rhs, DType outType)

Multiple different binary operations.

close()

Free the memory associated with a scalar.

durationDaysFromInt(Integer value)

Returns a DURATION_DAYS scalar.

durationDaysFromInt(int value)

Returns a DURATION_DAYS scalar.

durationFromLong(DType type, Long value)

Returns a duration scalar based on the type parameter.

durationFromLong(DType type, long value)

Returns a duration scalar based on the type parameter.

equals(Object o)

fromBool(Boolean value)

fromBool(boolean value)

fromByte(Byte value)

fromByte(byte value)

fromDecimal(BigDecimal value)

fromDecimal(BigInteger unscaledValue, DType dt)

fromDecimal(int scale, BigInteger unscaledValue)

fromDecimal(int scale, int unscaledValue)

fromDecimal(int scale, long unscaledValue)

fromDouble(Double value)

fromDouble(double value)

fromFloat(Float value)

fromFloat(float value)

fromInt(Integer value)

fromInt(int value)

fromLong(Long value)

fromLong(long value)

fromNull(DType type)

fromShort(Short value)

fromShort(short value)

fromString(String value)

fromUnsignedByte(Byte value)

fromUnsignedByte(byte value)

fromUnsignedInt(Integer value)

fromUnsignedInt(int value)

fromUnsignedLong(Long value)

fromUnsignedLong(long value)

fromUnsignedShort(Short value)

fromUnsignedShort(short value)

fromUTF8String(byte[] value)

Creates a String scalar from an array of UTF8 bytes.

getBigDecimal()

Returns the scalar value as a BigDecimal.

getBigInteger()

Returns the BigDecimal unscaled scalar value as a byte array.

getBoolean()

Returns the scalar value as a boolean.

getByte()

Returns the scalar value as a byte.

getChildrenFromStructScalar()

Fetches views of children columns from struct scalar.

getDouble()

Returns the scalar value as a double.

getFloat()

Returns the scalar value as a float.

getInt()

Returns the scalar value as an int.

getJavaString()

Returns the scalar value as a Java string.

getListAsColumnView()

Returns the scalar value as a ColumnView.

getLong()

Returns the scalar value as a long.

getScalarHandle()

Get the native handle (native pointer address) for the scalar.

getShort()

Returns the scalar value as a short.

getType()

Get the type of this data.

getUTF8()

Returns the scalar value as UTF-8 data.

hashCode()

incRefCount()

Increment the reference count for this scalar.

isValid()

listFromColumnView(ColumnView list)

Creates a scalar of list from a ColumnView.

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 the repeatTimes parameter.

structFromColumnViews(ColumnView... columns)

Creates a scalar of struct from a ColumnView.

structFromNull(HostColumnVector.DataType... elementTypes)

Creates a null scalar of struct type.

timestampDaysFromInt(Integer value)

timestampDaysFromInt(int value)

timestampFromLong(DType type, Long value)

timestampFromLong(DType type, long value)

toString()

Methods inherited from interface ai.rapids.cudf.BinaryOperable: add, and, arctan2, bitAnd, bitOr, bitXor, div, equalTo, equalToNullAware, floorDiv, greaterOrEqualTo, greaterThan, lessOrEqualTo, lessThan, log, maxNullAware, minNullAware, mod, mul, notEqualTo, notEqualToNullAware, or, pmod, pow, shiftLeft, shiftRight, shiftRightUnsigned, sub, trueDiv

Constructors

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

Methods

public long getScalarHandle()#

Get the native handle (native pointer address) for the scalar.

Returns:

The native handle

public Scalar incRefCount()#

Increment the reference count for this scalar.

You need to call close on this to decrement the reference count again.

public void close()#

Free the memory associated with a scalar.

public DType getType()#

Get the type of this data.

public boolean isValid()#
public boolean getBoolean()#

Returns the scalar value as a boolean.

public byte getByte()#

Returns the scalar value as a byte.

public short getShort()#

Returns the scalar value as a short.

public int getInt()#

Returns the scalar value as an int.

public long getLong()#

Returns the scalar value as a long.

public byte[] getBigInteger()#

Returns the BigDecimal unscaled scalar value as a byte array.

public float getFloat()#

Returns the scalar value as a float.

public double getDouble()#

Returns the scalar value as a double.

public BigDecimal getBigDecimal()#

Returns the scalar value as a BigDecimal.

public String getJavaString()#

Returns the scalar value as a Java string.

public byte[] getUTF8()#

Returns the scalar value as UTF-8 data.

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.

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

public ColumnVector binaryOp(
BinaryOp op,
BinaryOperable rhs,
DType outType
)#

Multiple different binary operations.

Parameters:
  • op – the operation to perform

  • rhs – the rhs of the operation

  • outType – the type of output you want.

Returns:

the result

public boolean equals(Object o)#
public int hashCode()#
public String toString()#
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.

Static Methods

public static Scalar fromNull(DType type)#
public static Scalar fromBool(boolean value)#
public static Scalar fromBool(Boolean value)#
public static Scalar fromByte(byte value)#
public static Scalar fromByte(Byte value)#
public static Scalar fromUnsignedByte(byte value)#
public static Scalar fromUnsignedByte(Byte value)#
public static Scalar fromShort(short value)#
public static Scalar fromShort(Short value)#
public static Scalar fromUnsignedShort(short value)#
public static Scalar fromUnsignedShort(Short value)#
public static Scalar durationDaysFromInt(int value)#

Returns a DURATION_DAYS scalar.

Parameters:

value – - days

Returns:

- Scalar value

public static Scalar durationDaysFromInt(Integer value)#

Returns a DURATION_DAYS scalar.

Parameters:

value – - days

Returns:

- Scalar value

public static Scalar fromInt(int value)#
public static Scalar fromInt(Integer value)#
public static Scalar fromUnsignedInt(int value)#
public static Scalar fromUnsignedInt(Integer value)#
public static Scalar fromLong(long value)#
public static Scalar fromLong(Long value)#
public static Scalar fromUnsignedLong(long value)#
public static Scalar fromUnsignedLong(Long value)#
public static Scalar fromFloat(float value)#
public static Scalar fromDecimal(int scale, int unscaledValue)#
public static Scalar fromDecimal(int scale, long unscaledValue)#
public static Scalar fromDecimal(int scale, BigInteger unscaledValue)#
public static Scalar fromFloat(Float value)#
public static Scalar fromDouble(double value)#
public static Scalar fromDouble(Double value)#
public static Scalar fromDecimal(BigDecimal value)#
public static Scalar fromDecimal(BigInteger unscaledValue, DType dt)#
public static Scalar timestampDaysFromInt(int value)#
public static Scalar timestampDaysFromInt(Integer value)#
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

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

public static Scalar timestampFromLong(DType type, long value)#
public static Scalar timestampFromLong(DType type, Long value)#
public static Scalar fromString(String value)#
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

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

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.

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

public static Scalar structFromColumnViews(ColumnView... columns)#

Creates a scalar of struct from a ColumnView.

Parameters:

columns – children columns of struct

Returns:

a Struct scalar