Skip to content

Commit

Permalink
Update ArrowUtils.scala
Browse files Browse the repository at this point in the history
  • Loading branch information
AngersZhuuuu committed Jun 21, 2024
1 parent 0eb76d6 commit 960370d
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,19 @@ private[sql] object ArrowUtils {
case _ => dt
}

/**
* Convert from spark sql types to arrow field can't support UserDefinedType yet.
* Arrow support UserDefinedType by read/write it's serialized/deserialized data.
* When compare output types should convert UserDefinedType to it's sqlType too.
*/
def toArrowOutputSchema(dt: DataType): DataType = {
dt match {
case udt: UserDefinedType[_] => toArrowOutputSchema(udt.sqlType)
case arr@ArrayType(elementType, _) =>
case arr @ ArrayType(elementType, _) =>
arr.copy(elementType = toArrowOutputSchema(elementType))
case struct@StructType(fields) =>
case struct @ StructType(fields) =>
struct.copy(fields.map(field => field.copy(dataType = toArrowOutputSchema(field.dataType))))
case map@MapType(keyType, valueType, _) =>
case map @ MapType(keyType, valueType, _) =>
map.copy(keyType = toArrowOutputSchema(keyType), valueType = toArrowOutputSchema(valueType))
case _ =>
dt
Expand Down

0 comments on commit 960370d

Please sign in to comment.