cloud-fan commented on a change in pull request #25198: [SPARK-28443][SQL]
Spark sql add exception when create field type NullType
URL: https://github.com/apache/spark/pull/25198#discussion_r312005630
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
##########
@@ -393,6 +394,75 @@ case class PreprocessTableInsertion(conf: SQLConf)
extends Rule[LogicalPlan] {
}
}
+/**
+ * SPARK-28443: fail the DDL command if it creates a table with null-type
columns
+ */
+object DDLCheck extends (LogicalPlan => Unit) {
+
+ def failAnalysis(msg: String): Unit = { throw new AnalysisException(msg) }
+
+ def throwWhenExistsNullType(dataType: DataType): Unit = {
+ dataType match {
+ case ArrayType(elementType, _) =>
+ throwWhenExistsNullType(elementType)
+
+ case MapType(keyType, valueType, _) =>
+ throwWhenExistsNullType(keyType)
+ throwWhenExistsNullType(valueType)
+
+ case StructType(fields) =>
+ fields.foreach{field => throwWhenExistsNullType(field.dataType)}
+
+ case other if other == NullType =>
+ failAnalysis("DataType NullType is not supported for create table.")
Review comment:
how about "cannot create tables with null-type column/field"
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]