@@ -49,9 +49,11 @@ use jni::{
4949
5050use self :: util:: jni:: TypePromotionInfo ;
5151use crate :: execution:: jni_api:: get_runtime;
52+ use crate :: execution:: metrics:: utils:: update_comet_metric;
5253use crate :: execution:: operators:: ExecutionError ;
5354use crate :: execution:: planner:: PhysicalPlanner ;
5455use crate :: execution:: serde;
56+ use crate :: execution:: spark_plan:: SparkPlan ;
5557use crate :: execution:: utils:: SparkArrowConvert ;
5658use crate :: jvm_bridge:: { jni_new_global_ref, JVMClasses } ;
5759use crate :: parquet:: data_type:: AsBytes ;
@@ -615,6 +617,8 @@ enum ParquetReaderState {
615617}
616618/// Parquet read context maintained across multiple JNI calls.
617619struct BatchContext {
620+ native_plan : Arc < SparkPlan > ,
621+ metrics_node : Arc < GlobalRef > ,
618622 batch_stream : Option < SendableRecordBatchStream > ,
619623 current_batch : Option < RecordBatch > ,
620624 reader_state : ParquetReaderState ,
@@ -716,6 +720,7 @@ pub unsafe extern "system" fn Java_org_apache_comet_parquet_Native_initRecordBat
716720 case_sensitive : jboolean ,
717721 object_store_options : jobject ,
718722 key_unwrapper_obj : JObject ,
723+ metrics_node : JObject ,
719724) -> jlong {
720725 try_unwrap_or_throw ( & e, |mut env| unsafe {
721726 JVMClasses :: init ( & mut env) ;
@@ -807,6 +812,8 @@ pub unsafe extern "system" fn Java_org_apache_comet_parquet_Native_initRecordBat
807812 let batch_stream = Some ( scan. execute ( partition_index, session_ctx. task_ctx ( ) ) ?) ;
808813
809814 let ctx = BatchContext {
815+ native_plan : Arc :: new ( SparkPlan :: new ( 0 , scan, vec ! [ ] ) ) ,
816+ metrics_node : Arc :: new ( jni_new_global_ref ! ( env, metrics_node) ?) ,
810817 batch_stream,
811818 current_batch : None ,
812819 reader_state : ParquetReaderState :: Init ,
@@ -822,7 +829,7 @@ pub extern "system" fn Java_org_apache_comet_parquet_Native_readNextRecordBatch(
822829 _jclass : JClass ,
823830 handle : jlong ,
824831) -> jint {
825- try_unwrap_or_throw ( & e, |_env | {
832+ try_unwrap_or_throw ( & e, |mut env | {
826833 let context = get_batch_context ( handle) ?;
827834 let mut rows_read: i32 = 0 ;
828835 let batch_stream = context. batch_stream . as_mut ( ) . unwrap ( ) ;
@@ -844,8 +851,11 @@ pub extern "system" fn Java_org_apache_comet_parquet_Native_readNextRecordBatch(
844851 Poll :: Ready ( None ) => {
845852 // EOF
846853
847- // TODO: (ARROW NATIVE) We can update metrics here
848- // crate::execution::jni_api::update_metrics(&mut env, exec_context)?;
854+ update_comet_metric (
855+ & mut env,
856+ context. metrics_node . as_obj ( ) ,
857+ & context. native_plan ,
858+ ) ?;
849859
850860 context. current_batch = None ;
851861 context. reader_state = ParquetReaderState :: Complete ;
0 commit comments