Github user dongjoon-hyun commented on a diff in the pull request: https://github.com/apache/spark/pull/14355#discussion_r72480778 --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CheckAnalysis.scala --- @@ -280,6 +267,37 @@ trait CheckAnalysis extends PredicateHelper { case p if p.expressions.exists(PredicateSubquery.hasPredicateSubquery) => failAnalysis(s"Predicate sub-queries can only be used in a Filter: $p") + case _: Union | _: SetOperation => + if (operator.children.length > 1) { + val dataTypes = operator.children.head.output.map(_.dataType) + val firstError = operator.children.find(_.output.map(_.dataType) != dataTypes) + if (firstError.isDefined) { + val tableIndex = operator.children.indexOf(firstError.get) + 1 + if (dataTypes.length != firstError.get.output.length) { + failAnalysis( + s""" + |${operator.nodeName} can only be performed on tables with the same number + |of columns, but the first table has ${dataTypes.length} columns and + |the ${if (tableIndex == 2) "second" else tableIndex + "th"} table has + |${firstError.get.output.length} columns + """.stripMargin.replace("\n", " ").trim()) + } else { + val columnIndex = firstError.get.output.map(_.dataType).zipWithIndex.find { + case (dataType, i) => dataType != dataTypes(i) + }.get._2 + 1 + failAnalysis( + s""" + |${operator.nodeName} can only be performed on tables with the compatible + |column types. The first table has '[${dataTypes.mkString(", ")}]' + |and ${if (tableIndex == 2) "second" else tableIndex + "th"} table has + |'[${firstError.get.output.map(_.dataType).mkString(", ")}]'. The + |${if (columnIndex == 1) "first" else columnIndex + "th"} column is + |incompatible + """.stripMargin.replace("\n", " ").trim()) + } + } + } + --- End diff -- Oh, I see.
--- 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 infrastruct...@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org