stefankandic commented on code in PR #49103: URL: https://github.com/apache/spark/pull/49103#discussion_r1899530240
########## sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CollationTypeCoercion.scala: ########## @@ -461,6 +421,66 @@ object CollationTypeCoercion { else right } } + + /** + * Throws an analysis exception if the new data type has indeterminate collation, + * and the expression is not allowed to have inputs with indeterminate collations. + */ + private def checkIndeterminateCollation(expression: Expression, newDataType: DataType): Unit = { + if (shouldFailWithIndeterminateCollation(expression, newDataType)) { + expression.failAnalysis( + errorClass = "INDETERMINATE_COLLATION_IN_EXPRESSION", + messageParameters = Map("expr" -> toSQLExpr(expression))) + } + } + + /** + * Returns whether the given expression which isn't allowed to have inputs with indeterminate + * collations has indeterminate collation. + */ + private def shouldFailWithIndeterminateCollation(expression: Expression): Boolean = { + def getDataTypeSafe(e: Expression): DataType = try { + e.dataType + } catch { + case _: Throwable => NullType + } + + expression.children.exists(child => expression.resolved && Review Comment: Good catch, this was supposed to check if the child is resolved! However we don't need this at all since we are only running the coercion if the children are resolved: https://github.com/apache/spark/blob/18bbddd2fe2dba04ab311e35ebdc6d69614c170f/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/CollationTypeCasts.scala#L25 -- 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: reviews-unsubscr...@spark.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org For additional commands, e-mail: reviews-h...@spark.apache.org