Skip to content

Commit

Permalink
Accept r-value references in convert_table_for_return(): (#10131)
Browse files Browse the repository at this point in the history
`cudf::jni::convert_table_for_return()` is usually used on tables returned from a libcudf API call.
It currently requires an l-value reference for its table argument. This necessitates parking the result of libcudf call in an avoidable temp variable.
This commit adds the option to use an r-value reference. This allows table expressions to be used directly, reducing clutter.

Note:
  1. The previous signature is retained, because not all call sites can use the r-value 
     interface cleanly. (E.g. when the libcudf call is complex.)
  2. The third argument (vector<unique_ptr<column>>) has been converted from l-ref to r-ref,
     so that an empty default can be introduced.

This commit also includes minor code cleanup in the periphery of calls to `convert_table_for_return()`.

Authors:
  - MithunR (https://github.com/mythrocks)

Approvers:
  - Jason Lowe (https://github.com/jlowe)

URL: #10131
  • Loading branch information
mythrocks authored Jan 27, 2022
1 parent 5dd1c39 commit 7c69dae
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 160 deletions.
3 changes: 3 additions & 0 deletions java/src/main/native/include/jni_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,9 @@ template <typename T> class native_jpointerArray {

T **data() { return reinterpret_cast<T **>(wrapped.data()); }

T *const *begin() const { return data(); }
T *const *end() const { return data() + size(); }

const jlongArray get_jArray() const { return wrapped.get_jArray(); }

jlongArray get_jArray() { return wrapped.get_jArray(); }
Expand Down
22 changes: 10 additions & 12 deletions java/src/main/native/src/ColumnViewJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -561,18 +561,17 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ColumnView_listSortRows(JNIEnv *env,

JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_stringSplit(JNIEnv *env, jclass,
jlong column_view,
jlong delimiter,
jlong delimiter_ptr,
jint max_split) {
JNI_NULL_CHECK(env, column_view, "column is null", 0);
JNI_NULL_CHECK(env, delimiter, "string scalar delimiter is null", 0);
JNI_NULL_CHECK(env, delimiter_ptr, "string scalar delimiter is null", 0);
try {
cudf::jni::auto_set_device(env);
cudf::column_view *cv = reinterpret_cast<cudf::column_view *>(column_view);
cudf::strings_column_view scv(*cv);
cudf::string_scalar *ss_scalar = reinterpret_cast<cudf::string_scalar *>(delimiter);
cudf::strings_column_view const scv{*reinterpret_cast<cudf::column_view *>(column_view)};
auto delimiter = reinterpret_cast<cudf::string_scalar *>(delimiter_ptr);

std::unique_ptr<cudf::table> table_result = cudf::strings::split(scv, *ss_scalar, max_split);
return cudf::jni::convert_table_for_return(env, table_result);
return cudf::jni::convert_table_for_return(env,
cudf::strings::split(scv, *delimiter, max_split));
}
CATCH_STD(env, 0);
}
Expand Down Expand Up @@ -1410,13 +1409,12 @@ JNIEXPORT jlongArray JNICALL Java_ai_rapids_cudf_ColumnView_extractRe(JNIEnv *en

try {
cudf::jni::auto_set_device(env);
cudf::column_view *column_view = reinterpret_cast<cudf::column_view *>(j_view_handle);
cudf::strings_column_view strings_column(*column_view);
cudf::strings_column_view const strings_column{
*reinterpret_cast<cudf::column_view *>(j_view_handle)};
cudf::jni::native_jstring pattern(env, patternObj);

std::unique_ptr<cudf::table> table_result =
cudf::strings::extract(strings_column, pattern.get());
return cudf::jni::convert_table_for_return(env, table_result);
return cudf::jni::convert_table_for_return(
env, cudf::strings::extract(strings_column, pattern.get()));
}
CATCH_STD(env, 0);
}
Expand Down
Loading

0 comments on commit 7c69dae

Please sign in to comment.