Airblader commented on a change in pull request #17256: URL: https://github.com/apache/flink/pull/17256#discussion_r709802110
########## File path: flink-python/pyflink/table/expressions.py ########## @@ -544,6 +544,26 @@ def if_then_else(condition: Union[bool, Expression[bool]], if_true, if_false) -> return _ternary_op("ifThenElse", condition, if_true, if_false) +def coalesce(*args) -> Expression: + """ + Returns the first argument that is not NULL. + + If all arguments are NULL, it returns NULL as well. The return type is the least restrictive, common type of all of its arguments. + The return type is nullable if all arguments are nullable as well. + + Examples: + :: + + >>> coalesce(null, "default") # Returns "default" + >>> coalesce(col("f0"), col("f1"), "default") returns the first non-null value among f0 and f1, or "default" if f0 and f1 are both null. Review comment: ```suggestion >>> # Returns the first non-null value among f0 and f1, >>> # or "default" if f0 and f1 are both null >>> coalesce(col("f0"), col("f1"), "default") returns the first non-null value among f0 and f1, or "default" if f0 and f1 are both null. ``` ########## File path: flink-python/pyflink/table/expressions.py ########## @@ -544,6 +544,26 @@ def if_then_else(condition: Union[bool, Expression[bool]], if_true, if_false) -> return _ternary_op("ifThenElse", condition, if_true, if_false) +def coalesce(*args) -> Expression: + """ + Returns the first argument that is not NULL. + + If all arguments are NULL, it returns NULL as well. The return type is the least restrictive, common type of all of its arguments. + The return type is nullable if all arguments are nullable as well. + + Examples: + :: + + >>> coalesce(null, "default") # Returns "default" Review comment: Python doesn't have a `null`, I think this would have to be `None`. I think it's OK to talk about "null" in the docs, but the code example should of course compile. :-) ```suggestion >>> coalesce(None, "default") # Returns "default" ``` ########## File path: flink-table/flink-table-api-scala/src/main/scala/org/apache/flink/table/api/ImplicitExpressionConversions.scala ########## @@ -726,6 +726,25 @@ trait ImplicitExpressionConversions { Expressions.ifThenElse(condition, ifTrue, ifFalse) } + /** + * Returns the first argument that is not NULL. + * + * If all arguments are NULL, it returns NULL as well. The return type is the least + * restrictive, common type of all of its arguments. The return type is nullable if all + * arguments are nullable as well. + * + * For example: + * + * - `coalesce(null, default")` returns `"default"`. + * - `coalesce($"f0", $"f1", "default")` returns the first non-null value among f0 and f1, + * or `"default"` if f0 and f1 are both null Review comment: This isn't yet a code block like with Java. There's also a syntax error in there. ```suggestion * Examples: * {{{ * // Returns "default" * coalesce(null, "default") * * // Returns the first non-null value among f0 and f1, or "default" if f0 and f1 are both null * coalesce($"f0", $"f1", "default") * }}} ``` -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org