mirror of
https://github.com/apache/arrow.git
synced 2026-10-29 00:56:31 +08:00
resolve comments
This commit is contained in:
1 parent
de8529cf18
commit
706c8dcd5a
4 files changed
+41
-27
No files matched your search
@@ -35,7 +35,8 @@ using ORCFileReader = arrow::adapters::orc::ORCFileReader;
|
||||
using RecordBatchReader = arrow::RecordBatchReader;
|
||||
|
||||
static jclass io_exception_class;
|
||||
static jclass exception_class;
|
||||
static jclass illegal_access_exception_class;
|
||||
static jclass illegal_argument_exception_class;
|
||||
|
||||
static jclass orc_field_node_class;
|
||||
static jmethodID orc_field_node_constructor;
|
||||
@@ -66,7 +67,7 @@ jmethodID GetMethodID(JNIEnv* env, jclass this_class, const char* name, const ch
|
||||
if (ret == nullptr) {
|
||||
std::string error_message = "Unable to find method " + std::string(name) +
|
||||
" within signature" + std::string(sig);
|
||||
env->ThrowNew(exception_class, error_message.c_str());
|
||||
env->ThrowNew(illegal_access_exception_class, error_message.c_str());
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -81,6 +82,26 @@ std::string JStringToCString(JNIEnv* env, jstring string) {
|
||||
return std::string(buffer.data(), clen);
|
||||
}
|
||||
|
||||
std::shared_ptr<ORCFileReader> GetFileReader(JNIEnv* env, jlong id) {
|
||||
auto reader = orc_reader_holder_.Lookup(id);
|
||||
if (!reader) {
|
||||
std::string error_message = "invalid reader id " + std::to_string(id);
|
||||
env->ThrowNew(illegal_argument_exception_class, error_message.c_str());
|
||||
}
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
std::shared_ptr<RecordBatchReader> GetStripeReader(JNIEnv* env, jlong id) {
|
||||
auto reader = orc_stripe_reader_holder_.Lookup(id);
|
||||
if (!reader) {
|
||||
std::string error_message = "invalid stripe reader id " + std::to_string(id);
|
||||
env->ThrowNew(illegal_argument_exception_class, error_message.c_str());
|
||||
}
|
||||
|
||||
return reader;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -92,7 +113,10 @@ jint JNI_OnLoad(JavaVM* vm, void* reserved) {
|
||||
}
|
||||
|
||||
io_exception_class = CreateGlobalClassReference(env, "Ljava/io/IOException;");
|
||||
exception_class = CreateGlobalClassReference(env, "Ljava/lang/Exception;");
|
||||
illegal_access_exception_class =
|
||||
CreateGlobalClassReference(env, "Ljava/lang/IllegalAccessException;");
|
||||
illegal_argument_exception_class =
|
||||
CreateGlobalClassReference(env, "Ljava/lang/IllegalArgumentException;");
|
||||
|
||||
orc_field_node_class =
|
||||
CreateGlobalClassReference(env, "Lorg/apache/arrow/adapter/orc/OrcFieldNode;");
|
||||
@@ -118,7 +142,8 @@ void JNI_OnUnload(JavaVM* vm, void* reserved) {
|
||||
JNIEnv* env;
|
||||
vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION);
|
||||
env->DeleteGlobalRef(io_exception_class);
|
||||
env->DeleteGlobalRef(exception_class);
|
||||
env->DeleteGlobalRef(illegal_access_exception_class);
|
||||
env->DeleteGlobalRef(illegal_argument_exception_class);
|
||||
env->DeleteGlobalRef(orc_field_node_class);
|
||||
env->DeleteGlobalRef(orc_memory_class);
|
||||
env->DeleteGlobalRef(record_batch_class);
|
||||
@@ -165,7 +190,7 @@ JNIEXPORT void JNICALL Java_org_apache_arrow_adapter_orc_OrcReaderJniWrapper_clo
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_org_apache_arrow_adapter_orc_OrcReaderJniWrapper_seek(
|
||||
JNIEnv* env, jobject this_obj, jlong id, jint row_number) {
|
||||
auto reader = orc_reader_holder_.Lookup(id);
|
||||
auto reader = GetFileReader(env, id);
|
||||
return reader->Seek(row_number).ok();
|
||||
}
|
||||
|
||||
@@ -173,7 +198,7 @@ JNIEXPORT jint JNICALL
|
||||
Java_org_apache_arrow_adapter_orc_OrcReaderJniWrapper_getNumberOfStripes(JNIEnv* env,
|
||||
jobject this_obj,
|
||||
jlong id) {
|
||||
auto reader = orc_reader_holder_.Lookup(id);
|
||||
auto reader = GetFileReader(env, id);
|
||||
return reader->NumberOfStripes();
|
||||
}
|
||||
|
||||
@@ -182,11 +207,7 @@ Java_org_apache_arrow_adapter_orc_OrcReaderJniWrapper_nextStripeReader(JNIEnv* e
|
||||
jobject this_obj,
|
||||
jlong id,
|
||||
jlong batch_size) {
|
||||
auto reader = orc_reader_holder_.Lookup(id);
|
||||
if (!reader) {
|
||||
std::string error_message = "invalid reader id " + std::to_string(id);
|
||||
env->ThrowNew(exception_class, error_message.c_str());
|
||||
}
|
||||
auto reader = GetFileReader(env, id);
|
||||
|
||||
std::shared_ptr<RecordBatchReader> stripe_reader;
|
||||
auto status = reader->NextStripeReader(batch_size, &stripe_reader);
|
||||
@@ -206,11 +227,7 @@ JNIEXPORT jbyteArray JNICALL
|
||||
Java_org_apache_arrow_adapter_orc_OrcStripeReaderJniWrapper_getSchema(JNIEnv* env,
|
||||
jclass this_cls,
|
||||
jlong id) {
|
||||
auto stripe_reader = orc_stripe_reader_holder_.Lookup(id);
|
||||
if (!stripe_reader) {
|
||||
std::string error_message = "invalid stripe reader id " + std::to_string(id);
|
||||
env->ThrowNew(exception_class, error_message.c_str());
|
||||
}
|
||||
auto stripe_reader = GetStripeReader(env, id);
|
||||
|
||||
auto schema = stripe_reader->schema();
|
||||
|
||||
@@ -231,11 +248,7 @@ JNIEXPORT jobject JNICALL
|
||||
Java_org_apache_arrow_adapter_orc_OrcStripeReaderJniWrapper_next(JNIEnv* env,
|
||||
jclass this_cls,
|
||||
jlong id) {
|
||||
auto stripe_reader = orc_stripe_reader_holder_.Lookup(id);
|
||||
if (!stripe_reader) {
|
||||
std::string error_message = "invalid stripe reader id " + std::to_string(id);
|
||||
env->ThrowNew(exception_class, error_message.c_str());
|
||||
}
|
||||
auto stripe_reader = GetStripeReader(env, id);
|
||||
|
||||
std::shared_ptr<arrow::RecordBatch> record_batch;
|
||||
auto status = stripe_reader->ReadNext(&record_batch);
|
||||
@@ -245,6 +258,7 @@ Java_org_apache_arrow_adapter_orc_OrcStripeReaderJniWrapper_next(JNIEnv* env,
|
||||
|
||||
auto schema = stripe_reader->schema();
|
||||
|
||||
// TODO: ARROW-4714 Ensure JVM has sufficient capacity to create local references
|
||||
// create OrcFieldNode[]
|
||||
jobjectArray field_array =
|
||||
env->NewObjectArray(schema->num_fields(), orc_field_node_class, nullptr);
|
||||
|
||||
@@ -34,7 +34,7 @@ class OrcJniUtils {
|
||||
private OrcJniUtils() {}
|
||||
|
||||
static void loadOrcAdapterLibraryFromJar()
|
||||
throws IOException {
|
||||
throws IOException, IllegalAccessException {
|
||||
synchronized (OrcJniUtils.class) {
|
||||
if (!isLoaded) {
|
||||
final String libraryToLoad = System.mapLibraryName(LIBRARY_NAME);
|
||||
|
||||
@@ -43,7 +43,7 @@ public class OrcReader implements AutoCloseable {
|
||||
* @param allocator allocator provided to ArrowReader.
|
||||
* @throws IOException throws exception in case of file not found
|
||||
*/
|
||||
public OrcReader(String filePath, BufferAllocator allocator) throws IOException {
|
||||
public OrcReader(String filePath, BufferAllocator allocator) throws IOException, IllegalAccessException {
|
||||
this.allocator = allocator;
|
||||
this.jniWrapper = OrcReaderJniWrapper.getInstance();
|
||||
this.nativeInstanceId = jniWrapper.open(filePath);
|
||||
@@ -55,7 +55,7 @@ public class OrcReader implements AutoCloseable {
|
||||
* @param rowNumber the rows number to seek
|
||||
* @return true if seek operation is succeeded
|
||||
*/
|
||||
public boolean seek(int rowNumber) {
|
||||
public boolean seek(int rowNumber) throws IllegalArgumentException {
|
||||
return jniWrapper.seek(nativeInstanceId, rowNumber);
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class OrcReader implements AutoCloseable {
|
||||
* @param batchSize the number of rows loaded on each iteration
|
||||
* @return ArrowReader that iterate over current stripes
|
||||
*/
|
||||
public ArrowReader nextStripeReader(long batchSize) {
|
||||
public ArrowReader nextStripeReader(long batchSize) throws IllegalArgumentException {
|
||||
long stripeReaderId = jniWrapper.nextStripeReader(nativeInstanceId, batchSize);
|
||||
if (stripeReaderId < 0) {
|
||||
return null;
|
||||
@@ -79,7 +79,7 @@ public class OrcReader implements AutoCloseable {
|
||||
*
|
||||
* @return number of stripes
|
||||
*/
|
||||
public int getNumberOfStripes() {
|
||||
public int getNumberOfStripes() throws IllegalArgumentException {
|
||||
return jniWrapper.getNumberOfStripes(nativeInstanceId);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ class OrcReaderJniWrapper {
|
||||
|
||||
private static volatile OrcReaderJniWrapper INSTANCE;
|
||||
|
||||
static OrcReaderJniWrapper getInstance() throws IOException {
|
||||
static OrcReaderJniWrapper getInstance() throws IOException, IllegalAccessException {
|
||||
if (INSTANCE == null) {
|
||||
synchronized (OrcReaderJniWrapper.class) {
|
||||
if (INSTANCE == null) {
|
||||
|
||||
Reference in new issue
Block a user