Skip to content

Commit 20ce5c6

Browse files
committed
Fixes for bumping DuckDb to 1.5+
1 parent 06d9c13 commit 20ce5c6

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

  • dataframe-jdbc/src
    • main/kotlin/org/jetbrains/kotlinx/dataframe/io/db
    • test/kotlin/org/jetbrains/kotlinx/dataframe/io/local

dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/db/DuckDb.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import org.duckdb.DuckDBColumnType.DECIMAL
1313
import org.duckdb.DuckDBColumnType.DOUBLE
1414
import org.duckdb.DuckDBColumnType.ENUM
1515
import org.duckdb.DuckDBColumnType.FLOAT
16+
import org.duckdb.DuckDBColumnType.GEOMETRY
1617
import org.duckdb.DuckDBColumnType.HUGEINT
1718
import org.duckdb.DuckDBColumnType.INTEGER
1819
import org.duckdb.DuckDBColumnType.INTERVAL
@@ -27,6 +28,7 @@ import org.duckdb.DuckDBColumnType.TIMESTAMP_MS
2728
import org.duckdb.DuckDBColumnType.TIMESTAMP_NS
2829
import org.duckdb.DuckDBColumnType.TIMESTAMP_S
2930
import org.duckdb.DuckDBColumnType.TIMESTAMP_WITH_TIME_ZONE
31+
import org.duckdb.DuckDBColumnType.TIME_NS
3032
import org.duckdb.DuckDBColumnType.TIME_WITH_TIME_ZONE
3133
import org.duckdb.DuckDBColumnType.TINYINT
3234
import org.duckdb.DuckDBColumnType.UBIGINT
@@ -38,6 +40,7 @@ import org.duckdb.DuckDBColumnType.USMALLINT
3840
import org.duckdb.DuckDBColumnType.UTINYINT
3941
import org.duckdb.DuckDBColumnType.UUID
4042
import org.duckdb.DuckDBColumnType.VARCHAR
43+
import org.duckdb.DuckDBColumnType.VARIANT
4144
import org.duckdb.DuckDBResultSetMetaData
4245
import org.duckdb.JsonNode
4346
import org.jetbrains.kotlinx.dataframe.AnyRow
@@ -135,7 +138,7 @@ public object DuckDb : AdvancedDbType("duckdb") {
135138

136139
DECIMAL -> jdbcToDfConverterFor<BigDecimal>(isNullable)
137140

138-
TIME ->
141+
TIME, TIME_NS ->
139142
jdbcToDfConverterFor<JavaLocalTime>(isNullable)
140143
.withPreprocessor { it?.toKotlinLocalTime() }
141144

@@ -162,7 +165,7 @@ public object DuckDb : AdvancedDbType("duckdb") {
162165
.inferType()
163166
}
164167

165-
BLOB -> jdbcToDfConverterFor<Blob>(isNullable)
168+
BLOB, GEOMETRY -> jdbcToDfConverterFor<Blob>(isNullable)
166169

167170
UUID -> jdbcToDfConverterFor<JavaUUID>(isNullable)
168171
.withPreprocessor { it?.toKotlinUuid() }
@@ -280,7 +283,7 @@ public object DuckDb : AdvancedDbType("duckdb") {
280283
}
281284

282285
// Cannot handle this in Kotlin
283-
UNION -> jdbcToDfConverterFor<Any>(isNullable)
286+
UNION, VARIANT -> jdbcToDfConverterFor<Any>(isNullable)
284287

285288
VARCHAR -> jdbcToDfConverterFor<String>(isNullable)
286289

dataframe-jdbc/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/local/duckDbTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class DuckDbTest {
112112
val float8Col: Double,
113113
@ColumnName("float_col")
114114
val floatCol: Float,
115+
@ColumnName("geometry_col")
116+
val geometryCol: Blob,
115117
@ColumnName("hugeint_col")
116118
val hugeintCol: BigInteger,
117119
@ColumnName("int128_col")
@@ -158,6 +160,8 @@ class DuckDbTest {
158160
val textCol: String,
159161
@ColumnName("time_col")
160162
val timeCol: LocalTime,
163+
@ColumnName("time_ns_col")
164+
val timeNsCol: LocalTime,
161165
@ColumnName("timestamp_col")
162166
val timestampCol: Instant,
163167
@ColumnName("timestamptz_col")
@@ -201,6 +205,12 @@ class DuckDbTest {
201205
bitCol = "1010",
202206
bitstringCol = "1010",
203207
blobCol = DuckDBResultSet.DuckDBBlobResult(ByteBuffer.wrap("DEADBEEF".toByteArray())),
208+
// TODO improve this test case once DuckDB supports the geometry type fully
209+
geometryCol = DuckDBResultSet.DuckDBBlobResult(
210+
ByteBuffer.wrap(
211+
byteArrayOf(1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 62, 64, 0, 0, 0, 0, 0, 0, 36, 64),
212+
),
213+
),
204214
boolCol = true,
205215
booleanCol = true,
206216
bpcharCol = "test",
@@ -237,6 +247,7 @@ class DuckDbTest {
237247
stringCol = "test string",
238248
textCol = "test text",
239249
timeCol = LocalTime.parse("12:34:56"),
250+
timeNsCol = LocalTime.parse("12:34:56"),
240251
timestampCol = Timestamp.valueOf("2025-06-19 12:34:56").toInstant().toKotlinInstant(),
241252
timestamptzCol = JavaOffsetDateTime.parse("2025-06-19T12:34:56+02:00"),
242253
timestampwtzCol = JavaOffsetDateTime.parse("2025-06-19T12:34:56+02:00"),
@@ -289,6 +300,8 @@ class DuckDbTest {
289300
val stringlistlistCol: List<List<String?>?>,
290301
@ColumnName("union_col")
291302
val unionCol: Any,
303+
@ColumnName("variant_col")
304+
val variantCol: Any,
292305
)
293306

294307
// endregion
@@ -464,6 +477,7 @@ class DuckDbTest {
464477
float8_col FLOAT8,
465478
float_col FLOAT,
466479
float4_col FLOAT4,
480+
geometry_col GEOMETRY,
467481
real_col REAL,
468482
hugeint_col HUGEINT,
469483
int128_col INT128,
@@ -479,6 +493,7 @@ class DuckDbTest {
479493
int16_col INT16,
480494
short_col SHORT,
481495
time_col TIME,
496+
time_ns_col TIME_NS,
482497
timestampwtz_col TIMESTAMP WITH TIME ZONE,
483498
timestamptz_col TIMESTAMPTZ,
484499
timestamp_col TIMESTAMP,
@@ -529,6 +544,7 @@ class DuckDbTest {
529544
3.14159, -- float8
530545
3.14, -- float
531546
3.14, -- float4
547+
'POINT (30 10)'::GEOMETRY, -- geometry
532548
3.14, -- real
533549
'170141183460469231731687303715884105727', -- hugeint
534550
'170141183460469231731687303715884105727', -- int128
@@ -544,6 +560,7 @@ class DuckDbTest {
544560
32767, -- int16
545561
32767, -- short
546562
'12:34:56', -- time
563+
'12:34:56', -- time_ns
547564
'2025-06-19 12:34:56+02', -- timestampwtz
548565
'2025-06-19 12:34:56+02', -- timestamptz
549566
'2025-06-19 12:34:56', -- timestamp
@@ -610,6 +627,7 @@ class DuckDbTest {
610627
ijstruct_col STRUCT(i INTEGER, j VARCHAR),
611628
ijstructlist_col STRUCT(i INTEGER, j VARCHAR)[],
612629
union_col UNION(num INTEGER, text VARCHAR),
630+
variant_col VARIANT,
613631
)
614632
""".trimIndent(),
615633
).executeUpdate()
@@ -628,6 +646,7 @@ class DuckDbTest {
628646
{ 'i': 42, 'j': 'answer' }, -- struct
629647
list_value({ 'i': 42, 'j': 'answer' }, { 'i': 44, 'j': 'answer' }), -- struct list
630648
union_value(num := 2), -- union
649+
'a'::VARIANT, -- variant
631650
)
632651
""".trimIndent(),
633652
).executeUpdate()
@@ -660,6 +679,7 @@ class DuckDbTest {
660679
NestedEntry(44, "answer"),
661680
)
662681
it["union_col"] shouldBe 2
682+
it["variant_col"] shouldBe "a"
663683
}
664684
}
665685

0 commit comments

Comments
 (0)