From 32548b074bc0350186906c223980acac142ba5a2 Mon Sep 17 00:00:00 2001 From: Nghia Truong <7416935+ttnghia@users.noreply.github.com> Date: Wed, 11 Dec 2024 16:34:28 -0800 Subject: [PATCH] Expose Scalar's constructor and `Scalar#getScalarHandle()` to public (#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 https://github.com/NVIDIA/spark-rapids-jni/issues/1307. Authors: - Nghia Truong (https://github.com/ttnghia) Approvers: - Jason Lowe (https://github.com/jlowe) URL: https://github.com/rapidsai/cudf/pull/17580 --- java/src/main/java/ai/rapids/cudf/Scalar.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/java/src/main/java/ai/rapids/cudf/Scalar.java b/java/src/main/java/ai/rapids/cudf/Scalar.java index 286b5c208c9..f3155bc5860 100644 --- a/java/src/main/java/ai/rapids/cudf/Scalar.java +++ b/java/src/main/java/ai/rapids/cudf/Scalar.java @@ -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. @@ -542,10 +557,6 @@ public synchronized Scalar incRefCount() { return this; } - long getScalarHandle() { - return offHeap.scalarHandle; - } - /** * Free the memory associated with a scalar. */