Skip to content

Conversation

elefeint
Copy link
Contributor

JDBC spec allows getting an array/list type as a 2-column ResultSet with the first column containing indices and the second column containing values.

This PR implements a ResultSet wrapper around an existing result vector.

public DuckDBArrayResultSet(DuckDBVector vector, int offset, int length) {
this.vector = vector;
this.offset = offset;
this.length = length;
Copy link
Member

Choose a reason for hiding this comment

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

Looks like you haven't used this offset anywhere, this means this will break on multiple arrays being returned by a single query. Easiest fix is to just use the methods on the original Array implementation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Mause Thank you! I was originally hoping to wrap DuckDBArray instead of DuckDBVector, but I only found an untyped Object getArray() on it. Reusing vector seemed less error-prone than type-checking in every getter. Are there better ways of using DuckDBArray that I missed?

In the meantime, I updated DuckDBArrayResultSet to use the offset. I could not find a test case to force a non-zero offset -- do you know offhand what query would work to test this case?

Copy link
Member

Choose a reason for hiding this comment

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

Something like

SELECT UNNEST([[1], [2]])

Should give a non zero offset, by having two list rows for a single column

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you! That worked to expose the offset issue on the previous implementation of getValue(). I added the test.

Copy link
Member

@Mause Mause left a comment

Choose a reason for hiding this comment

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

Switch to DuckDBArray

@Mause Mause added the JDBC label Sep 18, 2023
@github-actions github-actions bot marked this pull request as draft September 18, 2023 12:21
@elefeint elefeint marked this pull request as ready for review September 18, 2023 12:33
@github-actions github-actions bot marked this pull request as draft September 18, 2023 15:44
@elefeint elefeint marked this pull request as ready for review September 19, 2023 14:47
Copy link
Member

@Mause Mause left a comment

Choose a reason for hiding this comment

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

LGTM!

@elefeint
Copy link
Contributor Author

@Mytherin Is there anything blocking this PR getting merged? It's not a super important part of JDBC spec, but we had a user bring up that it was throwing Unsupported.

@Mytherin Mytherin merged commit 06e08ee into duckdb:main Oct 30, 2023
@Mytherin
Copy link
Collaborator

No this is ready to merge - thanks!

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.

3 participants