edponce commented on a change in pull request #10395:
URL: https://github.com/apache/arrow/pull/10395#discussion_r656468614



##########
File path: cpp/src/arrow/compute/api_scalar.cc
##########
@@ -50,6 +50,11 @@ namespace compute {
 SCALAR_ARITHMETIC_UNARY(AbsoluteValue, "abs", "abs_checked")
 SCALAR_ARITHMETIC_UNARY(Negate, "negate", "negate_checked")
 
+Result<Datum> Sign(const Datum& arg, SignOptions options, ExecContext* ctx) {
+  auto func_name = options.with_signed_zero ? "sign_with_signed_zero" : "sign";

Review comment:
       Also, I consider that `copysign` should not be exposed as a compute 
function but rather used internally, and instead we should expose `sign` and 
`sign_with_signed_zero` (implementations may use `copysign(x, 1)`. The 
rationale for this is that `copysign(x, 1)` is not common in any SQL, 
dataframes library but `sign` is.
   
   A use case of `sign` is to build a custom ranking based on the signedness of 
values.
   For example, consider ranking values relative to a constant value (e.g., 3):
   ```
   SELECT CASE 
       WHEN @a < 3 THEN 0
       WHEN @a = 3 THEN 1
       WHEN @a > 3 THEN 2
   END
   ```
   is not supported because expressions are not allowed in `CASE-WHEN` 
constructs, so a workaround is
   ```
   SELECT CASE SIGN(@a - 3)
       WHEN -1 THEN 0
       WHEN 0 THEN 1
       WHEN 1 THEN 2
   END
   ``` 




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to