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/27 01:39:04 UTC

[GitHub] [arrow-datafusion] comphead opened a new pull request, #4385: `date_part` support fractions of second

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

   # 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 #3997
   
   # Rationale for this change
   See #3997 
   <!--
    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?
   Extending `date_part` to support millis, micros, nanos
   <!--
   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?
   
   <!--
   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] comphead commented on pull request #4385: `date_part` support fractions of second

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

   @waitingkuo finally we can get back to #3997 resolution.
   Please check the PR.
   
   Now date_part supports second fraction, but its still not the same as in PSQL like 
   ```
   willy=# select date_part('second', timestamp '2000-01-01T00:00:00.1');
    date_part 
   -----------
          0.1
   (1 row)
   ```
   
   To do the same you need to run
   ```
   select date_part('milliseconds', timestamp)
   ```
   
   Let me know if this is ok


-- 
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 #4385: `date_part` support fractions of second

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -1285,12 +1285,36 @@ async fn test_extract_date_part() -> Result<()> {
         "12"
     );
     test_expression!(
-        "EXTRACT(second FROM to_timestamp('2020-09-08T12:00:12+00:00'))",
-        "12"
+        "EXTRACT(second FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12.12345678"
     );
     test_expression!(
-        "date_part('second', to_timestamp('2020-09-08T12:00:12+00:00'))",
-        "12"
+        "EXTRACT(millisecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12123.45678"
+    );
+    test_expression!(
+        "EXTRACT(microsecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12123456.78"
+    );
+    // test_expression!(
+    //     "EXTRACT(nanosecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+    //     "1212345678"
+    // );

Review Comment:
   i suggest that uncomment this test case and expect the error
   e.g. like this https://github.com/apache/arrow-datafusion/blob/740a4fa2c6ba4b85875a433bb86e5b00435a5969/datafusion/core/tests/sql/timestamp.rs#L1071-L1074
   



-- 
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 #4385: `date_part` support fractions of second

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

   hi @comphead  thank you
   
   i tested the pr
   ```bash
   ❯ select date_part('second', timestamp '2000-01-01T00:00:09.123456');
   +-------------------------------------------------------------+
   | datepart(Utf8("second"),Utf8("2000-01-01T00:00:09.123456")) |
   +-------------------------------------------------------------+
   | 9                                                           |
   +-------------------------------------------------------------+
   1 row in set. Query took 0.002 seconds.
   ❯ select date_part('millisecond', timestamp '2000-01-01T00:00:09.123456');
   +------------------------------------------------------------------+
   | datepart(Utf8("millisecond"),Utf8("2000-01-01T00:00:09.123456")) |
   +------------------------------------------------------------------+
   | 123                                                              |
   +------------------------------------------------------------------+
   1 row in set. Query took 0.002 seconds.
   ❯ select date_part('microsecond', timestamp '2000-01-01T00:00:09.123456');
   +------------------------------------------------------------------+
   | datepart(Utf8("microsecond"),Utf8("2000-01-01T00:00:09.123456")) |
   +------------------------------------------------------------------+
   | 123456                                                           |
   +------------------------------------------------------------------+
   1 row in set. Query took 0.002 seconds.
   ```
   
   the behavior is different than what postgresql has
   ```bash
   willy=# select date_part('second', timestamp '2000-01-01T00:00:09.123456');
    date_part 
   -----------
     9.123456
   (1 row)
   
   willy=# select date_part('millisecond', timestamp '2000-01-01T00:00:09.123456');
    date_part 
   -----------
     9123.456
   (1 row)
   
   willy=# select date_part('microsecond', timestamp '2000-01-01T00:00:09.123456');
    date_part 
   -----------
      9123456
   (1 row)
   ```
   
   i checked some other system,
   spark seems to have the same behavior as postgresql
   ```bash
   # this is spark
   SELECT date_part('SECONDS', timestamp'2019-10-01 00:00:01.000001');
   +----------------------------------------------------------+
   |date_part(SECONDS, TIMESTAMP '2019-10-01 00:00:01.000001')|
   +----------------------------------------------------------+
   |                                                  1.000001|
   +----------------------------------------------------------+
   ```
   
   while mysql's is similar as this pr
   ```bash
   # this is MYSQL
   EXTRACT(SECOND FROM "2017-06-20 00:00:01.123456");
   1
   ```
   
   I originally purposed to output f64 instead of i32 since i'd like to follow postgresql's
   
   @alamb  @tustvold  do you have any suggestion?
   
   
   
   


-- 
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 #4385: `date_part` support fractions of second

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

   Benchmark runs are scheduled for baseline = 19cddf5d5a5a66e150f36248fb5138bfae4fed66 and contender = cedb05aedf3cea030bfa8774b8575d8f4806a1c8. cedb05aedf3cea030bfa8774b8575d8f4806a1c8 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/3941575bebb64e5ba2e683adaf0c0800...b2422ea113564ff0a9dbfa3dc7e8274a/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/d7c50e90af554170896be2421a0a0185...24627632749940eab3686dbeb3bee300/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/c7b6141fae7b455dafb4f2fcdb91ca6d...5ea676d3a90040fbb7863e801213dec9/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/2091daa4b62b4be79cb2069b0c511107...ca19fe20480841c88983193c30ecdd45/)
   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] alamb commented on pull request #4385: `date_part` support fractions of second

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

   I think we should follow postgres (output floating point) if possible


-- 
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 pull request #4385: `date_part` support fractions of second

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

   Thanks @waitingkuo for testing the PR. I think since we now having seconds fraction support so we can concat the value and be in sync with postgres date_part if this is a preferred way


-- 
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 #4385: `date_part` support fractions of second

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

   Thanks @comphead  and @waitingkuo !


-- 
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 pull request #4385: `date_part` support fractions of second

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

   @waitingkuo made in sync with postgres.
   I have found extract nanosecond faces parser issue
   ```
   DataFusion CLI v14.0.0
   ❯ select EXTRACT(nanosecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'));  🤔 Invalid statement: sql parser error: Expected date/time field, found: nanosecond
   ``` 
   
   whereas nanosecond date_part works. I will create a ticket for 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 pull request #4385: `date_part` support fractions of second

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

   > @comphead i created a ticket and submitted a pr in sqlparser [sqlparser-rs/sqlparser-rs#748](https://github.com/sqlparser-rs/sqlparser-rs/issues/748)
   > 
   > it would be great if you could creat another ticket in datafusion so that we could fix it once the issue in sqlparser merged and new version released
   
   https://github.com/apache/arrow-datafusion/issues/4528
   Please assign this to me.


-- 
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 #4385: `date_part` support fractions of second

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -1285,12 +1285,36 @@ async fn test_extract_date_part() -> Result<()> {
         "12"
     );
     test_expression!(
-        "EXTRACT(second FROM to_timestamp('2020-09-08T12:00:12+00:00'))",
-        "12"
+        "EXTRACT(second FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12.12345678"
     );
     test_expression!(
-        "date_part('second', to_timestamp('2020-09-08T12:00:12+00:00'))",
-        "12"
+        "EXTRACT(millisecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12123.45678"
+    );
+    test_expression!(
+        "EXTRACT(microsecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12123456.78"
+    );
+    // test_expression!(
+    //     "EXTRACT(nanosecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+    //     "1212345678"
+    // );

Review Comment:
   i think we could uncomment this test case and expect the error
   e.g. https://github.com/apache/arrow-datafusion/blob/740a4fa2c6ba4b85875a433bb86e5b00435a5969/datafusion/core/tests/sql/timestamp.rs#L1071-L1074
   



-- 
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 #4385: `date_part` support fractions of second

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


-- 
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 #4385: `date_part` support fractions of second

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


##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -1285,12 +1285,36 @@ async fn test_extract_date_part() -> Result<()> {
         "12"
     );
     test_expression!(
-        "EXTRACT(second FROM to_timestamp('2020-09-08T12:00:12+00:00'))",
-        "12"
+        "EXTRACT(second FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12.12345678"
     );
     test_expression!(
-        "date_part('second', to_timestamp('2020-09-08T12:00:12+00:00'))",
-        "12"
+        "EXTRACT(millisecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12123.45678"
+    );
+    test_expression!(
+        "EXTRACT(microsecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+        "12123456.78"
+    );
+    // test_expression!(
+    //     "EXTRACT(nanosecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'))",
+    //     "1212345678"
+    // );

Review Comment:
   i suggest that uncomment this test case and expect the error
   e.g. https://github.com/apache/arrow-datafusion/blob/740a4fa2c6ba4b85875a433bb86e5b00435a5969/datafusion/core/tests/sql/timestamp.rs#L1071-L1074
   



-- 
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 #4385: `date_part` support fractions of second

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

   > @waitingkuo made in sync with postgres. I have found extract nanosecond faces parser issue
   > 
   > ```
   > DataFusion CLI v14.0.0
   > ❯ select EXTRACT(nanosecond FROM to_timestamp('2020-09-08T12:00:12.12345678+00:00'));  🤔 Invalid statement: sql parser error: Expected date/time field, found: nanosecond
   > ```
   > 
   > whereas nanosecond date_part works. I will create a ticket for this
   
   @comphead sqlparser doesn't support nanosecond for now.
   https://github.com/sqlparser-rs/sqlparser-rs/blob/813f4a2eff8f091b643058ac1a46a4fbffd96806/src/parser.rs#L1187-L1221


-- 
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 #4385: `date_part` support fractions of second

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

   @comphead i created a ticket and submitted a pr in sqlparser sqlparser-rs/sqlparser-rs#748
   
   it would be great if you could creat another ticket in datafusion so that we could fix it once the issue in sqlparser merged and new version released


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