diff --git a/java/src/main/java/ai/rapids/cudf/ColumnView.java b/java/src/main/java/ai/rapids/cudf/ColumnView.java index 5543f02d6ba..331c5b08764 100644 --- a/java/src/main/java/ai/rapids/cudf/ColumnView.java +++ b/java/src/main/java/ai/rapids/cudf/ColumnView.java @@ -1304,9 +1304,24 @@ public ColumnVector castTo(DType type) { * types must match. * @param type the type you want to go to. * @return a ColumnView that cannot outlive the Column that owns the actual data it points to. + * @deprecated this has changed to bit_cast in C++ so use that name instead */ + @Deprecated public ColumnView logicalCastTo(DType type) { - return new ColumnView(logicalCastTo(getNativeView(), + return bitCastTo(type); + } + + /** + * Zero-copy cast between types with the same underlying length. + * + * Similar to bit_cast in C++. This will take the underlying data and create new metadata + * so it is interpreted as a new type. Not all types are supported the width of the + * types must match. + * @param type the type you want to go to. + * @return a ColumnView that cannot outlive the Column that owns the actual data it points to. + */ + public ColumnView bitCastTo(DType type) { + return new ColumnView(bitCastTo(getNativeView(), type.typeId.getNativeId(), type.getScale())); } @@ -2607,7 +2622,7 @@ private static native long stringReplaceWithBackrefs(long columnView, String pat private static native long castTo(long nativeHandle, int type, int scale); - private static native long logicalCastTo(long nativeHandle, int type, int scale); + private static native long bitCastTo(long nativeHandle, int type, int scale); private static native long byteListCast(long nativeHandle, boolean config); diff --git a/java/src/main/native/src/ColumnViewJni.cpp b/java/src/main/native/src/ColumnViewJni.cpp index 47aa30e5d31..a0613f9b73f 100644 --- a/java/src/main/native/src/ColumnViewJni.cpp +++ b/java/src/main/native/src/ColumnViewJni.cpp @@ -760,16 +760,16 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_castTo(JNIEnv *env, jclas CATCH_STD(env, 0); } -JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_logicalCastTo(JNIEnv *env, jclass, - jlong handle, jint type, - jint scale) { +JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_bitCastTo(JNIEnv *env, jclass, + jlong handle, jint type, + jint scale) { JNI_NULL_CHECK(env, handle, "native handle is null", 0); try { cudf::jni::auto_set_device(env); cudf::column_view *column = reinterpret_cast(handle); cudf::data_type n_data_type = cudf::jni::make_data_type(type, scale); std::unique_ptr result = std::make_unique(); - *result = cudf::logical_cast(*column, n_data_type); + *result = cudf::bit_cast(*column, n_data_type); return reinterpret_cast(result.release()); } CATCH_STD(env, 0); diff --git a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java index 9dba4c4c184..a3500ae86ef 100644 --- a/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java +++ b/java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java @@ -2061,10 +2061,10 @@ void emptyStringColumnFindReplaceAll() { } @Test - void testLogicalCast() { + void testBitCast() { try (ColumnVector cv = ColumnVector.decimalFromLongs(-2, 1L, 2L, 100L, 552L); ColumnVector expected = ColumnVector.fromLongs(1L, 2L, 100L, 552L); - ColumnView casted = cv.logicalCastTo(DType.INT64)) { + ColumnView casted = cv.bitCastTo(DType.INT64)) { assertColumnsAreEqual(expected, casted); } }