-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Refactor Arrow Array and Schema allocation in ColumnReader and MetadataColumnReader #1047
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ use std::{boxed::Box, ptr::NonNull, sync::Arc}; | |
|
||
use crate::errors::{try_unwrap_or_throw, CometError}; | ||
|
||
use arrow::ffi::{FFI_ArrowArray, FFI_ArrowSchema}; | ||
use arrow::ffi::FFI_ArrowArray; | ||
|
||
/// JNI exposed methods | ||
use jni::JNIEnv; | ||
|
@@ -52,7 +52,6 @@ const STR_CLASS_NAME: &str = "java/lang/String"; | |
/// Parquet read context maintained across multiple JNI calls. | ||
struct Context { | ||
pub column_reader: ColumnReader, | ||
pub arrays: Option<(Arc<FFI_ArrowArray>, Arc<FFI_ArrowSchema>)>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This refactoring simplifies the context and the logic. We don't need to keep the array and schema pointers in the producer side. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is also easier to reason the array/schema release logic after this refactoring. |
||
last_data_page: Option<GlobalRef>, | ||
} | ||
|
||
|
@@ -110,7 +109,6 @@ pub extern "system" fn Java_org_apache_comet_parquet_Native_initColumnReader( | |
use_decimal_128 != 0, | ||
use_legacy_date_timestamp != 0, | ||
), | ||
arrays: None, | ||
last_data_page: None, | ||
}; | ||
let res = Box::new(ctx); | ||
|
@@ -539,24 +537,16 @@ pub extern "system" fn Java_org_apache_comet_parquet_Native_currentBatch( | |
e: JNIEnv, | ||
_jclass: JClass, | ||
handle: jlong, | ||
) -> jlongArray { | ||
try_unwrap_or_throw(&e, |env| { | ||
array_addr: jlong, | ||
schema_addr: jlong, | ||
) { | ||
try_unwrap_or_throw(&e, |_env| { | ||
let ctx = get_context(handle)?; | ||
let reader = &mut ctx.column_reader; | ||
let data = reader.current_batch(); | ||
let (array, schema) = data.to_spark()?; | ||
data.move_to_spark(array_addr, schema_addr)?; | ||
viirya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
unsafe { | ||
let arrow_array = Arc::from_raw(array as *const FFI_ArrowArray); | ||
let arrow_schema = Arc::from_raw(schema as *const FFI_ArrowSchema); | ||
ctx.arrays = Some((arrow_array, arrow_schema)); | ||
|
||
let res = env.new_long_array(2)?; | ||
let buf: [i64; 2] = [array, schema]; | ||
env.set_long_array_region(&res, 0, &buf) | ||
.expect("set long array region failed"); | ||
Ok(res.into_raw()) | ||
} | ||
Ok(()) | ||
}) | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated but we should not be needing to call
CometDictionaryVector
twice