[GitHub] [spark] cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] Only allow type upcasting when inserting table

2019-06-12 Thread GitBox
cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] 
Only allow type upcasting when inserting table
URL: https://github.com/apache/spark/pull/24806#discussion_r292768996
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ##
 @@ -128,8 +128,10 @@ object Cast {
 case _ if from == to => true
 case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
 case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
-case (f, t) if legalNumericPrecedence(f, t) => true
+case (f: NumericType, t: NumericType) if legalNumericPrecedence(f, t) => 
true
+
 case (DateType, TimestampType) => true
+case (NullType, _) => false
 
 Review comment:
   Why can't we upcast null to other nullable types? I think it's pretty common 
to write `INSERT INTO tbl VALUES (1, null)`


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] cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] Only allow type upcasting when inserting table

2019-06-12 Thread GitBox
cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] 
Only allow type upcasting when inserting table
URL: https://github.com/apache/spark/pull/24806#discussion_r292768996
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Cast.scala
 ##
 @@ -128,8 +128,10 @@ object Cast {
 case _ if from == to => true
 case (from: NumericType, to: DecimalType) if to.isWiderThan(from) => true
 case (from: DecimalType, to: NumericType) if from.isTighterThan(to) => true
-case (f, t) if legalNumericPrecedence(f, t) => true
+case (f: NumericType, t: NumericType) if legalNumericPrecedence(f, t) => 
true
+
 case (DateType, TimestampType) => true
+case (NullType, _) => false
 
 Review comment:
   Why can't we upcast null to other nullable types? I think it's pretty to 
write `INSERT INTO tbl VALUES (1, null)`


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] cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] Only allow type upcasting when inserting table

2019-06-12 Thread GitBox
cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] 
Only allow type upcasting when inserting table
URL: https://github.com/apache/spark/pull/24806#discussion_r292768394
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/rules.scala
 ##
 @@ -356,8 +358,28 @@ case class PreprocessTableInsertion(conf: SQLConf) 
extends Rule[LogicalPlan] {
   s"including ${staticPartCols.size} partition column(s) having 
constant value(s).")
 }
 
-val newQuery = DDLPreprocessingUtils.castAndRenameQueryOutput(
-  insert.query, expectedColumns, conf)
+val newQuery = if 
(conf.getConf(SQLConf.LEGACY_INSERT_TABLE_TYPE_COERCION)) {
+  DDLPreprocessingUtils.castAndRenameQueryOutput(insert.query, 
expectedColumns, conf)
+} else {
+  val errors = new mutable.ArrayBuffer[String]()
 
 Review comment:
   Have we moved it?


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] cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] Only allow type upcasting when inserting table

2019-06-12 Thread GitBox
cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] 
Only allow type upcasting when inserting table
URL: https://github.com/apache/spark/pull/24806#discussion_r292768054
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/encoders/EncoderResolutionSuite.scala
 ##
 @@ -230,11 +230,12 @@ class EncoderResolutionSuite extends PlanTest {
   castSuccess[Long, String]
   castSuccess[Int, java.math.BigDecimal]
   castSuccess[Long, java.math.BigDecimal]
+  castSuccess[Double, java.math.BigDecimal]
 
 Review comment:
   How is this supported?


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] cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] Only allow type upcasting when inserting table

2019-06-12 Thread GitBox
cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] 
Only allow type upcasting when inserting table
URL: https://github.com/apache/spark/pull/24806#discussion_r292767749
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/DataSourceV2AnalysisSuite.scala
 ##
 @@ -440,16 +439,15 @@ abstract class DataSourceV2AnalysisSuite extends 
AnalysisTest {
   StructField("y", DoubleType))).toAttributes)
 
 val query = TestRelation(StructType(Seq(
-  StructField("x", DoubleType),
+  StructField("x", FloatType),
 
 Review comment:
   ditto


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] cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] Only allow type upcasting when inserting table

2019-06-12 Thread GitBox
cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] 
Only allow type upcasting when inserting table
URL: https://github.com/apache/spark/pull/24806#discussion_r292767723
 
 

 ##
 File path: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/analysis/DataSourceV2AnalysisSuite.scala
 ##
 @@ -290,15 +290,14 @@ abstract class DataSourceV2AnalysisSuite extends 
AnalysisTest {
   StructField("y", DoubleType))).toAttributes)
 
 val query = TestRelation(StructType(Seq(
-  StructField("x", DoubleType),
+  StructField("x", FloatType),
 
 Review comment:
   why this change?


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] cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] Only allow type upcasting when inserting table

2019-06-12 Thread GitBox
cloud-fan commented on a change in pull request #24806: [WIP][SPARK-27856][SQL] 
Only allow type upcasting when inserting table
URL: https://github.com/apache/spark/pull/24806#discussion_r292767210
 
 

 ##
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/types/DecimalType.scala
 ##
 @@ -89,6 +90,7 @@ case class DecimalType(precision: Int, scale: Int) extends 
FractionalType {
   (precision - scale) <= (dt.precision - dt.scale) && scale <= dt.scale
 case dt: IntegralType =>
   isTighterThan(DecimalType.forType(dt))
+// For DoubleType/FloatType, the value can be NaN, PositiveInfinity or 
NegativeInfinity.
 
 Review comment:
   For `isWiderThan`, yes it's not safe to cast float/double to decimal because 
of NaN stuff.
   
   For `isTighterThan`, I think it's safe to cast decimal to float/double if 
the precision doesn't exceed?


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