Skip to content

Commit 0c8f4b1

Browse files
committed
Map support
1 parent 0d061b6 commit 0c8f4b1

File tree

1 file changed

+18
-2
lines changed
  • kotlin-spark-api/src/main/kotlin/org/jetbrains/kotlinx/spark/api

1 file changed

+18
-2
lines changed

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

+18-2
Original file line numberDiff line numberDiff line change
@@ -463,8 +463,24 @@ object KotlinTypeInference {
463463
)
464464
}
465465

466-
currentType.isSubtypeOf<Map<*, *>?>() -> TODO()
467-
currentType.isSubtypeOf<scala.collection.Map<*, *>?>() -> TODO()
466+
currentType.isSubtypeOf<Map<*, *>?>() || currentType.isSubtypeOf<scala.collection.Map<*, *>?>() -> {
467+
val keyEncoder = encoderFor(
468+
currentType = tArguments[0].type!!,
469+
seenTypeSet = seenTypeSet,
470+
typeVariables = typeVariables,
471+
)
472+
val valueEncoder = encoderFor(
473+
currentType = tArguments[1].type!!,
474+
seenTypeSet = seenTypeSet,
475+
typeVariables = typeVariables,
476+
)
477+
AgnosticEncoders.MapEncoder(
478+
/* clsTag = */ ClassTag.apply<Map<*, *>>(jClass),
479+
/* keyEncoder = */ keyEncoder,
480+
/* valueEncoder = */ valueEncoder,
481+
/* valueContainsNull = */ tArguments[1].type!!.isMarkedNullable,
482+
)
483+
}
468484

469485
kClass.isData -> {
470486
if (currentType in seenTypeSet) throw IllegalStateException("Circular reference detected for type $currentType")

0 commit comments

Comments
 (0)