Skip to content

Commit

Permalink
Expose Scalar's constructor and Scalar#getScalarHandle() to public (#…
Browse files Browse the repository at this point in the history
…17580)

This exposes the constructor and `getScalarHandle()` method in `Scalar.java` to the public, allowing them to be called from the outside. Without access to these methods, it was very inconvenient. Workaround has been implemented ([spark-rapids-jni/CudfAccessor.java](https://github.com/NVIDIA/spark-rapids-jni/blob/5231d4d82603d488b95ea259874a26f9f4354005/src/main/java/ai/rapids/cudf/CudfAccessor.java#L21)) to overcome this but it is better to have the issue addressed from the root.

Partially contributes to NVIDIA/spark-rapids-jni#1307.

Authors:
  - Nghia Truong (https://github.com/ttnghia)

Approvers:
  - Jason Lowe (https://github.com/jlowe)

URL: #17580
  • Loading branch information
ttnghia authored Dec 12, 2024
1 parent ebe5bad commit 32548b0
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions java/src/main/java/ai/rapids/cudf/Scalar.java
Original file line number Diff line number Diff line change
Expand Up @@ -521,13 +521,28 @@ private static ColumnVector buildNullColumnVector(HostColumnVector.DataType host
private static native long makeStructScalar(long[] viewHandles, boolean isValid);
private static native long repeatString(long scalarHandle, int repeatTimes);

Scalar(DType type, long scalarHandle) {
/**
* Constructor to create a scalar from a native handle and a type.
*
* @param type The type of the scalar
* @param scalarHandle The native handle (pointer address) to the scalar data
*/
public Scalar(DType type, long scalarHandle) {
this.type = type;
this.offHeap = new OffHeapState(scalarHandle);
MemoryCleaner.register(this, offHeap);
incRefCount();
}

/**
* Get the native handle (native pointer address) for the scalar.
*
* @return The native handle
*/
public long getScalarHandle() {
return offHeap.scalarHandle;
}

/**
* Increment the reference count for this scalar. You need to call close on this
* to decrement the reference count again.
Expand All @@ -542,10 +557,6 @@ public synchronized Scalar incRefCount() {
return this;
}

long getScalarHandle() {
return offHeap.scalarHandle;
}

/**
* Free the memory associated with a scalar.
*/
Expand Down

0 comments on commit 32548b0

Please sign in to comment.