Skip to content

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

Merged
lidavidm merged 2 commits into
apache:mainfrom
lidavidm:gh-3868
Apr 15, 2026
Merged

feat(java/driver/jni): implement get/set option#4203
lidavidm merged 2 commits into
apache: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
@lidavidm
lidavidm marked this pull request as ready for review April 13, 2026 06:04

@zeroshade zeroshade left a comment

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.

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

@amoeba amoeba left a comment

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.

+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?

@lidavidm
lidavidm merged commit 77fb7ae into apache:main Apr 15, 2026
14 checks passed
@lidavidm
lidavidm deleted the gh-3868 branch April 15, 2026 02:09
tokoko pushed a commit to tokoko/arrow-adbc that referenced this pull request May 29, 2026
@lidavidm lidavidm added this to the ADBC Libraries 24 milestone Jul 22, 2026
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