raminqaf commented on code in PR #30185: URL: https://github.com/apache/flink/pull/30185#discussion_r4771556683
########## docs/data/functions/mathematical/arithmetic_operators.yml: ########## @@ -0,0 +1,156 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License + +name: Arithmetic operators +summary: Returns the sum, difference, product, quotient or negation of numbers, with `+`, `-`, `*` and `/`. + +syntax: + sql: | + +expr + -expr + expr1 + expr2 + expr1 - expr2 + expr1 * expr2 + expr1 / expr2 + java: | + negative($("expr")) + $("expr1").plus(expr2) + $("expr1").minus(expr2) + $("expr1").times(expr2) + $("expr1").dividedBy(expr2) + python: | + -col("expr") + col("expr1") + expr2 + col("expr1") - expr2 + col("expr1") * expr2 + col("expr1") / expr2 + +arguments: + - name: expr, expr1, expr2 + type: Any numeric type + required: true + +returns: + description: The sum, difference, product or quotient of `expr1` and `expr2`. Unary `-` flips the sign of `expr`, and unary `+` returns it unchanged. A division of two integers drops the fraction, toward zero. + nulls: Returns NULL if an operand is NULL, and for a `DECIMAL` result that needs more than 38 digits. With NOT NULL operands, that result fails the job instead. + type: Two integer types give the larger of the two. An integer with a `FLOAT` or `DOUBLE` gives that type, and with a `DECIMAL` a `DECIMAL`. A `DECIMAL` with a `FLOAT` or `DOUBLE` gives `DOUBLE`. A `DOUBLE` with a `FLOAT` gives `DOUBLE`, but a `FLOAT` with a `DOUBLE` gives `FLOAT` instead of `DOUBLE`. Unary `+` and `-` keep the type of `expr`. NOT NULL if every operand is NOT NULL. + +notes: + - The scale of a `DECIMAL` result follows from the scales `s1` and `s2` of the operands and the precision `p2` of the second one. `+` and `-` give the larger of `s1` and `s2`, `*` gives `s1 + s2`, and `/` gives `s1 + p2 + 1`, but at least 6. An integer counts as a `DECIMAL` with scale 0 and the precision of its type, such as 10 for `INT`. The precision is what the result needs, up to 38. A result that would need more than 38 digits keeps fewer decimal places, but at least 6, or all of them if it has fewer than 6. + - An integer result that doesn't fit its type wraps around without an error, for `TINYINT`, `SMALLINT`, `INT` and `BIGINT` alike. `127 + 127` is `-2` for two `TINYINT` operands, and `2147483647 + 1` is `-2147483648` for two `INT` operands. Cast an operand to a wider type or to `DECIMAL` to get the right result. + - A `DECIMAL` result that needs more than 38 digits is NULL, without an error, such as `d + d` for the largest `DECIMAL(38, 0)`. `IS NULL` on it is FALSE all the same, and `IS NOT NULL` TRUE. When both operands are NOT NULL, the result type is NOT NULL too, so selecting the result fails the job instead. Review Comment: Added. That's with NOT NULL operands, since with nullable ones both return -1. I'll file it apart from FLINK-24847. -- 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]
