Skip to content

Conversation

@panbingkun
Copy link
Contributor

What changes were proposed in this pull request?

This pr replaces TypeCheckFailure by DataTypeMismatch in type checks in the complex type creator expressions, includes:

  1. CreateMap (3):
    TypeCheckResult.TypeCheckFailure(
    s"$prettyName expects a positive even number of arguments.")
    } else if (!TypeCoercion.haveSameType(keys.map(_.dataType))) {
    TypeCheckResult.TypeCheckFailure(
    "The given keys of function map should all be the same type, but they are " +
    keys.map(_.dataType.catalogString).mkString("[", ", ", "]"))
    } else if (!TypeCoercion.haveSameType(values.map(_.dataType))) {
    TypeCheckResult.TypeCheckFailure(
    "The given values of function map should all be the same type, but they are " +
    values.map(_.dataType.catalogString).mkString("[", ", ", "]"))
  2. CreateNamedStruct (3):
    if (children.size % 2 != 0) {
    TypeCheckResult.TypeCheckFailure(s"$prettyName expects an even number of arguments.")
    } else {
    val invalidNames = nameExprs.filterNot(e => e.foldable && e.dataType == StringType)
    if (invalidNames.nonEmpty) {
    TypeCheckResult.TypeCheckFailure(
    s"Only foldable ${StringType.catalogString} expressions are allowed to appear at odd" +
    s" position, got: ${invalidNames.mkString(",")}")
    } else if (!names.contains(null)) {
    TypeCheckResult.TypeCheckSuccess
    } else {
    TypeCheckResult.TypeCheckFailure("Field name should not be null")
    }
  3. UpdateFields (2):
    TypeCheckResult.TypeCheckFailure("struct argument should be struct type, got: " +
    dataType.catalogString)
    } else if (newExprs.isEmpty) {
    TypeCheckResult.TypeCheckFailure("cannot drop all fields in struct")

Why are the changes needed?

Migration onto error classes unifies Spark SQL error messages.

Does this PR introduce any user-facing change?

Yes. The PR changes user-facing error messages.

How was this patch tested?

  1. Add new UT
  2. Update existed UT
  3. Pass GA

"To convert values from <srcType> to <targetType>, you can use the functions <functionNames> instead."
]
},
"CREATE_MAP_KEY_DIFF_TYPES" : {
Copy link
Contributor

Choose a reason for hiding this comment

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

Cloud we make DATA_DIFF_TYPES more general and reuse it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Contributor Author

@panbingkun panbingkun Nov 1, 2022

Choose a reason for hiding this comment

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

but
image
Very hard to reuse it.
Maybe functionName pass to: map's keys or map's values, seems unreasonable

"The given keys of function <functionName> should all be the same type, but they are <dataType>."
]
},
"CREATE_MAP_VALUE_DIFF_TYPES" : {
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

s"Only foldable ${StringType.catalogString} expressions are allowed to appear at odd" +
s" position, got: ${invalidNames.mkString(",")}")
DataTypeMismatch(
errorSubClass = "CREATE_NAMED_STRUCT_WITHOUT_FOLDABLE_STRING",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can NON_FOLDABLE_INPUT be reused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Member

Choose a reason for hiding this comment

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

It seems that would be hard to make NON_FOLDABLE_INPUT more general to cover the case. Let's introduce more specific error class for the case.

)
} else if (newExprs.isEmpty) {
TypeCheckResult.TypeCheckFailure("cannot drop all fields in struct")
DataTypeMismatch(
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the original message did not clearly describe this error, the message doesn't look like DataTypeMismatch

Copy link
Member

Choose a reason for hiding this comment

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

It is some kind of UNEXPECTED_INPUT_TYPE: op (drop field) + its args are not supported because they produce empty struct. I am ok w/ this particular error class.

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@panbingkun
Copy link
Contributor Author

cc @MaxGekk

@MaxGekk
Copy link
Member

MaxGekk commented Nov 2, 2022

+1, LGTM. Merging to master.
Thank you, @panbingkun and @LuciferYang for review.

@MaxGekk MaxGekk closed this in 68531ad Nov 2, 2022
@panbingkun panbingkun deleted the SPARK-40374 branch November 7, 2022 02:11
SandishKumarHN pushed a commit to SandishKumarHN/spark that referenced this pull request Dec 12, 2022
…error classes

### What changes were proposed in this pull request?
This pr replaces TypeCheckFailure by DataTypeMismatch in type checks in the complex type creator expressions, includes:

1. CreateMap (3): https://github.com/apache/spark/blob/1431975723d8df30a25b2333eddcfd0bb6c57677/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala#L205-L214
2. CreateNamedStruct (3): https://github.com/apache/spark/blob/1431975723d8df30a25b2333eddcfd0bb6c57677/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala#L445-L457
3. UpdateFields (2): https://github.com/apache/spark/blob/1431975723d8df30a25b2333eddcfd0bb6c57677/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/complexTypeCreator.scala#L670-L673

### Why are the changes needed?
Migration onto error classes unifies Spark SQL error messages.

### Does this PR introduce _any_ user-facing change?
Yes. The PR changes user-facing error messages.

### How was this patch tested?
1. Add new UT
2. Update existed UT
3. Pass GA

Closes apache#38463 from panbingkun/SPARK-40374.

Authored-by: panbingkun <[email protected]>
Signed-off-by: Max Gekk <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants