maropu commented on a change in pull request #29837:
URL: https://github.com/apache/spark/pull/29837#discussion_r502787239
##########
File path: docs/sql-ref-datatypes.md
##########
@@ -314,3 +314,128 @@ SELECT COUNT(*), c2 FROM test GROUP BY c2;
| 3| Infinity|
+---------+---------+
```
+
+### Type conversion
+
+In general, an expression can contain different data types, type conversion is
the transformation of some data types into others in order to solve the
expressions.
+Spark supports both implicit conversions by type coercion and explicit
conversions by explicit casting and store assignment casting.
+
+#### Type coercion in operations between different types
+
+The following matrix shows the resulting type to which they are implicitly
converted to resolve an expression involving different data types
+
+Numeric expresions:
+
+| |ByteType |ShortType |IntegerType |LongType |FloatType
|DoubleType |StringType |
+|---------------|-----------|-----------|------------|----------|----------|-----------|-----------|
+|**ByteType** |-- |ShortType |IntegerType |LongType |FloatType
|DoubleType |DoubleType |
+|**ShortType** |ShortType |-- |IntegerType |LongType |FloatType
|DoubleType |DoubleType |
+|**IntegerType**|IntegerType|IntegerType|-- |LongType |FloatType
|DoubleType |DoubleType |
+|**LongType** |LongType |LongType |LongType |-- |FloatType
|DoubleType |DoubleType |
+|**FloatType** |FloatType |FloatType |FloatType |FloatType |--
|DoubleType |DoubleType |
+|**DoubleType** |DoubleType |DoubleType |DoubleType |DoubleType|DoubleType|--
|DoubleType |
+|**StringType** |DoubleType |DoubleType |DoubleType
|DoubleType|DoubleType|DoubleType |-- |
+
+The case of DecimalType, is treated differently, for example, there is no
common type for double and decimal because double's range is larger than
decimal, and yet decimal is more precise than double, but in an expresion, we
would cast the decimal into double.
+
+Time expresions:
+
+| |DateType |TimestampType |
+|------------------|-------------|--------------|
+|**DateType** |-- |TimestampType |
+|**TimestampType** |TimestampType|-- |
+
+#### Type coercion examples
+
+```sql
+DESCRIBE TABLE numericTable;
++-------------+---------+-------+
+|col_name |data_type|comment|
++-------------+---------+-------+
+|integerColumn|int |null |
+|doubleColumn |double |null |
++-------------+---------+-------+
+
+DESCRIBE SELECT integerColumn + doubleColumn as result FROM numericTable;
++--------+---------+-------+
+|col_name|data_type|comment|
++--------+---------+-------+
+| result| double| null|
++--------+---------+-------+
+
+```
+
+```sql
+DESCRIBE dateTable;
++---------------+---------+-------+
+| col_name|data_type|comment|
++---------------+---------+-------+
+| dateColumn| date| null|
+|timestampColumn|timestamp| null|
++---------------+---------+-------+
+
+SELECT MONTHS_BETWEEN(dateColumn,timestampColumn) FROM dateTable;
+
+```
+
+#### Explicit casting and store assignment casting
Review comment:
`Explicit casting and store assignment casting` -> `Explicit Casting and
Store Assignment Casting`
----------------------------------------------------------------
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]