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

[GitHub] [arrow-datafusion] izveigor opened a new pull request, #6312: feat: negation of `Intervals`

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

   # 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 #6311
   
   # 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?
   
   <!--
   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?
   Yes
   <!--
   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)?
   -->
   
   # Are there any user-facing changes?
   Yes
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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 merged pull request #6312: feat: negation of `Intervals`

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #6312:
URL: https://github.com/apache/arrow-datafusion/pull/6312


-- 
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 a diff in pull request #6312: feat: negation of `Intervals`

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


##########
datafusion/core/tests/sqllogictests/test_files/interval.slt:
##########
@@ -186,6 +186,30 @@ select interval '1 year' - '1 month' - '1 day' - '1 hour' - '1 minute' - '1 seco
 ----
 0 years 11 mons -1 days -1 hours -1 mins -1.001001001 secs
 
+# Interval with string literal negation and leading field
+query ?
+select -interval '5' - '1' - '2' year;
+----
+0 years -24 mons 0 days 0 hours 0 mins 0.000000000 secs

Review Comment:
   I think it is related to the fact that interval gets parsed to the same IntervalMonthDayNano all the time -- which was changed in https://github.com/apache/arrow-datafusion/pull/5806
   
   I think to handle it properly we need to have cast support between the different interval types, maybe 🤔 



-- 
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 #6312: feat: negation of `Intervals`

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

   Looks like @comphead has filed https://github.com/apache/arrow-datafusion/issues/6327 👍 


-- 
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] comphead commented on a diff in pull request #6312: feat: negation of `Intervals`

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


##########
datafusion/core/tests/sqllogictests/test_files/interval.slt:
##########
@@ -186,6 +186,30 @@ select interval '1 year' - '1 month' - '1 day' - '1 hour' - '1 minute' - '1 seco
 ----
 0 years 11 mons -1 days -1 hours -1 mins -1.001001001 secs
 
+# Interval with string literal negation and leading field
+query ?
+select -interval '5' - '1' - '2' year;
+----
+0 years -24 mons 0 days 0 hours 0 mins 0.000000000 secs

Review Comment:
   > I don't clearly know why years always translate to months (See: [Example](https://github.com/apache/arrow-datafusion/blob/main/datafusion/core/tests/sqllogictests/test_files/interval.slt#L51-L55)) (maybe because the output function use `IntervalYearMonth::to_months()`. But, I think it is not the actual problem of this PR.
   
   right, I'll investigate if we need a follow up on this



-- 
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] comphead commented on a diff in pull request #6312: feat: negation of `Intervals`

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


##########
datafusion/core/tests/sqllogictests/test_files/interval.slt:
##########
@@ -186,6 +186,30 @@ select interval '1 year' - '1 month' - '1 day' - '1 hour' - '1 minute' - '1 seco
 ----
 0 years 11 mons -1 days -1 hours -1 mins -1.001001001 secs
 
+# Interval with string literal negation and leading field
+query ?
+select -interval '5' - '1' - '2' year;
+----
+0 years -24 mons 0 days 0 hours 0 mins 0.000000000 secs

Review Comment:
   why it is -24 mons, not -2 years? 🤔 



-- 
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] comphead commented on a diff in pull request #6312: feat: negation of `Intervals`

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


##########
datafusion/core/tests/sqllogictests/test_files/interval.slt:
##########
@@ -186,6 +186,30 @@ select interval '1 year' - '1 month' - '1 day' - '1 hour' - '1 minute' - '1 seco
 ----
 0 years 11 mons -1 days -1 hours -1 mins -1.001001001 secs
 
+# Interval with string literal negation and leading field
+query ?
+select -interval '5' - '1' - '2' year;
+----
+0 years -24 mons 0 days 0 hours 0 mins 0.000000000 secs

Review Comment:
   ```
   select extract( year from interval '5' year);
   ```
   This works in PG and returns 5 years 
   
   But fails in DF, I'll create another ticket on this. 



-- 
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] izveigor commented on a diff in pull request #6312: feat: negation of `Intervals`

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


##########
datafusion/core/tests/sqllogictests/test_files/interval.slt:
##########
@@ -186,6 +186,30 @@ select interval '1 year' - '1 month' - '1 day' - '1 hour' - '1 minute' - '1 seco
 ----
 0 years 11 mons -1 days -1 hours -1 mins -1.001001001 secs
 
+# Interval with string literal negation and leading field
+query ?
+select -interval '5' - '1' - '2' year;
+----
+0 years -24 mons 0 days 0 hours 0 mins 0.000000000 secs

Review Comment:
   I don't clearly know why years always translate to months (See: [Example](https://github.com/apache/arrow-datafusion/blob/main/datafusion/core/tests/sqllogictests/test_files/interval.slt#L51-L55)) (maybe because the output function use `IntervalYearMonth::to_months()`. But, I think it is not the actual problem of this PR.



-- 
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 a diff in pull request #6312: feat: negation of `Intervals`

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


##########
datafusion/physical-expr/src/expressions/negative.rs:
##########
@@ -145,11 +151,88 @@ pub fn negative(
     let data_type = arg.data_type(input_schema)?;
     if is_null(&data_type) {
         Ok(arg)
-    } else if !is_signed_numeric(&data_type) {
+    } else if !is_signed_numeric(&data_type) && !is_interval(&data_type) {
         Err(DataFusionError::Internal(
             format!("Can't create negative physical expr for (- '{arg:?}'), the type of child expr is {data_type}, not signed numeric"),
         ))
     } else {
         Ok(Arc::new(NegativeExpr::new(arg)))
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use crate::expressions::col;
+    #[allow(unused_imports)]
+    use arrow::array::*;
+    use arrow::datatypes::*;
+    use arrow_schema::DataType::{Float32, Float64, Int16, Int32, Int64, Int8};
+    use arrow_schema::IntervalUnit::{DayTime, MonthDayNano, YearMonth};
+    use datafusion_common::{cast::as_primitive_array, Result};
+    use paste::paste;
+
+    macro_rules! test_array_negative_op {

Review Comment:
   thank you for adding this coverage of regular negate



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