Skip to content

_duckdb_jdbc_fetch misses HasError() check after Fetch(), causing silent result truncation on streaming queries #893

Closed

Description

@rigobc

Bug Description
When streaming results via the JDBC driver, a query failure mid-execution (e.g., synthetic data error, mid-stream S3 network drop, or corrupt Parquet chunk) is silently masked as end-of-stream (EOF).

Rather than throwing a SQLException, ResultSet.next() returns false, causing calling applications to receive partial data silently (e.g., returning 29M rows out of 40M without any warning or exception).

Root Cause Analysis
In core DuckDB C++, FetchInternal returns a null chunk both when data ends naturally and when execution encounters an error. Upon failure, it sets the error state on the result object for the caller to check via HasError().

In the Java native driver (duckdb_java.cpp, _duckdb_jdbc_fetch), HasError() is checked before invoking Fetch(), but not after.

When Fetch() returns null due to a mid-stream failure, _duckdb_jdbc_fetch replaces it with an empty chunk.

In DuckDBResultSet.next(), receiving an empty chunk is treated as finished = true, returning false to the caller.

Expected Behavior
If Fetch() yields a null chunk and HasError() returns true, _duckdb_jdbc_fetch / DuckDBResultSet should extract the error message and throw a SQLException.

Environment
Driver versions tested: 1.4.2.0, 1.5.6.0

Connection setting: Result streaming enabled (jdbc_stream_results = true)

Activity

  1. staticlibs commented on Oct 4, 2026

    @staticlibs
    Member

    Hi, thanks for the report! I believe this was fixed in #886. It can be checked with the following snapshot:

    <dependency>
        <groupId>org.duckdb</groupId>
        <artifactId>duckdb_jdbc</artifactId>
        <version>2.0.0-alpha43678-891</version>
    </dependency>
    <repository>
        <id>duckdb</id>
        <url>https://duckdb-staging.duckdb.org/duckdb/duckdb-java/maven/</url>
    </repository>
  2. rigobc commented on Oct 4, 2026

    @rigobc
    Author

    great - thank you!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions