Skip to content

Commit 816d602

Browse files
authored
Create utility dir arrow/jniutil (#27)
* Create utility dir arrow/jniutil * fix
1 parent b8bb16a commit 816d602

File tree

8 files changed

+75
-42
lines changed

8 files changed

+75
-42
lines changed

cpp/cmake_modules/DefineOptions.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
238238

239239
define_option(ARROW_JNI "Build the Arrow JNI lib" OFF)
240240

241+
define_option(ARROW_JNIUTIL "Build Arrow JNI utilities" ON)
242+
241243
define_option(ARROW_JSON "Build Arrow with JSON support (requires RapidJSON)" OFF)
242244

243245
define_option(ARROW_MIMALLOC "Build the Arrow mimalloc-based allocator" OFF)

cpp/src/arrow/CMakeLists.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,14 @@ if(ARROW_FILESYSTEM)
450450
list(APPEND ARROW_TESTING_SRCS filesystem/test_util.cc)
451451
endif()
452452

453+
if(ARROW_JNIUTIL)
454+
find_package(JNI REQUIRED)
455+
list(APPEND ARROW_SRCS
456+
jniutil/jni_util.cc)
457+
458+
set(ARROW_PRIVATE_INCLUDES ${ARROW_PRIVATE_INCLUDES} ${JNI_INCLUDE_DIRS})
459+
endif()
460+
453461
if(ARROW_IPC)
454462
list(APPEND ARROW_SRCS
455463
ipc/dictionary.cc
@@ -516,7 +524,9 @@ add_arrow_lib(arrow
516524
SHARED_INSTALL_INTERFACE_LIBS
517525
${ARROW_SHARED_INSTALL_INTERFACE_LIBS}
518526
STATIC_INSTALL_INTERFACE_LIBS
519-
${ARROW_STATIC_INSTALL_INTERFACE_LIBS})
527+
${ARROW_STATIC_INSTALL_INTERFACE_LIBS}
528+
PRIVATE_INCLUDES
529+
${JNI_INCLUDE_DIRS})
520530

521531
add_dependencies(arrow ${ARROW_LIBRARIES})
522532

@@ -700,6 +710,10 @@ if(ARROW_IPC)
700710
add_subdirectory(ipc)
701711
endif()
702712

713+
if(ARROW_JNIUTIL)
714+
add_subdirectory(jniutil)
715+
endif()
716+
703717
if(ARROW_JSON)
704718
add_subdirectory(json)
705719
endif()
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitationsn
16+
# under the License.
17+
18+
#
19+
# arrow_dataset_jni
20+
#
21+
22+
arrow_install_all_headers("arrow/jniutil")
23+
24+
find_package(JNI REQUIRED)
25+
26+
add_arrow_test(arrow_jniutil_test
27+
SOURCES
28+
jni_util_test.cc
29+
jni_util.cc
30+
EXTRA_INCLUDES
31+
${JNI_INCLUDE_DIRS})
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
#include "jni/dataset/jni_util.h"
1918
#include "arrow/ipc/metadata_internal.h"
19+
#include "arrow/jniutil/jni_util.h"
2020
#include "arrow/util/base64.h"
2121
#include "arrow/util/key_value_metadata.h"
2222
#include "arrow/util/logging.h"
@@ -27,12 +27,10 @@
2727
#include <flatbuffers/flatbuffers.h>
2828

2929
namespace arrow {
30+
namespace jniutil {
3031

3132
namespace flatbuf = org::apache::arrow::flatbuf;
3233

33-
namespace dataset {
34-
namespace jni {
35-
3634
class ReservationListenableMemoryPool::Impl {
3735
public:
3836
explicit Impl(MemoryPool* pool, std::shared_ptr<ReservationListener> listener,
@@ -427,6 +425,5 @@ Result<std::shared_ptr<RecordBatch>> DeserializeUnsafeFromJava(
427425
return RecordBatch::Make(schema, length, columns_array_data);
428426
}
429427

430-
} // namespace jni
431-
} // namespace dataset
428+
} // namespace jniutil
432429
} // namespace arrow
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
#include <jni.h>
2828

2929
namespace arrow {
30-
namespace dataset {
31-
namespace jni {
30+
namespace jniutil {
3231

3332
Status CheckException(JNIEnv* env);
3433

@@ -140,6 +139,5 @@ class ReservationListenableMemoryPool : public MemoryPool {
140139
std::unique_ptr<Impl> impl_;
141140
};
142141

143-
} // namespace jni
144-
} // namespace dataset
142+
} // namespace jniutil
145143
} // namespace arrow
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919

2020
#include "arrow/memory_pool.h"
2121
#include "arrow/testing/gtest_util.h"
22-
#include "jni/dataset/jni_util.h"
22+
#include "arrow/jniutil/jni_util.h"
2323

2424
namespace arrow {
25-
namespace dataset {
26-
namespace jni {
25+
namespace jniutil {
2726

2827
class MyListener : public ReservationListener {
2928
public:
@@ -129,6 +128,5 @@ TEST(ReservationListenableMemoryPool, BlockSize2) {
129128
ASSERT_EQ(1, listener->release_count());
130129
}
131130

132-
} // namespace jni
133-
} // namespace dataset
131+
} // namespace jniutil
134132
} // namespace arrow

cpp/src/jni/dataset/CMakeLists.txt

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ add_custom_target(arrow_dataset_jni_proto ALL DEPENDS ${PROTO_OUTPUT_FILES})
5959
set(PROTO_SRCS "${PROTO_OUTPUT_DIR}/DTypes.pb.cc")
6060
set(PROTO_HDRS "${PROTO_OUTPUT_DIR}/DTypes.pb.h")
6161

62-
set(ARROW_DATASET_JNI_SOURCES jni_wrapper.cc jni_util.cc ${PROTO_SRCS})
62+
set(ARROW_DATASET_JNI_SOURCES jni_wrapper.cc ${PROTO_SRCS})
6363

6464
add_arrow_lib(arrow_dataset_jni
6565
BUILD_SHARED
@@ -81,10 +81,3 @@ add_arrow_lib(arrow_dataset_jni
8181
arrow_dataset_jni_proto)
8282

8383
add_dependencies(arrow_dataset_jni ${ARROW_DATASET_JNI_LIBRARIES})
84-
85-
add_arrow_test(dataset_jni_test
86-
SOURCES
87-
jni_util_test.cc
88-
jni_util.cc
89-
EXTRA_INCLUDES
90-
${JNI_INCLUDE_DIRS})

cpp/src/jni/dataset/jni_wrapper.cc

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
#include "arrow/dataset/file_base.h"
2424
#include "arrow/filesystem/localfs.h"
2525
#include "arrow/ipc/api.h"
26+
#include "arrow/jniutil/jni_util.h"
2627
#include "arrow/util/iterator.h"
2728

2829
#include "jni/dataset/DTypes.pb.h"
29-
#include "jni/dataset/jni_util.h"
3030

3131
#include "org_apache_arrow_dataset_file_JniWrapper.h"
3232
#include "org_apache_arrow_dataset_jni_JniWrapper.h"
@@ -89,7 +89,7 @@ arrow::Result<std::shared_ptr<arrow::dataset::FileFormat>> GetFileFormat(
8989
}
9090
}
9191

92-
class ReserveFromJava : public arrow::dataset::jni::ReservationListener {
92+
class ReserveFromJava : public arrow::jniutil::ReservationListener {
9393
public:
9494
ReserveFromJava(JavaVM* vm, jobject java_reservation_listener)
9595
: vm_(vm), java_reservation_listener_(java_reservation_listener) {}
@@ -100,7 +100,7 @@ class ReserveFromJava : public arrow::dataset::jni::ReservationListener {
100100
return arrow::Status::Invalid("JNIEnv was not attached to current thread");
101101
}
102102
env->CallObjectMethod(java_reservation_listener_, reserve_memory_method, size);
103-
RETURN_NOT_OK(arrow::dataset::jni::CheckException(env));
103+
RETURN_NOT_OK(arrow::jniutil::CheckException(env));
104104
return arrow::Status::OK();
105105
}
106106

@@ -110,7 +110,7 @@ class ReserveFromJava : public arrow::dataset::jni::ReservationListener {
110110
return arrow::Status::Invalid("JNIEnv was not attached to current thread");
111111
}
112112
env->CallObjectMethod(java_reservation_listener_, unreserve_memory_method, size);
113-
RETURN_NOT_OK(arrow::dataset::jni::CheckException(env));
113+
RETURN_NOT_OK(arrow::jniutil::CheckException(env));
114114
return arrow::Status::OK();
115115
}
116116

@@ -322,7 +322,7 @@ arrow::Result<std::shared_ptr<arrow::RecordBatch>> FromBytes(
322322
JNIEnv* env, std::shared_ptr<arrow::Schema> schema, jbyteArray bytes) {
323323
ARROW_ASSIGN_OR_RAISE(
324324
std::shared_ptr<arrow::RecordBatch> batch,
325-
arrow::dataset::jni::DeserializeUnsafeFromJava(env, schema, bytes))
325+
arrow::jniutil::DeserializeUnsafeFromJava(env, schema, bytes))
326326
return batch;
327327
}
328328

@@ -347,7 +347,7 @@ arrow::Result<std::shared_ptr<arrow::dataset::Scanner>> MakeJavaDatasetScanner(
347347
}
348348
auto bytes = (jbyteArray)env->CallObjectMethod(
349349
java_serialized_record_batch_iterator, serialized_record_batch_iterator_next);
350-
RETURN_NOT_OK(arrow::dataset::jni::CheckException(env));
350+
RETURN_NOT_OK(arrow::jniutil::CheckException(env));
351351
ARROW_ASSIGN_OR_RAISE(auto batch, FromBytes(env, schema, bytes));
352352
return batch;
353353
});
@@ -363,18 +363,18 @@ arrow::Result<std::shared_ptr<arrow::dataset::Scanner>> MakeJavaDatasetScanner(
363363
}
364364
} // namespace
365365

366-
using arrow::dataset::jni::CreateGlobalClassReference;
367-
using arrow::dataset::jni::CreateNativeRef;
368-
using arrow::dataset::jni::FromSchemaByteArray;
369-
using arrow::dataset::jni::GetMethodID;
370-
using arrow::dataset::jni::JStringToCString;
371-
using arrow::dataset::jni::ReleaseNativeRef;
372-
using arrow::dataset::jni::RetrieveNativeInstance;
373-
using arrow::dataset::jni::ToSchemaByteArray;
374-
using arrow::dataset::jni::ToStringVector;
366+
using arrow::jniutil::CreateGlobalClassReference;
367+
using arrow::jniutil::CreateNativeRef;
368+
using arrow::jniutil::FromSchemaByteArray;
369+
using arrow::jniutil::GetMethodID;
370+
using arrow::jniutil::JStringToCString;
371+
using arrow::jniutil::ReleaseNativeRef;
372+
using arrow::jniutil::RetrieveNativeInstance;
373+
using arrow::jniutil::ToSchemaByteArray;
374+
using arrow::jniutil::ToStringVector;
375375

376-
using arrow::dataset::jni::ReservationListenableMemoryPool;
377-
using arrow::dataset::jni::ReservationListener;
376+
using arrow::jniutil::ReservationListenableMemoryPool;
377+
using arrow::jniutil::ReservationListener;
378378

379379
#define JNI_METHOD_START try {
380380
// macro ended
@@ -659,7 +659,7 @@ JNIEXPORT jbyteArray JNICALL Java_org_apache_arrow_dataset_jni_JniWrapper_nextRe
659659
if (record_batch == nullptr) {
660660
return nullptr; // stream ended
661661
}
662-
return JniGetOrThrow(arrow::dataset::jni::SerializeUnsafeFromNative(env, record_batch));
662+
return JniGetOrThrow(arrow::jniutil::SerializeUnsafeFromNative(env, record_batch));
663663
JNI_METHOD_END(nullptr)
664664
}
665665

0 commit comments

Comments
 (0)