Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/main/java/org/duckdb/DuckDBAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public class DuckDBAppender implements AutoCloseable {

supportedTypes.add(DUCKDB_TYPE_ARRAY.typeId);
supportedTypes.add(DUCKDB_TYPE_STRUCT.typeId);
supportedTypes.add(DUCKDB_TYPE_UUID.typeId);
}
private static final CAPIType[] int8Types = new CAPIType[] {DUCKDB_TYPE_TINYINT, DUCKDB_TYPE_UTINYINT};
private static final CAPIType[] int16Types = new CAPIType[] {DUCKDB_TYPE_SMALLINT, DUCKDB_TYPE_USMALLINT};
Expand Down Expand Up @@ -922,6 +923,26 @@ public DuckDBAppender append(String value) throws SQLException {
return appendStringOrBlobInternal(DUCKDB_TYPE_VARCHAR, bytes);
}

public DuckDBAppender appendUUID(long mostSigBits, long leastSigBits) throws SQLException {
Column col = currentColumnWithRowPos(DUCKDB_TYPE_UUID);
col.data.putLong(leastSigBits);
mostSigBits ^= Long.MIN_VALUE;
col.data.putLong(mostSigBits);
incrementColOrStructFieldIdx();
return this;
}

public DuckDBAppender append(UUID value) throws SQLException {
checkCurrentColumnType(DUCKDB_TYPE_UUID);
if (value == null) {
return appendNull();
}

long mostSigBits = value.getMostSignificantBits();
long leastSigBits = value.getLeastSignificantBits();
return appendUUID(mostSigBits, leastSigBits);
}

public DuckDBAppender appendEpochDays(int days) throws SQLException {
Column col = currentColumnWithRowPos(DUCKDB_TYPE_DATE);
col.data.putInt(days);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/duckdb/DuckDBBindings.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ enum CAPIType {
// duckdb_array, only useful as logical type
DUCKDB_TYPE_ARRAY(33, 0),
// duckdb_hugeint
DUCKDB_TYPE_UUID(27),
DUCKDB_TYPE_UUID(27, 16),
// union type, only useful as logical type
DUCKDB_TYPE_UNION(28),
// duckdb_bit
Expand Down
26 changes: 26 additions & 0 deletions src/test/java/org/duckdb/TestAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@ public static void test_appender_unsigned() throws Exception {
}
}

public static void test_appender_uuid() throws Exception {
try (DuckDBConnection conn = DriverManager.getConnection(JDBC_URL).unwrap(DuckDBConnection.class);
Statement stmt = conn.createStatement()) {

stmt.execute("CREATE TABLE tab1(col1 INT, col2 UUID)");
UUID uuid1 = UUID.randomUUID();
UUID uuid2 = UUID.randomUUID();
try (DuckDBAppender appender = conn.createAppender("tab1")) {
appender.beginRow().append(1).append(uuid1).endRow();
appender.beginRow().append(2).append(uuid2).endRow();
appender.flush();
}

try (DuckDBResultSet rs =
stmt.executeQuery("SELECT * FROM tab1 ORDER BY col1").unwrap(DuckDBResultSet.class)) {
assertTrue(rs.next());
assertEquals(rs.getUuid(2), uuid1);
assertEquals(rs.getObject(2, UUID.class), uuid1);
assertTrue(rs.next());
assertEquals(rs.getUuid(2), uuid2);
assertEquals(rs.getObject(2, UUID.class), uuid2);
assertFalse(rs.next());
}
}
}

public static void test_appender_long_string() throws Exception {
try (DuckDBConnection conn = DriverManager.getConnection(JDBC_URL).unwrap(DuckDBConnection.class);
Statement stmt = conn.createStatement()) {
Expand Down