Skip to content

Commit

Permalink
Merge pull request duckdb#9659 from pdet/arrow_jdbc_segfault
Browse files Browse the repository at this point in the history
[JDBC] Sync all methods from a statement that interact with a query result
  • Loading branch information
Mytherin authored Nov 24, 2023
2 parents 7524538 + 776ff11 commit 0e01450
Show file tree
Hide file tree
Showing 4 changed files with 190 additions and 122 deletions.
3 changes: 3 additions & 0 deletions tools/jdbc/src/jni/duckdb_java.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,6 +994,9 @@ void _duckdb_jdbc_appender_append_null(JNIEnv *env, jclass, jobject appender_ref
}

jlong _duckdb_jdbc_arrow_stream(JNIEnv *env, jclass, jobject res_ref_buf, jlong batch_size) {
if (!res_ref_buf) {
throw InvalidInputException("Invalid result set");
}
auto res_ref = (ResultHolder *)env->GetDirectBufferAddress(res_ref_buf);
if (!res_ref || !res_ref->res || res_ref->res->HasError()) {
throw InvalidInputException("Invalid result set");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ public void clearParameters() throws SQLException {
public void close() throws SQLException {
if (select_result != null) {
select_result.close();
select_result = null;
}
if (stmt_ref != null) {
DuckDBNative.duckdb_jdbc_release(stmt_ref);
Expand Down
7 changes: 4 additions & 3 deletions tools/jdbc/src/main/java/org/duckdb/DuckDBResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public ResultSetMetaData getMetaData() throws SQLException {
return meta;
}

public boolean next() throws SQLException {
public synchronized boolean next() throws SQLException {
if (isClosed()) {
throw new SQLException("ResultSet was closed");
}
Expand Down Expand Up @@ -109,7 +109,7 @@ protected void finalize() throws Throwable {
close();
}

public boolean isClosed() throws SQLException {
public synchronized boolean isClosed() throws SQLException {
return result_ref == null;
}

Expand All @@ -129,7 +129,8 @@ private void check(int columnIndex) throws SQLException {
* @param arrow_batch_size batch size of arrow vectors to return
* @return an instance of {@link org.apache.arrow.vector.ipc.ArrowReader}
*/
public Object arrowExportStream(Object arrow_buffer_allocator, long arrow_batch_size) throws SQLException {
public synchronized Object arrowExportStream(Object arrow_buffer_allocator, long arrow_batch_size)
throws SQLException {
if (isClosed()) {
throw new SQLException("Result set is closed");
}
Expand Down
Loading

0 comments on commit 0e01450

Please sign in to comment.