in connector/src/main/scala/com/datastax/spark/connector/datasource/UnsafeRowReaderFactory.scala [106:135]
private def structTypeDecoder(structType: StructType): Any => Any = {
val childDecoders = structType.fields.map(field => buildDataTypeDecoder(field.dataType)).toIndexedSeq
input => {
input match {
case null => null
case udt: UDTValue =>
val selectedValues = structType.fields.zipWithIndex.map { case (field, idx) =>
val originalIndex = udt.indexOf(field.name)
val decoded = childDecoders(idx)(udt.columnValues(originalIndex))
decoded.asInstanceOf[AnyRef]
}
UDTValue.apply(structType.fieldNames.toIndexedSeq, selectedValues.toIndexedSeq)
case tuple: TupleValue =>
val selectedValues = structType.fields.zipWithIndex.map { case (field, idx) =>
val fieldInt = try {
field.name.toInt
} catch {
case _: NumberFormatException =>
throw new IllegalArgumentException(s"Expected integer for tuple column name, got ${field.name}")
}
val decoded = childDecoders(idx)(tuple.values(fieldInt))
decoded.asInstanceOf[AnyRef]
}
TupleValue(selectedValues.toIndexedSeq: _*)
case other =>
// ??
other
}
}
}