huaxingao commented on a change in pull request #29837:
URL: https://github.com/apache/spark/pull/29837#discussion_r505898587
##########
File path: docs/sql-ref-datatypes.md
##########
@@ -314,3 +314,151 @@ SELECT COUNT(*), c2 FROM test GROUP BY c2;
| 3| Infinity|
+---------+---------+
```
+
+### Type Conversion
+
+In general, an expression can contain different data types and type conversion
is the transformation of some data types into others in order to resolve type
mismatches.
+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
+
+Type Coercion refers to the automatic or implicit conversion of values from
one type to another when you need to to resolve type mismatches.
+The following matrix shows the resulting type to which they are implicitly
converted to resolve an expression involving different data types.
+
+**Numeric expressions**:
Review comment:
super nit: Numeric expressions -> Numeric Expressions?
##########
File path: docs/sql-ref-datatypes.md
##########
@@ -314,3 +314,151 @@ SELECT COUNT(*), c2 FROM test GROUP BY c2;
| 3| Infinity|
+---------+---------+
```
+
+### Type Conversion
+
+In general, an expression can contain different data types and type conversion
is the transformation of some data types into others in order to resolve type
mismatches.
+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
+
+Type Coercion refers to the automatic or implicit conversion of values from
one type to another when you need to to resolve type mismatches.
+The following matrix shows the resulting type to which they are implicitly
converted to resolve an expression involving different data types.
+
+**Numeric expressions**:
+
+| |ByteType |ShortType |IntegerType |LongType |FloatType
|DoubleType |StringType |DecimalType |
+|---------------|-----------|-----------|------------|-----------|----------------------|----------------------|-----------|-----------------------------|
+|**ByteType** |-- |ShortType |IntegerType |LongType |FloatType
|DoubleType |DoubleType |DecimalType(3,0)<sup>1</sup> |
+|**ShortType** |ShortType |-- |IntegerType |LongType |FloatType
|DoubleType |DoubleType |DecimalType(5,0)<sup>1</sup> |
+|**IntegerType**|IntegerType|IntegerType|-- |LongType |FloatType
|DoubleType |DoubleType |DecimalType(10,0)<sup>1</sup>|
+|**LongType** |LongType |LongType |LongType |-- |FloatType
|DoubleType |DoubleType |DecimalType(20,0)<sup>1</sup>|
+|**FloatType** |FloatType |FloatType |FloatType |FloatType |--
|DoubleType |DoubleType |DoubleType |
+|**DoubleType** |DoubleType |DoubleType |DoubleType |DoubleType |DoubleType
|-- |DoubleType |DoubleType |
+|**StringType** |DoubleType |DoubleType |DoubleType |DoubleType |DoubleType
|DoubleType |-- |DoubleType |
+|**DecimalType**|DecimalType|DecimalType|DecimalType
|DecimalType|DoubleType<sup>2</sup>|DoubleType<sup>2</sup>|DoubleType |--
|
+
+**Note 1**: DecimalType(precision,scale)
+**Note 2**: In these cases DecimalType can lose precision, there is no common
type for decimal and double because double's range is larger than decimal, and
yet decimal is more precise than double so when we cast Decimaltype into
DobleType it could lose precision.
+
+**Time expressions**:
Review comment:
super nit: Time expressions -> Time Expressions?
##########
File path: docs/sql-ref-datatypes.md
##########
@@ -314,3 +314,151 @@ SELECT COUNT(*), c2 FROM test GROUP BY c2;
| 3| Infinity|
+---------+---------+
```
+
+### Type Conversion
+
+In general, an expression can contain different data types and type conversion
is the transformation of some data types into others in order to resolve type
mismatches.
+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
+
+Type Coercion refers to the automatic or implicit conversion of values from
one type to another when you need to to resolve type mismatches.
+The following matrix shows the resulting type to which they are implicitly
converted to resolve an expression involving different data types.
+
+**Numeric expressions**:
+
+| |ByteType |ShortType |IntegerType |LongType |FloatType
|DoubleType |StringType |DecimalType |
+|---------------|-----------|-----------|------------|-----------|----------------------|----------------------|-----------|-----------------------------|
+|**ByteType** |-- |ShortType |IntegerType |LongType |FloatType
|DoubleType |DoubleType |DecimalType(3,0)<sup>1</sup> |
+|**ShortType** |ShortType |-- |IntegerType |LongType |FloatType
|DoubleType |DoubleType |DecimalType(5,0)<sup>1</sup> |
+|**IntegerType**|IntegerType|IntegerType|-- |LongType |FloatType
|DoubleType |DoubleType |DecimalType(10,0)<sup>1</sup>|
+|**LongType** |LongType |LongType |LongType |-- |FloatType
|DoubleType |DoubleType |DecimalType(20,0)<sup>1</sup>|
+|**FloatType** |FloatType |FloatType |FloatType |FloatType |--
|DoubleType |DoubleType |DoubleType |
+|**DoubleType** |DoubleType |DoubleType |DoubleType |DoubleType |DoubleType
|-- |DoubleType |DoubleType |
+|**StringType** |DoubleType |DoubleType |DoubleType |DoubleType |DoubleType
|DoubleType |-- |DoubleType |
+|**DecimalType**|DecimalType|DecimalType|DecimalType
|DecimalType|DoubleType<sup>2</sup>|DoubleType<sup>2</sup>|DoubleType |--
|
+
+**Note 1**: DecimalType(precision,scale)
+**Note 2**: In these cases DecimalType can lose precision, there is no common
type for decimal and double because double's range is larger than decimal, and
yet decimal is more precise than double so when we cast Decimaltype into
DobleType it could lose precision.
+
+**Time expressions**:
+
+| |DateType |TimestampType |
+|------------------|-------------|--------------|
+|**DateType** |-- |TimestampType |
+|**TimestampType** |TimestampType|-- |
+
+
+**Possible implicit conversions**:
Review comment:
super nit: Possible implicit conversions -> Possible Implicit
Conversions?
----------------------------------------------------------------
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]