jackylee-ch commented on code in PR #12211:
URL: https://github.com/apache/gluten/pull/12211#discussion_r3434168059


##########
cpp/core/jni/JniWrapper.cc:
##########
@@ -1476,6 +1510,31 @@ JNIEXPORT void JNICALL 
Java_org_apache_gluten_vectorized_ColumnarBatchSerializer
   JNI_METHOD_END()
 }
 
+JNIEXPORT jlong JNICALL
+Java_org_apache_gluten_vectorized_ColumnarBatchSerializerJniWrapper_deserializeWithProjection(
 // NOLINT
+    JNIEnv* env,
+    jobject wrapper,
+    jlong serializerHandle,
+    jbyteArray data,
+    jintArray requestedCols) {
+  JNI_METHOD_START
+  auto ctx = getRuntime(env, wrapper);
+  auto serializer = 
ObjectStore::retrieve<ColumnarBatchSerializer>(serializerHandle);
+  GLUTEN_DCHECK(serializer != nullptr, "ColumnarBatchSerializer cannot be 
null");
+  int32_t size = env->GetArrayLength(data);
+  auto safeData = getByteArrayElementsSafe(env, data);
+  // null requestedCols → all columns (nullopt); non-null (including int[0]) → 
selection.
+  std::optional<std::vector<int32_t>> requestedOpt;
+  if (requestedCols != nullptr) {
+    jsize nCols = env->GetArrayLength(requestedCols);
+    auto safeCols = getIntArrayElementsSafe(env, requestedCols);
+    requestedOpt = std::vector<int32_t>(safeCols.elems(), safeCols.elems() + 
nCols);
+  }

Review Comment:
   Fixed in 57d491434. The `nCols == 0` case (the `count(*)` zero-column 
projection, where Scala passes `Array.empty[Int]`) is now handled explicitly 
via `requestedOpt.emplace()` before any pointer arithmetic, so we never form 
`nullptr + 0` from `getIntArrayElementsSafe` on an empty `jintArray`. Thanks 
for catching this.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to