Skip to content

Commit b7cf42d

Browse files
authored
fix: struct type for nullable field
* fix StructType for nullable list and map field in 3.0 * fix StructType for nullable list and map field in 2.4 * fix test name Co-authored-by: can wang <can.wang@thoughtworks.com>
1 parent 05a3dca commit b7cf42d

File tree

4 files changed

+27
-5
lines changed
  • kotlin-spark-api
    • 2.4/src
      • main/kotlin/org/jetbrains/kotlinx/spark/api
      • test/kotlin/org/jetbrains/kotlinx/spark/api
    • 3.0/src
      • main/kotlin/org/jetbrains/kotlinx/spark/api
      • test/kotlin/org/jetbrains/kotlinx/spark/api

4 files changed

+27
-5
lines changed

kotlin-spark-api/2.4/src/main/kotlin/org/jetbrains/kotlinx/spark/api/ApiV1.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ fun schema(type: KType, map: Map<String, KType> = mapOf()): DataType {
884884
KComplexTypeWrapper(
885885
DataTypes.createArrayType(schema(listParam, types), listParam.isMarkedNullable),
886886
klass.java,
887-
listParam.isMarkedNullable
887+
type.isMarkedNullable
888888
)
889889
}
890890
klass.isSubclassOf(Map::class) -> {
@@ -897,7 +897,7 @@ fun schema(type: KType, map: Map<String, KType> = mapOf()): DataType {
897897
true
898898
),
899899
klass.java,
900-
mapValueParam.isMarkedNullable
900+
type.isMarkedNullable
901901
)
902902
}
903903
klass.isData -> {

kotlin-spark-api/2.4/src/test/kotlin/org/jetbrains/kotlinx/spark/api/ApiTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,12 @@ class ApiTest : ShouldSpec({
542542
.reduceK { a, b -> a + b }
543543
expect(result).toBe(3)
544544
}
545+
should("Generate schema correctly with nullalble list and map") {
546+
val schema = encoder<NullFieldAbleDataClass>().schema()
547+
schema.fields().forEach {
548+
it.nullable() shouldBe true
549+
}
550+
}
545551
}
546552
}
547553
})
@@ -591,3 +597,9 @@ data class ComplexEnumDataClass(
591597
val someOtherArray: Array<SomeOtherEnum>,
592598
val enumMap: Map<SomeEnum, SomeOtherEnum>,
593599
)
600+
601+
602+
data class NullFieldAbleDataClass(
603+
val optionList: List<Int>?,
604+
val optionMap: Map<String, Int>?
605+
)

kotlin-spark-api/3.0/src/main/kotlin/org/jetbrains/kotlinx/spark/api/ApiV1.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ fun schema(type: KType, map: Map<String, KType> = mapOf()): DataType {
887887
KComplexTypeWrapper(
888888
DataTypes.createArrayType(schema(listParam, types), listParam.isMarkedNullable),
889889
klass.java,
890-
listParam.isMarkedNullable
890+
type.isMarkedNullable
891891
)
892892
}
893893
klass.isSubclassOf(Map::class) -> {
@@ -900,7 +900,7 @@ fun schema(type: KType, map: Map<String, KType> = mapOf()): DataType {
900900
true
901901
),
902902
klass.java,
903-
mapValueParam.isMarkedNullable
903+
type.isMarkedNullable
904904
)
905905
}
906906
klass.isData -> {

kotlin-spark-api/3.0/src/test/kotlin/org/jetbrains/kotlinx/spark/api/ApiTest.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,12 @@ class ApiTest : ShouldSpec({
585585
.reduceK { a, b -> a + b }
586586
expect(result).toBe(3)
587587
}
588-
588+
should("Generate schema correctly with nullalble list and map") {
589+
val schema = encoder<NullFieldAbleDataClass>().schema()
590+
schema.fields().forEach {
591+
it.nullable() shouldBe true
592+
}
593+
}
589594
}
590595
}
591596
})
@@ -615,4 +620,9 @@ data class ComplexEnumDataClass(
615620
val someEnumArray: Array<SomeEnum>,
616621
val someOtherArray: Array<SomeOtherEnum>,
617622
val enumMap: Map<SomeEnum, SomeOtherEnum>,
623+
)
624+
625+
data class NullFieldAbleDataClass(
626+
val optionList: List<Int>?,
627+
val optionMap: Map<String, Int>?
618628
)

0 commit comments

Comments
 (0)