Skip to content

feat(java/driver/jni): implement get/set option#4203

Open
lidavidm wants to merge 1 commit intoapache:mainfrom
lidavidm:gh-3868
Open

feat(java/driver/jni): implement get/set option#4203
lidavidm wants to merge 1 commit intoapache:mainfrom
lidavidm:gh-3868

Conversation

@lidavidm
Copy link
Copy Markdown
Member

Closes #3868.

@lidavidm lidavidm requested review from amoeba and zeroshade April 13, 2026 05:18
Copy link
Copy Markdown
Member

@zeroshade zeroshade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically just one comment that repeats multiple times. Otherwise this looks good to me!

Comment on lines +473 to +480
while (length > buf.size()) {
// Buffer was too small, resize and try again
buf.resize(length);
CHECK_ADBC_ERROR(
AdbcStatementGetOptionBytes(db, key_str.value, const_cast<uint8_t*>(buf.data()),
&length, &error),
error);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The spec says that the length should be set to the required length, do we really need this to be a loop?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The other driver managers also use a loop

Comment on lines +538 to +545
while (length > buf.size()) {
// Buffer was too small, resize and try again
buf.resize(length);
CHECK_ADBC_ERROR(
AdbcStatementGetOption(db, key_str.value, const_cast<char*>(buf.data()),
&length, &error),
error);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above, if length is set to the required size, we shouldn't need a loop here, just an if

Comment on lines +764 to +771
while (length > buf.size()) {
// Buffer was too small, resize and try again
buf.resize(length);
CHECK_ADBC_ERROR(
AdbcConnectionGetOptionBytes(db, key_str.value,
const_cast<uint8_t*>(buf.data()), &length, &error),
error);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

AdbcConnectionGetOption(db, key_str.value, const_cast<char*>(buf.data()), &length,
&error),
error);
while (length > buf.size()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

AdbcDatabaseGetOptionBytes(db, key_str.value, const_cast<uint8_t*>(buf.data()),
&length, &error),
error);
while (length > buf.size()) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

Copy link
Copy Markdown
Member

@amoeba amoeba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1, two small things.

JniDriver.PARAM_DRIVER.set(parameters, "adbc_driver_sqlite");
try (final AdbcDatabase db = driver.open(parameters)) {
AdbcException e;
//noinspection unchecked
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My LSP wants to see these annotations for the yellow squigglies to go away,

diff --git a/java/driver/jni/src/test/java/org/apache/arrow/adbc/driver/jni/JniDriverTest.java b/java/driver/jni/src/test/java/org/apache/arrow/adbc/driver/jni/JniDriverTest.java
index c9a092221..8513d0de7 100644
--- a/java/driver/jni/src/test/java/org/apache/arrow/adbc/driver/jni/JniDriverTest.java
+++ b/java/driver/jni/src/test/java/org/apache/arrow/adbc/driver/jni/JniDriverTest.java
@@ -461,6 +461,7 @@ class JniDriverTest {
     }
   }
 
+  @SuppressWarnings("unchecked")
   @ParameterizedTest
   @MethodSource("getSetOptionFailProvider")
   void getSetOptionFailDatabase(GetSetOptionFailCase testCase) throws Exception {
@@ -478,6 +479,7 @@ class JniDriverTest {
     }
   }
 
+  @SuppressWarnings("unchecked")
   @ParameterizedTest
   @MethodSource("getSetOptionFailProvider")
   void getSetOptionFailConnection(GetSetOptionFailCase testCase) throws Exception {
@@ -495,6 +497,7 @@ class JniDriverTest {
     }
   }
 
+  @SuppressWarnings("unchecked")
   @ParameterizedTest
   @MethodSource("getSetOptionFailProvider")
   void getSetOptionFailStatement(GetSetOptionFailCase testCase) throws Exception {

Java_org_apache_arrow_adbc_driver_jni_impl_NativeAdbc_statementGetOptionBytes(
JNIEnv* env, [[maybe_unused]] jclass self, jlong handle, jstring key) {
struct AdbcError error = ADBC_ERROR_INIT;
auto* db = reinterpret_cast<struct AdbcStatement*>(static_cast<uintptr_t>(handle));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe rename these variables stmt and conn throughout this file as appropriate?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

java/driver/jni: enable setting statement options

3 participants