cloud-fan commented on code in PR #41763:
URL: https://github.com/apache/spark/pull/41763#discussion_r1345272360
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/LogicalPlan.scala:
##########
@@ -325,6 +326,61 @@ object LogicalPlanIntegrity {
LogicalPlanIntegrity.hasUniqueExprIdsForOutput(plan))
}
+ /**
+ * This method validates there are no dangling attribute references.
+ * Returns an error message if the check does not pass, or None if it does
pass.
+ */
+ def validateNoDanglingReferences(plan: LogicalPlan): Option[String] = {
+ plan.collectFirst {
+ // DML commands and multi instance relations (like InMemoryRelation
caches)
+ // have different output semantics than typical queries.
+ case _: Command => None
+ case _: MultiInstanceRelation => None
+ case n if canGetOutputAttrs(n) =>
+ if ( n.missingInput.nonEmpty) {
+ Some(s"Aliases ${ n.missingInput.mkString(", ")} are dangling " +
+ s"in the references for plan:\n ${n.treeString}")
+ } else {
+ None
+ }
+ }.flatten
+ }
+
+ /**
+ * Validate that the grouping key types in Aggregate plans are valid.
+ * Returns an error message if the check fails, or None if it succeeds.
+ */
+ def validateGroupByTypes(plan: LogicalPlan): Option[String] = {
+ plan.collectFirst {
+ case a @ Aggregate(groupingExprs, _, _) =>
+ val badExprs =
groupingExprs.filter(_.dataType.isInstanceOf[MapType]).map(_.toString)
+ if (badExprs.nonEmpty) {
+ Some(s"Grouping expressions ${badExprs.mkString(", ")} cannot be of
type Map " +
+ s"for plan:\n ${a.treeString}")
+ } else {
+ None
+ }
+ }.flatten
+ }
+
+ /**
+ * Validate that the aggregation expressions in Aggregate plans are valid.
+ * Returns an error message if the check fails, or None if it succeeds.
+ */
+ def validateAggregateExpressions(plan: LogicalPlan): Option[String] = {
+ plan.collectFirst {
+ case a: Aggregate =>
+ try {
+ ExprUtils.assertValidAggregation(a)
+ None
+ } catch {
+ case _: AnalysisException =>
+ Some(s"Aggregate: ${a.toString} is not a valid aggregate
expression")
Review Comment:
shall we take the actual error message? `case e: AnalysisException =>
Some(e.getMessage)`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]