You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tz70s (via GitHub)" <gi...@apache.org> on 2023/05/04 16:23:04 UTC

[GitHub] [arrow-datafusion] tz70s opened a new pull request, #6232: Safeguard round function decimal places overflow

tz70s opened a new pull request, #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #6133.
   
   # Rationale for this change
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   
   Safeguard the panic from round function decimal places overflow.
   
   In #6133 stated there could be a type check in binding phase, but likely only work for literals, having runtime check is still needed. Add the runtime check in this PR.
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are these changes tested?
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   Yes
   
   # Are there any user-facing changes?
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   No
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   
   No


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] viirya commented on pull request #6232: Safeguard round function decimal places overflow

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#issuecomment-1641205802

   I think the change is so out-of-dated from latest branch so the diffs are unclear what are actual change from this PR. It'd be better to sync up with latest branch.


-- 
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: github-unsubscribe@arrow.apache.org

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


Re: [PR] Safeguard round function decimal places overflow [datafusion]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6232:
URL: https://github.com/apache/datafusion/pull/6232#issuecomment-2099576194

   Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.


-- 
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: github-unsubscribe@datafusion.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org


[GitHub] [arrow-datafusion] 2010YOUY01 commented on a diff in pull request #6232: Safeguard round function decimal places overflow

Posted by "2010YOUY01 (via GitHub)" <gi...@apache.org>.
2010YOUY01 commented on code in PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#discussion_r1199328005


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -226,21 +227,23 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
                     }
                 )) as ArrayRef)
             }
-            ColumnarValue::Array(decimal_places) => Ok(Arc::new(make_function_inputs2!(

Review Comment:
   Nice work! This overflow issue can be solved during binding in the future(hopefully...), I think it's not necessary to change the existing macro 🤔 



##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -290,6 +295,14 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+fn round_downcast_decimal_places(decimal_place: i64) -> Result<i32> {

Review Comment:
   I noticed most small helpers inside execution are macros to guarantee inline for performance, should we make this function macro?



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] tz70s commented on a diff in pull request #6232: Safeguard round function decimal places overflow

Posted by "tz70s (via GitHub)" <gi...@apache.org>.
tz70s commented on code in PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#discussion_r1226999164


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -290,6 +295,14 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+fn round_downcast_decimal_places(decimal_place: i64) -> Result<i32> {

Review Comment:
   Thanks, I made it as a macro instead!



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #6232: Safeguard round function decimal places overflow

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#discussion_r1227069601


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -287,6 +288,16 @@ pub fn random(args: &[ColumnarValue]) -> Result<ColumnarValue> {
     Ok(ColumnarValue::Array(Arc::new(array)))
 }
 
+macro_rules! round_downcast_decimal_places {
+    ($dp:expr) => {
+        $dp.try_into().map_err(|_| {
+            DataFusionError::Execution(
+                "round function requires decimal_places as 32 bit integers".to_string(),
+            )
+        })
+    };
+}
+

Review Comment:
   The input/output types are always i64/i32. This isn't necessary to be a macro, I guess.



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] tz70s commented on a diff in pull request #6232: Safeguard round function decimal places overflow

Posted by "tz70s (via GitHub)" <gi...@apache.org>.
tz70s commented on code in PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#discussion_r1185242876


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -226,21 +227,23 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
                     }
                 )) as ArrayRef)
             }
-            ColumnarValue::Array(decimal_places) => Ok(Arc::new(make_function_inputs2!(

Review Comment:
   I basically give up using the existing macro (`make_function_inputs2`), not sure is it worth changing it to be possibly return `Result` within the `$FUNC`.



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] tz70s commented on a diff in pull request #6232: Safeguard round function decimal places overflow

Posted by "tz70s (via GitHub)" <gi...@apache.org>.
tz70s commented on code in PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#discussion_r1185242876


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -226,21 +227,23 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
                     }
                 )) as ArrayRef)
             }
-            ColumnarValue::Array(decimal_places) => Ok(Arc::new(make_function_inputs2!(

Review Comment:
   I basically gave up using the existing macro (`make_function_inputs2`), not sure is it worth changing it to be possibly return `Result` within the `$FUNC`.



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] tz70s commented on pull request #6232: Safeguard round function decimal places overflow

Posted by "tz70s (via GitHub)" <gi...@apache.org>.
tz70s commented on PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#issuecomment-1535150346

   > Maybe we can simply change the `Round` to accept i32 here: https://github.com/apache/arrow-datafusion/blob/main/datafusion/expr/src/function.rs#L651-L654
   
   Postgres output:
   
   ```
   postgres=# select round(5.4323, 2147483648);
   ERROR:  function round(numeric, bigint) does not exist
   LINE 1: select round(5.4323, 2147483648);
                  ^
   HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
   ```


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #6232: Safeguard round function decimal places overflow

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#issuecomment-1640984589

   I am not sure what is going on with this PR -- it now looks like a huge change and it has been stale for quite a while. Marking it as draft while we figure out what to do with it


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #6232: Safeguard round function decimal places overflow

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#discussion_r1227070238


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -287,6 +288,16 @@ pub fn random(args: &[ColumnarValue]) -> Result<ColumnarValue> {
     Ok(ColumnarValue::Array(Arc::new(array)))
 }
 
+macro_rules! round_downcast_decimal_places {
+    ($dp:expr) => {
+        $dp.try_into().map_err(|_| {
+            DataFusionError::Execution(
+                "round function requires decimal_places as 32 bit integers".to_string(),
+            )
+        })
+    };
+}
+

Review Comment:
   You can have a inline function instead.



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] tz70s commented on pull request #6232: Safeguard round function decimal places overflow

Posted by "tz70s (via GitHub)" <gi...@apache.org>.
tz70s commented on PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#issuecomment-1535148429

   Maybe we can simply change the `Round` to accept i32 here: https://github.com/apache/arrow-datafusion/blob/main/datafusion/expr/src/function.rs#L651-L654


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #6232: Safeguard round function decimal places overflow

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#issuecomment-1619050226

   I wonder if https://github.com/apache/arrow-datafusion/pull/6833 is similar functionality


-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] viirya commented on a diff in pull request #6232: Safeguard round function decimal places overflow

Posted by "viirya (via GitHub)" <gi...@apache.org>.
viirya commented on code in PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#discussion_r1227066382


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -290,6 +295,14 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+fn round_downcast_decimal_places(decimal_place: i64) -> Result<i32> {

Review Comment:
   You could inline a function too. Not necessary to be macros actually as macros are more difficult to read.



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] tz70s commented on a diff in pull request #6232: Safeguard round function decimal places overflow

Posted by "tz70s (via GitHub)" <gi...@apache.org>.
tz70s commented on code in PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#discussion_r1227083240


##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -290,6 +295,14 @@ pub fn round(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+fn round_downcast_decimal_places(decimal_place: i64) -> Result<i32> {

Review Comment:
   Thanks, revert it back with inline attribute instead.



-- 
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: github-unsubscribe@arrow.apache.org

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


[GitHub] [arrow-datafusion] alamb commented on pull request #6232: Safeguard round function decimal places overflow

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on PR #6232:
URL: https://github.com/apache/arrow-datafusion/pull/6232#issuecomment-1593142902

   @viirya (or @liukun4515 ) do you have time to review / approve this PR? I haven't been following closely and I think you are the experts in Decimal implementation in DataFusion


-- 
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: github-unsubscribe@arrow.apache.org

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