You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/11/12 10:44:36 UTC

[GitHub] [arrow-datafusion] Jefffrey opened a new pull request, #4186: Parse nanoseconds for intervals

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

   # 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 #3204.
   
   # 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.  
   -->
   
   Change parsing granularity of intervals from milliseconds to nanoseconds, to support passing fractions of milliseconds/seconds (down to nanoseconds) as `IntervalMonthDayNano` supports granularity down to nanoseconds.
   
   # 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.
   -->
   
   Accumulating with nanoseconds instead of milliseconds, changing to f64/i128 where necessary to account for shift in range of values.
   
   # 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)?
   -->
   
   Added some unit tests, and fixed others as there is now more precision for seconds fractions.
   
   # Are there any user-facing changes?
   
   <!--
   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 commented on pull request #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
alamb commented on PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#issuecomment-1315167009

   Thanks @Jefffrey  for the fix and @waitingkuo and @waynexia for the reviews!


-- 
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] waitingkuo commented on a diff in pull request #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on code in PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#discussion_r1021236228


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -917,19 +917,19 @@ async fn test_interval_expressions() -> Result<()> {
     );
     test_expression!(
         "interval '0.499 day'",
-        "0 years 0 mons 0 days 11 hours 58 mins 33.596 secs"
+        "0 years 0 mons 0 days 11 hours 58 mins 33.600 secs"
     );
     test_expression!(
         "interval '0.4999 day'",
-        "0 years 0 mons 0 days 11 hours 59 mins 51.364 secs"
+        "0 years 0 mons 0 days 11 hours 59 mins 51.360 secs"
     );
     test_expression!(
         "interval '0.49999 day'",
         "0 years 0 mons 0 days 11 hours 59 mins 59.136 secs"
     );
     test_expression!(
         "interval '0.49999999999 day'",
-        "0 years 0 mons 0 days 12 hours 0 mins 0.00 secs"
+        "0 years 0 mons 0 days 11 hours 59 mins 59.999999136 secs"
     );
     test_expression!(

Review Comment:
   i think we can add a test case for this (which will fail in the current version) and wait for the update to arrow 27 #4199
   ```suggestion
       test_expression!(
           "interval '0.00000000001 day'",
           "0 years 0 mons 0 days 0 hours 0 mins 0.000000864 secs"
       );
       test_expression!(
   ```



-- 
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] waitingkuo commented on a diff in pull request #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on code in PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#discussion_r1021283989


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -917,19 +917,19 @@ async fn test_interval_expressions() -> Result<()> {
     );
     test_expression!(
         "interval '0.499 day'",
-        "0 years 0 mons 0 days 11 hours 58 mins 33.596 secs"
+        "0 years 0 mons 0 days 11 hours 58 mins 33.600 secs"
     );
     test_expression!(
         "interval '0.4999 day'",
-        "0 years 0 mons 0 days 11 hours 59 mins 51.364 secs"
+        "0 years 0 mons 0 days 11 hours 59 mins 51.360 secs"
     );
     test_expression!(
         "interval '0.49999 day'",
         "0 years 0 mons 0 days 11 hours 59 mins 59.136 secs"
     );
     test_expression!(
         "interval '0.49999999999 day'",
-        "0 years 0 mons 0 days 12 hours 0 mins 0.00 secs"
+        "0 years 0 mons 0 days 11 hours 59 mins 59.999999136 secs"
     );
     test_expression!(

Review Comment:
   i just found that the arrow-rs fix isn't included in 27.0.0
   @tustvold do you have any suggestion for this? should we just merge this first and add some test cases after arrow 28.0.0 merged?



-- 
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] waynexia commented on a diff in pull request #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
waynexia commented on code in PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#discussion_r1020839570


##########
datafusion/common/src/parsers.rs:
##########
@@ -19,8 +19,8 @@
 use crate::{DataFusionError, Result, ScalarValue};
 use std::str::FromStr;
 
-const SECONDS_PER_HOUR: f32 = 3_600_f32;
-const MILLIS_PER_SECOND: f32 = 1_000_f32;
+const SECONDS_PER_HOUR: f64 = 3_600_f64;
+const NANOS_PER_SECOND: f64 = 1_000_000_000f64;

Review Comment:
   ```suggestion
   const NANOS_PER_SECOND: f64 = 1_000_000_000_f64;
   ```
   
   nitpicking, to be consistent with another literal 😋



##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -917,19 +917,19 @@ async fn test_interval_expressions() -> Result<()> {
     );
     test_expression!(
         "interval '0.499 day'",
-        "0 years 0 mons 0 days 11 hours 58 mins 33.596 secs"
+        "0 years 0 mons 0 days 11 hours 58 mins 33.600 secs"
     );
     test_expression!(
         "interval '0.4999 day'",
-        "0 years 0 mons 0 days 11 hours 59 mins 51.364 secs"
+        "0 years 0 mons 0 days 11 hours 59 mins 51.360 secs"
     );
     test_expression!(
         "interval '0.49999 day'",
         "0 years 0 mons 0 days 11 hours 59 mins 59.136 secs"
     );
     test_expression!(
         "interval '0.49999999999 day'",
-        "0 years 0 mons 0 days 12 hours 0 mins 0.00 secs"
+        "0 years 0 mons 0 days 11 hours 59 mins 59.999999136 secs"

Review Comment:
   Great improvement! 👍 



-- 
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] waitingkuo commented on a diff in pull request #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on code in PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#discussion_r1021209708


##########
datafusion/common/src/parsers.rs:
##########
@@ -29,73 +29,74 @@ pub fn parse_interval(leading_field: &str, value: &str) -> Result<ScalarValue> {
     // INTERVAL '0.5 MONTH' = 15 days, INTERVAL '1.5 MONTH' = 1 month 15 days
     // INTERVAL '0.5 DAY' = 12 hours, INTERVAL '1.5 DAY' = 1 day 12 hours
     let align_interval_parts =
-        |month_part: f32, mut day_part: f32, mut milles_part: f32| -> (i32, i32, f32) {
+        |month_part: f64, mut day_part: f64, mut nanos_part: f64| -> (i64, i64, f64) {
             // Convert fractional month to days, It's not supported by Arrow types, but anyway
-            day_part += (month_part - (month_part as i32) as f32) * 30_f32;
+            day_part += (month_part - (month_part as i64) as f64) * 30_f64;
 
             // Convert fractional days to hours
-            milles_part += (day_part - ((day_part as i32) as f32))
-                * 24_f32
+            nanos_part += (day_part - ((day_part as i64) as f64))
+                * 24_f64
                 * SECONDS_PER_HOUR
-                * MILLIS_PER_SECOND;
+                * NANOS_PER_SECOND;
 
-            (month_part as i32, day_part as i32, milles_part)
+            (month_part as i64, day_part as i64, nanos_part)

Review Comment:
   👍 



-- 
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] ursabot commented on pull request #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
ursabot commented on PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#issuecomment-1315170681

   Benchmark runs are scheduled for baseline = d91ce0684646f07edc8f182214f15845a9efab97 and contender = 8bfc0ea2e2b5040d0386b1d11c6817b0a8d20661. 8bfc0ea2e2b5040d0386b1d11c6817b0a8d20661 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/3ba75d1fe89940d888b1580fe3d6f382...f6336a70d2284ab4952b73cd16885388/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/aeb867307f854d3cb1b143193f290cb4...512611f90d6a48749c24cab68ed236a1/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/feb2a39c8e1745d4ba1214c6dd27bd2b...e36e1ef16a9a4191bee0a1cb09a1cf1d/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/2a36d3aee31941fba8841196e1ad1736...2d4b0fa08b71405fa354f0d0cdf8a036/)
   Buildkite builds:
   Supported benchmarks:
   ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
   test-mac-arm: Supported benchmark langs: C++, Python, R
   ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
   ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java
   


-- 
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] waitingkuo commented on pull request #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
waitingkuo commented on PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#issuecomment-1313302656

   while we have leading zeros after decimal, it displays incorrectly
   ```bash
   ❯ select interval '0.01 second';
   +------------------------------------------------+
   | IntervalDayTime("10")                          |
   +------------------------------------------------+
   | 0 years 0 mons 0 days 0 hours 0 mins 0.10 secs |
   +------------------------------------------------+
   1 row in set. Query took 0.000 seconds.
   
   ❯ select interval '0.001 second';
   +------------------------------------------------+
   | IntervalDayTime("1")                           |
   +------------------------------------------------+
   | 0 years 0 mons 0 days 0 hours 0 mins 0.01 secs |
   +------------------------------------------------+
   1 row in set. Query took 0.000 seconds.
   ```


-- 
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 #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
alamb merged PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186


-- 
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] Jefffrey commented on pull request #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
Jefffrey commented on PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#issuecomment-1313302175

   > thank you @Jefffrey
   > 
   > there's a bug while displaying IntervalMonthDayNano
   > 
   > ```shell
   > ❯ select interval '0.0001 second';
   > +----------------------------------------------------+
   > | IntervalMonthDayNano("100000")                     |
   > +----------------------------------------------------+
   > | 0 years 0 mons 0 days 0 hours 0 mins 0.100000 secs |
   > +----------------------------------------------------+
   > 1 row in set. Query took 0.002 seconds.
   > ```
   > 
   > i checked the underline value it's correct `(month: 0, day: 0, nanos: 100000)` i think this is the display issue
   
   Issue with arrow-rs, has already been addressed: https://github.com/apache/arrow-rs/pull/3093


-- 
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 #4186: Parse nanoseconds for intervals

Posted by GitBox <gi...@apache.org>.
alamb commented on code in PR #4186:
URL: https://github.com/apache/arrow-datafusion/pull/4186#discussion_r1022661156


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -917,19 +917,19 @@ async fn test_interval_expressions() -> Result<()> {
     );
     test_expression!(
         "interval '0.499 day'",
-        "0 years 0 mons 0 days 11 hours 58 mins 33.596 secs"
+        "0 years 0 mons 0 days 11 hours 58 mins 33.600 secs"
     );
     test_expression!(
         "interval '0.4999 day'",
-        "0 years 0 mons 0 days 11 hours 59 mins 51.364 secs"
+        "0 years 0 mons 0 days 11 hours 59 mins 51.360 secs"
     );
     test_expression!(
         "interval '0.49999 day'",
         "0 years 0 mons 0 days 11 hours 59 mins 59.136 secs"
     );
     test_expression!(
         "interval '0.49999999999 day'",
-        "0 years 0 mons 0 days 12 hours 0 mins 0.00 secs"
+        "0 years 0 mons 0 days 11 hours 59 mins 59.999999136 secs"
     );
     test_expression!(

Review Comment:
   We can also add test cases that are marked as `#[should_fail]` 



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