Skip to content

Commit 99d8e88

Browse files
committed
Read NullVector as Column<Nothing?>
1 parent 0b0c90f commit 99d8e88

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

dataframe-arrow/src/main/kotlin/org/jetbrains/kotlinx/dataframe/io/arrowReadingImpl.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ private fun StructVector.values(range: IntRange): List<Map<String, Any?>?> = ran
173173
getObject(it)
174174
}
175175

176-
private fun NullVector.values(range: IntRange): List<Any?> = range.map {
177-
getObject(it)
176+
private fun NullVector.values(range: IntRange): List<Nothing?> = range.map {
177+
getObject(it) as Nothing?
178178
}
179179

180180
private fun VarCharVector.values(range: IntRange): List<String?> = range.map {
@@ -209,6 +209,12 @@ private fun LargeVarCharVector.values(range: IntRange): List<String?> = range.ma
209209
}
210210
}
211211

212+
internal fun nothingType(nullable: Boolean): KType = if (nullable) {
213+
typeOf<List<Nothing?>>()
214+
} else {
215+
typeOf<List<Nothing>>()
216+
}.arguments.first().type!!
217+
212218
private inline fun <reified T> List<T?>.withTypeNullable(
213219
expectedNulls: Boolean,
214220
nullabilityOptions: NullabilityOptions,
@@ -250,7 +256,7 @@ private fun readField(root: VectorSchemaRoot, field: Field, nullability: Nullabi
250256
is TimeStampMilliVector -> vector.values(range).withTypeNullable(field.isNullable, nullability)
251257
is TimeStampSecVector -> vector.values(range).withTypeNullable(field.isNullable, nullability)
252258
is StructVector -> vector.values(range).withTypeNullable(field.isNullable, nullability)
253-
is NullVector -> vector.values(range).withTypeNullable(field.isNullable, nullability)
259+
is NullVector -> vector.values(range) to nothingType(field.isNullable)
254260
else -> {
255261
throw NotImplementedError("reading from ${vector.javaClass.canonicalName} is not implemented")
256262
}

dataframe-arrow/src/test/kotlin/org/jetbrains/kotlinx/dataframe/io/exampleEstimatesAssertions.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ internal fun assertEstimations(exampleFrame: AnyFrame, expectedNullable: Boolean
160160
}
161161

162162
exampleFrame.getColumnOrNull("nulls")?.let { nullCol ->
163+
nullCol.type() shouldBe nothingType(hasNulls)
163164
assert(hasNulls)
164165
nullCol.values().forEach {
165166
assert(it == null)

0 commit comments

Comments
 (0)