coderfender commented on code in PR #102:
URL: https://github.com/apache/datafusion-java/pull/102#discussion_r3367857232
##########
native/src/lib.rs:
##########
@@ -1042,6 +1042,47 @@ pub extern "system" fn
Java_org_apache_datafusion_SessionContext_getOptionNative
)
}
+#[no_mangle]
+pub extern "system" fn
Java_org_apache_datafusion_SessionContext_tableExists<'local>(
+ mut env: JNIEnv<'local>,
+ _class: JClass<'local>,
+ handle: jlong,
+ name: JString<'local>,
+) -> jboolean {
+ try_unwrap_or_throw(&mut env, 0, |env| -> JniResult<jboolean> {
+ if handle == 0 {
+ return Err("SessionContext handle is null".into());
+ }
+ // SAFETY: handle is a valid Box<SessionContext> allocated by
createSessionContext,
+ // the null check above guards against zero, and the Java side zeroes
nativeHandle
+ // on close() so a closed context is caught before reaching here.
+ let ctx = unsafe { &*(handle as *const SessionContext) };
+ let name: String = env.get_string(&name)?.into();
+ Ok(ctx.table_exist(&name)? as jboolean)
Review Comment:
Could we port all common code into a new inline function here ?
##########
core/src/main/java/org/apache/datafusion/SessionContext.java:
##########
@@ -601,6 +601,41 @@ private static byte[] serializeSchemaIpc(Schema schema) {
return baos.toByteArray();
}
+ /**
+ * Returns {@code true} if a table with the given name is registered in this
session.
+ *
+ * <p>This is the Java counterpart to DataFusion's Rust {@code
SessionContext::table_exist}.
+ *
+ * @throws IllegalStateException if this context is closed.
+ */
+ public boolean tableExists(String name) {
+ if (nativeHandle == 0) {
+ throw new IllegalStateException("SessionContext is closed");
+ }
+ if (name == null) {
+ throw new IllegalArgumentException("tableExists name must be non-null");
+ }
Review Comment:
Does the native code throw an exception when a null invariant is passed ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]