huaxingao commented on a change in pull request #28264:
URL: https://github.com/apache/spark/pull/28264#discussion_r414125535
##########
File path: docs/sql-ref-datatypes.md
##########
@@ -706,3 +708,62 @@ The following table shows the type names as well as
aliases used in Spark SQL pa
</table>
</div>
</div>
+
+### Floating Point Special Values
+
+Spark SQL supports several special floating point values in a case-insensitive
manner:
+
+ * Inf/+Inf/Infinity/+Infinity: positive infinity
+ * ```FloatType```: 1.0f / 0.0f, which is equal to the value returned by
<code>java.lang.Float.intBitsToFloat(0x7f800000)</code>.
+ * ```DoubleType```: 1.0 / 0.0, which is equal to the value returned by
<code>java.lang.Double.longBitsToDouble(0x7ff0000000000000L)</code>.
+ * -Inf/-Infinity: negative infinity
+ * ```FloatType```: -1.0f / 0.0f, which is equal to the value returned by
<code>java.lang.Float.intBitsToFloat(0xff800000)</code>.
+ * ```DoubleType```: -1.0 / 0.0, which is equal to the value returned by
<code>java.lang.Double.longBitsToDouble(0xfff0000000000000L)</code>.
+ * NaN: not a number
+ * ```FloatType```: 0.0f / 0.0f, which is equivalent to the value returned
by <code>java.lang.Float.intBitsToFloat(0x7fc00000)</code>.
+ * ```DoubleType```: 0.0d / 0.0, which is equivalent to the value returned
by <code>java.lang.Double.longBitsToDouble(0x7ff8000000000000L)</code>.
+
+#### Examples
+
+{% highlight sql %}
+SELECT double('infinity');
++------------------------+
+|CAST(infinity AS DOUBLE)|
++------------------------+
+| Infinity|
++------------------------+
+
+SELECT float('-inf');
++-------------------+
+|CAST(-inf AS FLOAT)|
++-------------------+
+| -Infinity|
++-------------------+
+
+SELECT float('NaN');
++------------------+
+|CAST(NaN AS FLOAT)|
++------------------+
+| NaN|
++------------------+
+{% endhighlight %}
+
+### Negative/positive Infinity Semantics
+There is special handling for negative and positive infinity. They have the
following semantics:
+
+ - Infinity = Infinity, Inf = Infinity, -Infinity = -Infinity and -Inf =
-Infinity return true.
+ - In aggregations, all Inf/Infinity or -Inf/-Infinity values are grouped
together.
+ - Inf/Infinity/-Inf/Infinity are treated as a normal value in join keys.
Review comment:
In the following paragraph NaN Semantics, it has ```NaN is treated as a
normal value in join keys.``` I want to have something similar.
What I meant is:
```
create table test1 (a int, b double);
insert into test1 values (1, double('infinity'));
create table test2 (c int, b double);
insert into test2 values (3, double('inf'));
select test1.a, test1.b, test2.c FROM test1 inner join test2 on test1.b =
test2.b;
1 Infinity 3
```
so Positive infinity and negative infinity are treated as normal values in
join keys.
----------------------------------------------------------------
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]