mihaibudiu commented on code in PR #3571:
URL: https://github.com/apache/calcite/pull/3571#discussion_r1428356182


##########
site/_docs/reference.md:
##########
@@ -2806,14 +2806,14 @@ BigQuery's type system uses confusingly different names 
for types and functions:
 | h s | string1 NOT RLIKE string2                    | Whether *string1* does 
not match regex pattern *string2* (similar to `NOT LIKE`, but uses Java regex)
 | b o | RPAD(string, length[, pattern ])             | Returns a string or 
bytes value that consists of *string* appended to *length* with *pattern*
 | b o | RTRIM(string)                                | Returns *string* with 
all blanks removed from the end
-| b | SAFE_ADD(numeric1, numeric2)                   | Returns *numeric1* + 
*numeric2*, or NULL on overflow
+| b | SAFE_ADD(numeric1, numeric2)                   | Returns *numeric1* + 
*numeric2*, or NULL on overflow.  Only supports BIGINT, DOUBLE, or DECIMAL 
arguments

Review Comment:
   But this is exactly how all SQL functions work. For example, trigonometric 
functions are only defined for DOUBLE values. When you call them the compiler 
inserts an implicit cast for the argument to convert it to double. This kind of 
"internal processing" happens almost always, it has nothing to do with these 
functions. It is really part of the definition of SQL. These functions indeed 
can only use the types you enumerate, if you use a value with another type as 
argument it will be cast to one of these three types. That is exactly what I am 
documenting.
   
   What is important in this case is to understand that one cannot use SAFE_* 
to perform safe computations on integers. If you do SAFE_ADD(int, int) the 
result will be a BIGINT. If you try to assign this to an integer column and it 
overflows you will get an exception, which is completely unexpected since this 
is what the SAFE function was designed to avoid. You also need a SAFE_CAST if 
you want to avoid the error.



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

Reply via email to