Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 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,7 +18,7 @@
package org.apache.spark.sql.types

import scala.collection.mutable.ArrayBuffer
import scala.util.Try
import scala.util.{Failure, Success, Try}

import org.json4s.JsonDSL._

Expand Down Expand Up @@ -469,9 +469,16 @@ object StructType extends AbstractDataType {
case leftField @ StructField(leftName, leftType, leftNullable, _) =>
rightMapped.get(leftName)
.map { case rightField @ StructField(_, rightType, rightNullable, _) =>
leftField.copy(
dataType = merge(leftType, rightType),
nullable = leftNullable || rightNullable)
Try {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge(leftType, rightType)
} match {
case Success(dataType) =>
leftField.copy(
dataType = dataType,
nullable = leftNullable || rightNullable)
case Failure(e) =>
throw new SparkException(s"Failed to merge field '$leftName': " + e.getMessage)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we throw an AnalysisException with both sides, left and right? Thanks!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other exceptions in this class are also SparkException, for example the precision conflicts. Should we keep it as SparkException?
For "with both sides, left and right", do you mean just to modify the message a bit to include both left and right names(though they are the same)?
@gatorsmile your other comments are resolved.

}
}
.orElse {
optionalMeta.putBoolean(metadataKeyForOptionalField, value = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,17 @@ class DataTypeSuite extends SparkFunSuite {
test("merge where right contains type conflict") {
val left = StructType(
StructField("a", LongType) ::
StructField("b", FloatType) :: Nil)
StructField("conflictColumn", FloatType) :: Nil)

val right = StructType(
StructField("b", LongType) :: Nil)
StructField("conflictColumn", LongType) :: Nil)

intercept[SparkException] {
val message = intercept[SparkException] {
left.merge(right)
}
}.getMessage
assert(message.contains("conflictColumn"))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we capture the whole message? It can help us review the error message.

assert(message.contains(FloatType.toString))
assert(message.contains(LongType.toString))
}

test("existsRecursively") {
Expand Down