[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-08-08 Thread GitBox
ulysses-you 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_r312077202
 
 

 ##
 File path: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
 ##
 @@ -2516,4 +2516,13 @@ class HiveDDLSuite
   }
 }
   }
+
+  test("SPARK-28443: fail the DDL command if it creates a table with null-type 
columns") {
 
 Review comment:
   I forget that spark not support `create table t as select null as c` now. 
Remove this.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-08-08 Thread GitBox
ulysses-you 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_r312056710
 
 

 ##
 File path: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
 ##
 @@ -2516,4 +2516,13 @@ class HiveDDLSuite
   }
 }
   }
+
+  test("SPARK-28443: fail the DDL command if it creates a table with null-type 
columns") {
+withTable("t") {
+  val e = intercept[AnalysisException]{
+sql(s"CREATE TABLE t as SELECT NULL AS c")
 
 Review comment:
   Nested fields are tested in `CatalogSuite`. This UT is just to confirm that 
cannot using CTAS with `NullType`. I have not seen other place confirm this.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-08-08 Thread GitBox
ulysses-you 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_r312056710
 
 

 ##
 File path: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
 ##
 @@ -2516,4 +2516,13 @@ class HiveDDLSuite
   }
 }
   }
+
+  test("SPARK-28443: fail the DDL command if it creates a table with null-type 
columns") {
+withTable("t") {
+  val e = intercept[AnalysisException]{
+sql(s"CREATE TABLE t as SELECT NULL AS c")
 
 Review comment:
   Nested fields are tested in `CatalogSuite`. This UT is just to confirm that 
cannot using CTAS with `NullType`. I have not seen other place confirm this.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-08-08 Thread GitBox
ulysses-you 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_r312056710
 
 

 ##
 File path: 
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala
 ##
 @@ -2516,4 +2516,13 @@ class HiveDDLSuite
   }
 }
   }
+
+  test("SPARK-28443: fail the DDL command if it creates a table with null-type 
columns") {
+withTable("t") {
+  val e = intercept[AnalysisException]{
+sql(s"CREATE TABLE t as SELECT NULL AS c")
 
 Review comment:
   Nested fields are tested in `CatalogSuite`. This UT is just to confirm that 
cannot using CTAS with `NullType`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-08-08 Thread GitBox
ulysses-you 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_r311948969
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
 ##
 @@ -393,6 +393,60 @@ 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")
+
+  case _ => // OK
+}
+  }
+
+  def checkSchema(schema: StructType): Unit = {
+schema.foreach{field => throwWhenExistsNullType(field.dataType)}
+  }
+
+  override def apply(plan: LogicalPlan): Unit = {
+plan.foreach {
+  case CreateTable(tableDesc, _, _) =>
+checkSchema(tableDesc.schema)
+
+  case CreateV2Table(_, _, tableSchema, _, _, _) =>
 
 Review comment:
   OK, and also add `AlterTable`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-08-07 Thread GitBox
ulysses-you 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_r311809754
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
 ##
 @@ -393,6 +393,43 @@ case class PreprocessTableInsertion(conf: SQLConf) 
extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * SPARK-28443: Spark sql add exception when create field type NullType
+ */
+object DDLCheck extends (LogicalPlan => Unit) {
+
+  def failAnalysis(msg: String): Unit = { throw new AnalysisException(msg) }
+
+  def throwWhenExistsNullType(schema: StructType): Unit = {
+if (schema.exists(f => DataTypes.NullType.sameType(f.dataType))) {
 
 Review comment:
   Hive also forbid nested field with NullType


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-08-07 Thread GitBox
ulysses-you 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_r311809754
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
 ##
 @@ -393,6 +393,43 @@ case class PreprocessTableInsertion(conf: SQLConf) 
extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * SPARK-28443: Spark sql add exception when create field type NullType
+ */
+object DDLCheck extends (LogicalPlan => Unit) {
+
+  def failAnalysis(msg: String): Unit = { throw new AnalysisException(msg) }
+
+  def throwWhenExistsNullType(schema: StructType): Unit = {
+if (schema.exists(f => DataTypes.NullType.sameType(f.dataType))) {
 
 Review comment:
   Hive also forbid nested filed with NullType


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-08-07 Thread GitBox
ulysses-you 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_r311808608
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
 ##
 @@ -393,6 +393,43 @@ case class PreprocessTableInsertion(conf: SQLConf) 
extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * SPARK-28443: Spark sql add exception when create field type NullType
+ */
+object DDLCheck extends (LogicalPlan => Unit) {
+
+  def failAnalysis(msg: String): Unit = { throw new AnalysisException(msg) }
+
+  def throwWhenExistsNullType(schema: StructType): Unit = {
+if (schema.exists(f => DataTypes.NullType.sameType(f.dataType))) {
+  failAnalysis("DataType NullType is not supported for create table ")
+}
+  }
+
+  override def apply(plan: LogicalPlan): Unit = {
+plan.foreach {
+  case CreateTable(tableDesc, _, _) =>
+throwWhenExistsNullType(tableDesc.schema)
+
+  case CreateV2Table(_, _, tableSchema, _, _, _) =>
+throwWhenExistsNullType(tableSchema)
+
+  // DataSourceAnalysis will convert CreateTable to 
CreateDataSourceTableCommand before check
+  case CreateDataSourceTableCommand(table, _) =>
+throwWhenExistsNullType(table.schema)
+
+  // HiveAnalysis will convert CreateTable to CreateTableCommand before 
check
+  case CreateTableCommand(table, _) =>
+throwWhenExistsNullType(table.schema)
+
+  case ReplaceTable(_, _, tableSchema, _, _, _) =>
+throwWhenExistsNullType(tableSchema)
+
+  case _ => // OK
 
 Review comment:
   Spark allowed `CreateTableAsSelect` and `ReplaceTableAsSelect ` with 
NullType, isn't it ?
   E.g. `create table test as select null as c1`.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-07-24 Thread GitBox
ulysses-you 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_r307059217
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
 ##
 @@ -393,6 +393,42 @@ case class PreprocessTableInsertion(conf: SQLConf) 
extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * SPARK-28443: Spark sql add exception when create field type NullType
+ */
+object DDLCheck extends (LogicalPlan => Unit) {
+
+  def failAnalysis(msg: String): Unit = { throw new AnalysisException(msg) }
+
+  override def apply(plan: LogicalPlan): Unit = {
+plan.foreach {
+  case ct: CreateTable if ct.tableDesc.schema.exists { f =>
+DataTypes.NullType.sameType(f.dataType)
+  } =>
+failAnalysis("DataType NullType is not supported for create table ")
+
+  case ct2: CreateV2Table if ct2.tableSchema.exists { f =>
+DataTypes.NullType.sameType(f.dataType)
+  } =>
+failAnalysis("DataType NullType is not supported for create table")
+
+  // DataSourceStrategy will convert CreateTable to 
CreateDataSourceTableCommand before check
+  case cdstc: CreateDataSourceTableCommand if cdstc.table.schema.exists { 
f =>
 
 Review comment:
   Thanks for your advise.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-07-22 Thread GitBox
ulysses-you 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_r306109902
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
 ##
 @@ -393,6 +393,21 @@ case class PreprocessTableInsertion(conf: SQLConf) 
extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * SPARK-28443: Spark sql add exception when create field type NullType
+ */
+object CreateTableCheck extends Rule[LogicalPlan] {
+  override def apply(plan: LogicalPlan): LogicalPlan = {
+plan match {
+  case ct: CreateTable if ct.tableDesc.schema.exists { f =>
 
 Review comment:
   ok, I will check this later


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] ulysses-you commented on a change in pull request #25198: [SPARK-28443][SQL] Spark sql add exception when create field type NullType

2019-07-22 Thread GitBox
ulysses-you 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_r306092603
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
 ##
 @@ -393,6 +393,21 @@ case class PreprocessTableInsertion(conf: SQLConf) 
extends Rule[LogicalPlan] {
   }
 }
 
+/**
+ * SPARK-28443: Spark sql add exception when create field type NullType
+ */
+object CreateTableCheck extends Rule[LogicalPlan] {
+  override def apply(plan: LogicalPlan): LogicalPlan = {
+plan match {
+  case ct: CreateTable if ct.tableDesc.schema.exists { f =>
 
 Review comment:
   I consider that it's a little different between create table(DDL) and insert 
data (DML).  Maybe split in two rules ?


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org