@@ -23,6 +23,7 @@ pub mod session_options {
2323 include ! ( concat!( env!( "OUT_DIR" ) , "/datafusion_java.rs" ) ) ;
2424}
2525
26+ use std:: path:: PathBuf ;
2627use std:: sync:: { Arc , OnceLock } ;
2728
2829use datafusion:: arrow:: datatypes:: { Schema , SchemaRef } ;
@@ -31,13 +32,16 @@ use datafusion::arrow::ipc::reader::StreamReader;
3132use datafusion:: arrow:: record_batch:: RecordBatchIterator ;
3233use datafusion:: dataframe:: DataFrame ;
3334use datafusion:: error:: DataFusionError ;
34- use datafusion:: prelude:: { ParquetReadOptions , SessionContext } ;
35+ use datafusion:: execution:: runtime_env:: RuntimeEnvBuilder ;
36+ use datafusion:: prelude:: { ParquetReadOptions , SessionConfig , SessionContext } ;
3537use jni:: objects:: { JByteArray , JClass , JObjectArray , JString } ;
3638use jni:: sys:: { jboolean, jint, jlong} ;
3739use jni:: JNIEnv ;
40+ use prost:: Message ;
3841use tokio:: runtime:: Runtime ;
3942
4043use crate :: errors:: { try_unwrap_or_throw, JniResult } ;
44+ use crate :: session_options:: SessionOptions ;
4145
4246pub ( crate ) fn runtime ( ) -> & ' static Runtime {
4347 static RT : OnceLock < Runtime > = OnceLock :: new ( ) ;
@@ -55,6 +59,46 @@ pub extern "system" fn Java_org_apache_datafusion_SessionContext_createSessionCo
5559 } )
5660}
5761
62+ #[ no_mangle]
63+ pub extern "system" fn Java_org_apache_datafusion_SessionContext_createSessionContextWithOptions <
64+ ' local ,
65+ > (
66+ mut env : JNIEnv < ' local > ,
67+ _class : JClass < ' local > ,
68+ options_bytes : JByteArray < ' local > ,
69+ ) -> jlong {
70+ try_unwrap_or_throw ( & mut env, 0 , |env| -> JniResult < jlong > {
71+ let bytes: Vec < u8 > = env. convert_byte_array ( & options_bytes) ?;
72+ let opts = SessionOptions :: decode ( bytes. as_slice ( ) ) ?;
73+
74+ let mut config = SessionConfig :: new ( ) ;
75+ if let Some ( v) = opts. batch_size {
76+ config = config. with_batch_size ( v as usize ) ;
77+ }
78+ if let Some ( v) = opts. target_partitions {
79+ config = config. with_target_partitions ( v as usize ) ;
80+ }
81+ if let Some ( v) = opts. collect_statistics {
82+ config = config. with_collect_statistics ( v) ;
83+ }
84+ if let Some ( v) = opts. information_schema {
85+ config = config. with_information_schema ( v) ;
86+ }
87+
88+ let mut runtime = RuntimeEnvBuilder :: new ( ) ;
89+ if let Some ( mem) = opts. memory_limit {
90+ runtime = runtime. with_memory_limit ( mem. max_memory_bytes as usize , mem. memory_fraction ) ;
91+ }
92+ if let Some ( dir) = opts. temp_directory {
93+ runtime = runtime. with_temp_file_path ( PathBuf :: from ( dir) ) ;
94+ }
95+
96+ let runtime_env = runtime. build ( ) ?;
97+ let ctx = SessionContext :: new_with_config_rt ( config, Arc :: new ( runtime_env) ) ;
98+ Ok ( Box :: into_raw ( Box :: new ( ctx) ) as jlong )
99+ } )
100+ }
101+
58102#[ no_mangle]
59103pub extern "system" fn Java_org_apache_datafusion_SessionContext_createDataFrame < ' local > (
60104 mut env : JNIEnv < ' local > ,
0 commit comments