You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2021/04/29 16:43:21 UTC

[GitHub] [arrow] zhztheplayer commented on a change in pull request #10108: ARROW-11776: [Java][Dataset] Support writing to files within dataset scanner via JNI

zhztheplayer commented on a change in pull request #10108:
URL: https://github.com/apache/arrow/pull/10108#discussion_r623221239



##########
File path: cpp/src/jni/dataset/jni_util.cc
##########
@@ -211,32 +234,140 @@ std::vector<std::string> ToStringVector(JNIEnv* env, jobjectArray& str_array) {
   return vector;
 }
 
-arrow::Result<jbyteArray> ToSchemaByteArray(JNIEnv* env,
-                                            std::shared_ptr<arrow::Schema> schema) {
-  ARROW_ASSIGN_OR_RAISE(
-      std::shared_ptr<arrow::Buffer> buffer,
-      arrow::ipc::SerializeSchema(*schema, arrow::default_memory_pool()))
+Result<jbyteArray> ToSchemaByteArray(JNIEnv* env, std::shared_ptr<Schema> schema) {
+  ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Buffer> buffer,
+                        ipc::SerializeSchema(*schema, default_memory_pool()))
 
   jbyteArray out = env->NewByteArray(buffer->size());
   auto src = reinterpret_cast<const jbyte*>(buffer->data());
   env->SetByteArrayRegion(out, 0, buffer->size(), src);
   return out;
 }
 
-arrow::Result<std::shared_ptr<arrow::Schema>> FromSchemaByteArray(
-    JNIEnv* env, jbyteArray schemaBytes) {
-  arrow::ipc::DictionaryMemo in_memo;
+Result<std::shared_ptr<Schema>> FromSchemaByteArray(JNIEnv* env, jbyteArray schemaBytes) {
+  ipc::DictionaryMemo in_memo;
   int schemaBytes_len = env->GetArrayLength(schemaBytes);
   jbyte* schemaBytes_data = env->GetByteArrayElements(schemaBytes, nullptr);
-  auto serialized_schema = std::make_shared<arrow::Buffer>(
+  auto serialized_schema = std::make_shared<Buffer>(
       reinterpret_cast<uint8_t*>(schemaBytes_data), schemaBytes_len);
-  arrow::io::BufferReader buf_reader(serialized_schema);
-  ARROW_ASSIGN_OR_RAISE(std::shared_ptr<arrow::Schema> schema,
-                        arrow::ipc::ReadSchema(&buf_reader, &in_memo))
+  io::BufferReader buf_reader(serialized_schema);
+  ARROW_ASSIGN_OR_RAISE(std::shared_ptr<Schema> schema,
+                        ipc::ReadSchema(&buf_reader, &in_memo))
   env->ReleaseByteArrayElements(schemaBytes, schemaBytes_data, JNI_ABORT);
   return schema;
 }
 
+Status SetSingleField(std::shared_ptr<ArrayData> array_data,
+                      UnsafeNativeManagedRecordBatchProto& batch_proto) {
+  FieldProto* field_adder = batch_proto.add_fields();
+  field_adder->set_length(array_data->length);
+  field_adder->set_nullcount(array_data->null_count);
+
+  std::vector<std::shared_ptr<Buffer>> buffers;
+  for (const auto& buffer : array_data->buffers) {
+    buffers.push_back(buffer);
+  }

Review comment:
       fixed in https://github.com/apache/arrow/pull/10201/commits/c16e0cb5c29624c1330f4bd1df6e6ddcb954861e, PR #10201 




-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org