Details
-
Sub-task
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
BigQuery offers the SAFE_MULTIPLY(value1, value2) function which returns the result of value1 * value2. If overflow occurs, null is returned.
The correct return type may be inferred according to the BigQuery docs.
BigQuery treats all integer types as aliases for BIGINT (which BigQuery calls INT64. Therefore, all integer types (and the result of their multiplication) should be treated as BIGINT. This means, for example, multiplying two TINYINT that would cause TINYINT overflow, would be okay as long as the result does not also cause BIGINT overflow. BIGINT translates to Java's LONG whose bounds are used to determine whether overflow has occurred.
BigQuery also supports Decimal and BigDecimal types, which maps to Calcite's DECIMAL type. Their overflow is determined using their precision and scale, and if they exceed BigQuery's limits, then overflow has occurred. Because Calcite does not differentiate between DECIMAL and BIGDECIMAL, there are only 9 possible combinations of operand types, although the chart linked above has 16.
BigQuery's FLOAT64 maps to Java's DOUBLE and it's MAX_VALUE and MIN_VALUE are used to determine whether overflow has occurred.
Any questions about this implementation are welcomed and appreciated.
Attachments
Issue Links
- links to