-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-18950][SQL] Report conflicting fields when merging two StructTypes #16365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
9bc9f8a
54a898f
f500a11
f4892c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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._ | ||
|
|
||
|
|
@@ -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 { | ||
| 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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we throw an
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? |
||
| } | ||
| } | ||
| .orElse { | ||
| optionalMeta.putBoolean(metadataKeyForOptionalField, value = true) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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") { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use the JAVA style
tryandcatch? See the https://github.com/databricks/scala-style-guide#exception-handling-try-vs-try