Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.spark.sql.types

import scala.collection.mutable.ArrayBuffer
import scala.util.control.NonFatal
import scala.util.Try

import org.json4s.JsonDSL._
Expand Down Expand Up @@ -468,10 +469,16 @@ object StructType extends AbstractDataType {
leftFields.foreach {
case leftField @ StructField(leftName, leftType, leftNullable, _) =>
rightMapped.get(leftName)
.map { case rightField @ StructField(_, rightType, rightNullable, _) =>
leftField.copy(
dataType = merge(leftType, rightType),
nullable = leftNullable || rightNullable)
.map { case rightField @ StructField(rightName, rightType, rightNullable, _) =>
try {
leftField.copy(
dataType = merge(leftType, rightType),
nullable = leftNullable || rightNullable)
} catch {
case NonFatal(e) =>
throw new SparkException(s"Failed to merge fields '$leftName' and " +
s"'$rightName'. " + e.getMessage)
}
}
.orElse {
optionalMeta.putBoolean(metadataKeyForOptionalField, value = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,11 @@ class DataTypeSuite extends SparkFunSuite {
val right = StructType(
StructField("b", LongType) :: Nil)

intercept[SparkException] {
val message = intercept[SparkException] {
left.merge(right)
}
}.getMessage
assert(message.equals("Failed to merge fields 'b' and 'b'. " +
"Failed to merge incompatible data types FloatType and LongType"))
}

test("existsRecursively") {
Expand Down