Skip to content

Commit

Permalink
Add JNI for substring without 'end' parameter. (#12113)
Browse files Browse the repository at this point in the history
Authors:
  - Liangcai Li (https://github.com/firestarman)

Approvers:
  - Robert (Bobby) Evans (https://github.com/revans2)
  - Nghia Truong (https://github.com/ttnghia)

URL: #12113
  • Loading branch information
firestarman authored Nov 11, 2022
1 parent f87d2b4 commit 3894427
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
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

0 comments on commit 3894427

Please sign in to comment.