Skip to content

Commit 8b2003c

Browse files
committed
tiny fix for type rendering to include variance. It caused unhelpful errors because variance mismatches in duckdb map values
1 parent a376b5c commit 8b2003c

File tree

2 files changed

+9
-3
lines changed
  • core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl
  • dataframe-jdbc/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/db

2 files changed

+9
-3
lines changed

core/src/main/kotlin/org/jetbrains/kotlinx/dataframe/impl/Rendering.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import java.net.URL
1616
import java.time.LocalDateTime
1717
import java.time.LocalTime
1818
import kotlin.reflect.KType
19+
import kotlin.reflect.KVariance
1920
import kotlin.reflect.full.isSubtypeOf
2021
import kotlin.reflect.jvm.jvmErasure
2122
import kotlin.reflect.typeOf
@@ -89,7 +90,12 @@ internal fun renderType(type: KType?): String {
8990
append(name)
9091
if (type.arguments.isNotEmpty()) {
9192
val arguments = type.arguments.joinToString {
92-
renderType(it.type)
93+
when (it.variance) {
94+
null -> "*"
95+
KVariance.INVARIANT -> renderType(it.type)
96+
KVariance.IN -> "in ${renderType(it.type)}"
97+
KVariance.OUT -> "out ${renderType(it.type)}"
98+
}
9399
}
94100
append("<$arguments>")
95101
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public object DuckDb : DbType("duckdb") {
132132
Map::class.createType(
133133
listOf(
134134
KTypeProjection.invariant(key.toKType(false)),
135-
KTypeProjection.covariant(value.toKType(true)),
135+
KTypeProjection.invariant(value.toKType(true)),
136136
),
137137
)
138138
}
@@ -141,7 +141,7 @@ public object DuckDb : DbType("duckdb") {
141141
// TODO requires #1266 and #1273 for specific types
142142
// val listType = parseListType(sqlTypeName)
143143
// Array::class.createType(
144-
// listOf(KTypeProjection.covariant(listType.toKType(true))),
144+
// listOf(KTypeProjection.invariant(listType.toKType(true))),
145145
// )
146146
typeOf<Array>()
147147
}

0 commit comments

Comments
 (0)