gengliangwang commented on a change in pull request #31349:
URL: https://github.com/apache/spark/pull/31349#discussion_r572987635



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/AnsiTypeCoercion.scala
##########
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.catalyst.analysis
+
+import org.apache.spark.sql.catalyst.analysis.TypeCoercion.numericPrecedence
+import org.apache.spark.sql.catalyst.expressions._
+import org.apache.spark.sql.catalyst.expressions.aggregate._
+import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
+import org.apache.spark.sql.catalyst.rules.Rule
+import org.apache.spark.sql.types._
+
+/**
+ * In Spark ANSI mode, the type coercion rules are based on the type 
precedence lists of the input
+ * data types.
+ * As per the section "Type precedence list determination" of "ISO/IEC 
9075-2:2011
+ * Information technology - Database languages - SQL - Part 2: Foundation 
(SQL/Foundation)",
+ * the type precedence lists of primitive data types are as following:
+ *   * Byte: Byte, Short, Int, Long, Decimal, Float, Double
+ *   * Short: Short, Int, Long, Decimal, Float, Double
+ *   * Int: Int, Long, Decimal, Float, Double
+ *   * Long: Long, Decimal, Float, Double
+ *   * Decimal: Any wider Numeric type
+ *   * Float: Float, Double
+ *   * Double: Double
+ *   * String: String
+ *   * Date: Date, Timestamp
+ *   * Timestamp: Timestamp
+ *   * Binary: Binary
+ *   * Boolean: Boolean
+ *   * Interval: Interval
+ * As for complex data types, Spark will determine the precedent list 
recursively based on their
+ * sub-types.
+ *
+ * With the definition of type precedent list, the general type coercion rules 
are as following:
+ *   * Data type S is allowed to be implicitly cast as type T iff T is in the 
precedence list of S
+ *   * Comparison is allowed iff the data type precedence list of both sides 
has at least one common
+ *     element. When evaluating the comparison, Spark casts both sides as the 
tightest common data
+ *     type of their precedent lists.
+ *   * There should be at least one common data type among all the children's 
precedence lists for
+ *     the following operators. The data type of the operator is the tightest 
common precedent
+ *     data type.
+ *       * In
+ *       * Except(odd)

Review comment:
       Oh, it's a mistake, I had a question about it before. Let me remove 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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to