Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/7420#discussion_r34704858
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
---
@@ -369,17 +369,15 @@ abstract class BinaryOperator extends
BinaryExpression with ExpectsInputTypes {
override def inputTypes: Seq[AbstractDataType] = Seq(inputType,
inputType)
override def checkInputDataTypes(): TypeCheckResult = {
- // First call the checker for ExpectsInputTypes, and then check
whether left and right have
- // the same type.
- super.checkInputDataTypes() match {
- case TypeCheckResult.TypeCheckSuccess =>
- if (left.dataType != right.dataType) {
- TypeCheckResult.TypeCheckFailure(s"differing types in
'$prettyString' " +
- s"(${left.dataType.simpleString} and
${right.dataType.simpleString}).")
- } else {
- TypeCheckResult.TypeCheckSuccess
- }
- case TypeCheckResult.TypeCheckFailure(msg) =>
TypeCheckResult.TypeCheckFailure(msg)
+ // First check whether left and right have the same type, then check
if the type is acceptable.
+ if (left.dataType != right.dataType) {
+ TypeCheckResult.TypeCheckFailure(s"differing types in
'$prettyString' " +
+ s"(${left.dataType.simpleString} and
${right.dataType.simpleString}).")
+ } else if (!inputType.acceptsType(left.dataType)) {
+ TypeCheckResult.TypeCheckFailure(s"'$prettyString' accepts
${inputType.simpleString} type," +
+ s" not ${left.dataType.simpleString}")
--- End diff --
I think it's better to generate a different error message for
`BinaryOperator`, as 2 children have same type and same expected type, we don't
need to follow `ExpectsInputTypes` to report type error for both left and right.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]