paul-rogers commented on code in PR #13671:
URL: https://github.com/apache/druid/pull/13671#discussion_r1073918523


##########
docs/querying/sql-operators.md:
##########
@@ -37,6 +37,10 @@ sidebar_label: "Operators"
 
 Operators in [Druid SQL](./sql.md) typically operate on one or two values and 
return a result based on the values. Types of operators in Druid SQL include 
arithmetic, comparison, logical, and more, as described here. 
 
+When performing math operations, Druid uses the integer datatype unless there 
are double or float values. If double or float values are involved, Druid uses 
double. Note that the highest precision way to store digits in Druid are 64-bit 
integers (long) or 64-bit floats (double). In essence, a double can represent 
52 binary digits, so Druid may return incorrect results for doubles if the 
value exceeds 2^52.
+
+For more information about how Java handles primitive data types and how it 
may impact the results you get, see [Primitive data types in Java are a matter 
of 
precision](https://blogs.oracle.com/javamagazine/post/java-primitive-datatypes-int-float-double).

Review Comment:
   This really punts! The user has no control over the expressions we use. 
Druid is interpreted: _we_ decide how to do casting to get arguments to the 
right type, and we decide on the final result value of our functions. Referring 
to what Java does is not useful except to someone who reads the code, sees 
where we use bits of Java, then works that backward through our type inference 
system.
   
   We should spell out our rules explicitly, which are one of the two bullets 
above. @clintropolis can probably provide details.



##########
docs/querying/sql-operators.md:
##########
@@ -37,6 +37,10 @@ sidebar_label: "Operators"
 
 Operators in [Druid SQL](./sql.md) typically operate on one or two values and 
return a result based on the values. Types of operators in Druid SQL include 
arithmetic, comparison, logical, and more, as described here. 
 
+When performing math operations, Druid uses the integer datatype unless there 
are double or float values. If double or float values are involved, Druid uses 
double. Note that the highest precision way to store digits in Druid are 64-bit 
integers (long) or 64-bit floats (double). In essence, a double can represent 
52 binary digits, so Druid may return incorrect results for doubles if the 
value exceeds 2^52.

Review Comment:
   Reword: Druid uses the 64-bit integer (long) data type...
   
   > If double or float values are involved, Druid uses double.
   
   Not sure what this means. Is it:
   
   * If an operation uses float or double values, then the result is double.
   * If an operation uses only float types, the result type is float. If an 
operation uses only double values, or both double and float values, the result 
is double.
   
   Nit: "datatype" is not really a word. Consider "data type". 
   
   Probably worth saying that the precision of float and double are defined by 
Java and by the IEEE standard. Perhaps we can link to those reference materials.



-- 
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.

To unsubscribe, e-mail: [email protected]

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