Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Java] Add JNI bindings for integers_to_hex #14205

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions java/src/main/java/ai/rapids/cudf/ColumnView.java
Original file line number Diff line number Diff line change
Expand Up @@ -4088,6 +4088,8 @@ static DeviceMemoryBufferView getOffsetsBuffer(long viewHandle) {


private static native long isFixedPoint(long viewHandle, int nativeTypeId, int scale);

private static native long toHex(long viewHandle);

/**
* Native method to concatenate a list column of strings (each row is a list of strings),
Expand Down Expand Up @@ -5231,4 +5233,13 @@ static ColumnView[] getColumnViewsFromPointers(long[] nativeHandles) {
}
}
}

/**
* Convert this integer column to hexadecimal column
revans2 marked this conversation as resolved.
Show resolved Hide resolved
* @return new string ColumnVector
*/
public ColumnVector toHex() {
assert getType().isIntegral() : "Only integers are supported";
razajafri marked this conversation as resolved.
Show resolved Hide resolved
return new ColumnVector(toHex(this.getNativeView()));
}
}
19 changes: 19 additions & 0 deletions java/src/main/java/ai/rapids/cudf/DType.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,14 @@ public boolean isDurationType() {
}

/**
* Returns true for strictly Integer types not a type backed by
* ints
*/
public boolean isIntegral() {
return INTEGRALS.contains(this.typeId);
}

/**
* Returns true for nested types
*/
public boolean isNestedType() {
Expand Down Expand Up @@ -506,4 +514,15 @@ public boolean hasOffsets() {
DTypeEnum.STRING,
DTypeEnum.LIST
);

private static final EnumSet<DTypeEnum> INTEGRALS = EnumSet.of(
DTypeEnum.INT8,
DTypeEnum.INT16,
DTypeEnum.INT32,
DTypeEnum.INT64,
DTypeEnum.UINT8,
DTypeEnum.UINT16,
DTypeEnum.UINT32,
DTypeEnum.UINT64
);
}
10 changes: 10 additions & 0 deletions java/src/main/native/src/ColumnViewJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2563,4 +2563,14 @@ Java_ai_rapids_cudf_ColumnView_purgeNonEmptyNulls(JNIEnv *env, jclass, jlong col
CATCH_STD(env, 0);
}

JNIEXPORT jlong JNICALL
Java_ai_rapids_cudf_ColumnView_toHex(JNIEnv *env, jclass, jlong input_ptr) {
JNI_NULL_CHECK(env, input_ptr, "input is null", 0);
try {
cudf::jni::auto_set_device(env);
const cudf::column_view *input = reinterpret_cast<cudf::column_view *>(input_ptr);
return release_as_jlong(cudf::strings::integers_to_hex(*input));
}
CATCH_STD(env, 0);
}
} // extern "C"
10 changes: 10 additions & 0 deletions java/src/test/java/ai/rapids/cudf/ColumnVectorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6876,4 +6876,14 @@ public void testUseAfterFree() {
vector.close();
assertThrows(NullPointerException.class, vector::getDeviceMemorySize);
}

@Test
public void testConvertIntegerToHex() {
try (
ColumnVector input = ColumnVector.fromInts(14, 2621, 50);
ColumnVector expected = ColumnVector.fromStrings("0E", "0A3D", "32");
ColumnVector actual = input.toHex()) {
assertColumnsAreEqual(expected, actual);
}
}
}