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 for substring without 'end' parameter. #12113

Merged
merged 5 commits into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 11 additions & 3 deletions java/src/main/java/ai/rapids/cudf/ColumnView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2632,12 +2632,13 @@ public final ColumnVector stringSplitRecord(String delimiter) {

/**
* Returns a new strings column that contains substrings of the strings in the provided column.
* Overloading subString to support if end index is not provided. Appending -1 to indicate to
* read until end of string.
* The character positions to retrieve in each string are `[start, <the string end>)`..
*
* @param start first character index to begin the substring(inclusive).
*/
public final ColumnVector substring(int start) {
return substring(start, -1);
assert type.equals(DType.STRING) : "column type must be a String";
return new ColumnVector(substringS(getNativeView(), start));
}

/**
Expand Down Expand Up @@ -3983,6 +3984,13 @@ private static native long stringSplitRecord(long nativeHandle, String pattern,
*/
private static native long substring(long columnView, int start, int end) throws CudfException;

/**
* Native method to extract substrings from a given strings column.
* @param columnView native handle of the cudf::column_view being operated on.
* @param start first character index to begin the substrings (inclusive).
*/
private static native long substringS(long columnView, int start) throws CudfException;

/**
* Native method to calculate substring from a given string column.
* @param columnView native handle of the cudf::column_view being operated on.
Expand Down
15 changes: 13 additions & 2 deletions java/src/main/native/src/ColumnViewJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,18 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_binaryOpVS(JNIEnv *env, j
CATCH_STD(env, 0);
}

JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substringS(JNIEnv *env, jclass,
jlong cv_handle, jint start) {
JNI_NULL_CHECK(env, cv_handle, "column is null", 0);
try {
cudf::jni::auto_set_device(env);
auto const cv = reinterpret_cast<cudf::column_view const *>(cv_handle);
auto const scv = cudf::strings_column_view{*cv};
return release_as_jlong(cudf::strings::slice_strings(scv, start));
}
CATCH_STD(env, 0);
}

JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substring(JNIEnv *env, jclass,
jlong column_view, jint start,
jint end) {
Expand All @@ -1405,8 +1417,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_substring(JNIEnv *env, jc
cudf::jni::auto_set_device(env);
cudf::column_view *cv = reinterpret_cast<cudf::column_view *>(column_view);
cudf::strings_column_view scv(*cv);
return release_as_jlong((end == -1 ? cudf::strings::slice_strings(scv, start) :
cudf::strings::slice_strings(scv, start, end)));
return release_as_jlong(cudf::strings::slice_strings(scv, start, end));
}
CATCH_STD(env, 0);
}
Expand Down