You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "jayzhan211 (via GitHub)" <gi...@apache.org> on 2024/11/18 08:56:26 UTC
[PR] Return int for integer type date part [datafusion]
jayzhan211 opened a new pull request, #13466:
URL: https://github.com/apache/datafusion/pull/13466
## 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 #.
## Rationale for this change
Date part such as year, month, day are integer type, we can return i32 instead of casting it to f64
<!--
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?
<!--
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.
-->
<!--
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@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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1846514032
##########
datafusion/sqllogictest/test_files/expr.slt:
##########
@@ -1487,32 +1487,32 @@ SELECT extract(epoch from arrow_cast('1969-12-31', 'Date64'))
# test_extract_interval
-query R
+query I
SELECT extract(year from arrow_cast('10 years', 'Interval(YearMonth)'))
----
10
-query R
+query I
Review Comment:
Since `I` is for integer and we don't need to make sure it is exactly i32 or i64 so I think that is fine. If we want to differentiate type like utf8 or utf8View then we need `arrow_typeof`
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#issuecomment-2492645774
Thanks @comphead @findepi @Dandandan
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#issuecomment-2483260073
```
--------------------
Benchmark clickbench_1.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query ┃ main ┃ date-part-int ┃ Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0 │ 0.40ms │ 0.53ms │ 1.33x slower │
│ QQuery 1 │ 45.15ms │ 47.96ms │ 1.06x slower │
│ QQuery 2 │ 81.29ms │ 79.44ms │ no change │
│ QQuery 3 │ 68.24ms │ 62.99ms │ +1.08x faster │
│ QQuery 4 │ 404.77ms │ 408.36ms │ no change │
│ QQuery 5 │ 730.24ms │ 722.14ms │ no change │
│ QQuery 6 │ 38.72ms │ 39.52ms │ no change │
│ QQuery 7 │ 44.31ms │ 43.05ms │ no change │
│ QQuery 8 │ 476.74ms │ 467.79ms │ no change │
│ QQuery 9 │ 672.87ms │ 669.63ms │ no change │
│ QQuery 10 │ 175.53ms │ 179.61ms │ no change │
│ QQuery 11 │ 199.23ms │ 199.55ms │ no change │
│ QQuery 12 │ 758.33ms │ 775.82ms │ no change │
│ QQuery 13 │ 895.53ms │ 895.39ms │ no change │
│ QQuery 14 │ 725.44ms │ 724.15ms │ no change │
│ QQuery 15 │ 485.85ms │ 500.24ms │ no change │
│ QQuery 16 │ 1132.63ms │ 1145.34ms │ no change │
│ QQuery 17 │ 1058.71ms │ 1047.24ms │ no change │
│ QQuery 18 │ 3434.22ms │ 2979.31ms │ +1.15x faster │
│ QQuery 19 │ 55.59ms │ 57.97ms │ no change │
│ QQuery 20 │ 850.86ms │ 853.53ms │ no change │
│ QQuery 21 │ 1116.08ms │ 1105.99ms │ no change │
│ QQuery 22 │ 3147.33ms │ 3218.51ms │ no change │
│ QQuery 23 │ 7837.74ms │ 7632.39ms │ no change │
│ QQuery 24 │ 502.62ms │ 483.36ms │ no change │
│ QQuery 25 │ 497.66ms │ 505.86ms │ no change │
│ QQuery 26 │ 559.75ms │ 529.33ms │ +1.06x faster │
│ QQuery 27 │ 1317.98ms │ 1291.91ms │ no change │
│ QQuery 28 │ 9508.45ms │ 9513.32ms │ no change │
│ QQuery 29 │ 432.42ms │ 406.76ms │ +1.06x faster │
│ QQuery 30 │ 668.52ms │ 670.90ms │ no change │
│ QQuery 31 │ 679.62ms │ 696.56ms │ no change │
│ QQuery 32 │ 3171.05ms │ 3326.19ms │ no change │
│ QQuery 33 │ 3197.64ms │ 3022.01ms │ +1.06x faster │
│ QQuery 34 │ 2907.09ms │ 3069.23ms │ 1.06x slower │
│ QQuery 35 │ 714.22ms │ 702.46ms │ no change │
│ QQuery 36 │ 137.17ms │ 132.89ms │ no change │
│ QQuery 37 │ 101.83ms │ 99.71ms │ no change │
│ QQuery 38 │ 101.74ms │ 102.64ms │ no change │
│ QQuery 39 │ 254.02ms │ 251.36ms │ no change │
│ QQuery 40 │ 40.08ms │ 37.21ms │ +1.08x faster │
│ QQuery 41 │ 38.25ms │ 31.57ms │ +1.21x faster │
│ QQuery 42 │ 41.37ms │ 39.40ms │ no change │
└──────────────┴───────────┴───────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary ┃ ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (main) │ 49307.28ms │
│ Total Time (date-part-int) │ 48769.11ms │
│ Average Time (main) │ 1146.68ms │
│ Average Time (date-part-int) │ 1134.17ms │
│ Queries Faster │ 7 │
│ Queries Slower │ 3 │
│ Queries with No Change │ 33 │
└──────────────────────────────┴────────────┘
```
```
--------------------
Benchmark tpch_sf1.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query ┃ main ┃ date-part-int ┃ Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1 │ 106.95ms │ 98.68ms │ +1.08x faster │
│ QQuery 2 │ 27.55ms │ 26.60ms │ no change │
│ QQuery 3 │ 41.45ms │ 40.75ms │ no change │
│ QQuery 4 │ 29.59ms │ 25.12ms │ +1.18x faster │
│ QQuery 5 │ 61.08ms │ 56.22ms │ +1.09x faster │
│ QQuery 6 │ 20.54ms │ 18.17ms │ +1.13x faster │
│ QQuery 7 │ 76.95ms │ 70.63ms │ +1.09x faster │
│ QQuery 8 │ 58.13ms │ 56.18ms │ no change │
│ QQuery 9 │ 70.39ms │ 69.05ms │ no change │
│ QQuery 10 │ 64.87ms │ 62.71ms │ no change │
│ QQuery 11 │ 19.23ms │ 17.79ms │ +1.08x faster │
│ QQuery 12 │ 39.59ms │ 38.58ms │ no change │
│ QQuery 13 │ 33.14ms │ 35.80ms │ 1.08x slower │
│ QQuery 14 │ 31.71ms │ 28.79ms │ +1.10x faster │
│ QQuery 15 │ 48.16ms │ 45.50ms │ +1.06x faster │
│ QQuery 16 │ 19.27ms │ 19.69ms │ no change │
│ QQuery 17 │ 81.12ms │ 78.97ms │ no change │
│ QQuery 18 │ 116.53ms │ 115.46ms │ no change │
│ QQuery 19 │ 51.45ms │ 50.14ms │ no change │
│ QQuery 20 │ 43.01ms │ 41.61ms │ no change │
│ QQuery 21 │ 94.00ms │ 90.85ms │ no change │
│ QQuery 22 │ 21.32ms │ 20.42ms │ no change │
└──────────────┴──────────┴───────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary ┃ ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (main) │ 1156.04ms │
│ Total Time (date-part-int) │ 1107.72ms │
│ Average Time (main) │ 52.55ms │
│ Average Time (date-part-int) │ 50.35ms │
│ Queries Faster │ 8 │
│ Queries Slower │ 1 │
│ Queries with No Change │ 13 │
└──────────────────────────────┴───────────┘
```
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1849711044
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
+ )
+}
+
+// Try to remove quote if exist, if the quote is invalid, return original string and let the downstream function handle the error
+fn part_normalization(part: &str) -> &str {
+ part.strip_prefix(|c| c == '\'' || c == '\"')
+ .and_then(|s| s.strip_suffix(|c| c == '\'' || c == '\"'))
Review Comment:
```
postgres=# SELECT EXTRACT(second FROM timestamp '2020-09-08T12:00:12.123456789+00');
extract
-----------
12.123457
(1 row)
postgres=# SELECT EXTRACT('second' FROM timestamp '2020-09-08T12:00:12.123456789+00');
extract
-----------
12.123457
(1 row)
```
It seems this it to be postgres-compatible
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
+ )
+}
+
+// Try to remove quote if exist, if the quote is invalid, return original string and let the downstream function handle the error
+fn part_normalization(part: &str) -> &str {
+ part.strip_prefix(|c| c == '\'' || c == '\"')
+ .and_then(|s| s.strip_suffix(|c| c == '\'' || c == '\"'))
Review Comment:
```
postgres=# SELECT EXTRACT(second FROM timestamp '2020-09-08T12:00:12.123456789+00');
extract
-----------
12.123457
(1 row)
postgres=# SELECT EXTRACT('second' FROM timestamp '2020-09-08T12:00:12.123456789+00');
extract
-----------
12.123457
(1 row)
```
It seems this it to be postgres-compatible
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1846980887
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
i didn't know `extract(second ..` returns seconds with fraction. In PostgreSQL it does so, in e.g. Trino and Snowflake it does not
```
postgres=# select extract(second from now());
extract
-----------
29.009019
```
```
trino> select extract(second from now());
_col0
-------
46
```
so yes, keep seconds with float for now
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1848116106
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
filed https://github.com/apache/datafusion/issues/13482 for this
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
filed https://github.com/apache/datafusion/issues/13482 for 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@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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "Dandandan (via GitHub)" <gi...@apache.org>.
Dandandan commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1848147064
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
Review Comment:
```suggestion
fn is_integer_part(part: &str) -> bool {
```
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1850732512
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -261,14 +283,63 @@ fn get_date_part_doc() -> &'static Documentation {
})
}
-/// Invoke [`date_part`] and cast the result to Float64
-fn date_part_f64(array: &dyn Array, part: DatePart) -> Result<ArrayRef> {
- Ok(cast(date_part(array, part)?.as_ref(), &Float64)?)
+/// Invoke [`date_part`] on an `array` (e.g. Timestamp) and convert the
+/// result to a total number of seconds, milliseconds, microseconds or
+/// nanoseconds
+fn seconds_as_i32(array: &dyn Array, unit: TimeUnit) -> Result<ArrayRef> {
+ // Nanosecond is neither supported in Postgres nor DuckDB, to avoid to deal with overflow and precision issue we don't support nanosecond
+ if unit == Nanosecond {
+ return internal_err!("unit {unit:?} not supported");
+ }
+
+ let conversion_factor = match unit {
Review Comment:
we should probably factor out the common part for this conversion in future. its too many hardcoded conversions between second fraction and corresponding long value.
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1850732512
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -261,14 +283,63 @@ fn get_date_part_doc() -> &'static Documentation {
})
}
-/// Invoke [`date_part`] and cast the result to Float64
-fn date_part_f64(array: &dyn Array, part: DatePart) -> Result<ArrayRef> {
- Ok(cast(date_part(array, part)?.as_ref(), &Float64)?)
+/// Invoke [`date_part`] on an `array` (e.g. Timestamp) and convert the
+/// result to a total number of seconds, milliseconds, microseconds or
+/// nanoseconds
+fn seconds_as_i32(array: &dyn Array, unit: TimeUnit) -> Result<ArrayRef> {
+ // Nanosecond is neither supported in Postgres nor DuckDB, to avoid to deal with overflow and precision issue we don't support nanosecond
+ if unit == Nanosecond {
+ return internal_err!("unit {unit:?} not supported");
+ }
+
+ let conversion_factor = match unit {
Review Comment:
we should probably get common part for this conversion in future
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1846439004
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
second, millisecond, micro, nanos too?
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
+ )
+}
+
+// Try to remove quote if exist, if the quote is invalid, return original string and let the downstream function handle the error
+fn part_normalization(part: &str) -> &str {
+ part.strip_prefix(|c| c == '\'' || c == '\"')
+ .and_then(|s| s.strip_suffix(|c| c == '\'' || c == '\"'))
Review Comment:
why would we want to support unmatched quotes like `'..."`?
the date_part argument shouldn't contain any quotes, why would we want to support quotes at all?
i see this is pre-existing, so okay to keep, but still wonder why we're doing this, doesn't feel right
##########
datafusion/sqllogictest/test_files/expr.slt:
##########
@@ -1487,32 +1487,32 @@ SELECT extract(epoch from arrow_cast('1969-12-31', 'Date64'))
# test_extract_interval
-query R
+query I
SELECT extract(year from arrow_cast('10 years', 'Interval(YearMonth)'))
----
10
-query R
+query I
Review Comment:
Should we have explicit tests inspecting `arrow_typeof(extract(....))`?
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 merged PR #13466:
URL: https://github.com/apache/datafusion/pull/13466
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1847127624
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
extract for seconds is float correct, returning the fractions. however its not the case for DuckDB.
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1847127624
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
extract is float correct, returning the fractions
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#issuecomment-2483258404
```
Comparing main and date-part-int
--------------------
Benchmark clickbench_1.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query ┃ main ┃ date-part-int ┃ Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 0 │ 0.40ms │ 0.53ms │ 1.33x slower │
│ QQuery 1 │ 45.15ms │ 47.96ms │ 1.06x slower │
│ QQuery 2 │ 81.29ms │ 79.44ms │ no change │
│ QQuery 3 │ 68.24ms │ 62.99ms │ +1.08x faster │
│ QQuery 4 │ 404.77ms │ 408.36ms │ no change │
│ QQuery 5 │ 730.24ms │ 722.14ms │ no change │
│ QQuery 6 │ 38.72ms │ 39.52ms │ no change │
│ QQuery 7 │ 44.31ms │ 43.05ms │ no change │
│ QQuery 8 │ 476.74ms │ 467.79ms │ no change │
│ QQuery 9 │ 672.87ms │ 669.63ms │ no change │
│ QQuery 10 │ 175.53ms │ 179.61ms │ no change │
│ QQuery 11 │ 199.23ms │ 199.55ms │ no change │
│ QQuery 12 │ 758.33ms │ 775.82ms │ no change │
│ QQuery 13 │ 895.53ms │ 895.39ms │ no change │
│ QQuery 14 │ 725.44ms │ 724.15ms │ no change │
│ QQuery 15 │ 485.85ms │ 500.24ms │ no change │
│ QQuery 16 │ 1132.63ms │ 1145.34ms │ no change │
│ QQuery 17 │ 1058.71ms │ 1047.24ms │ no change │
│ QQuery 18 │ 3434.22ms │ 2979.31ms │ +1.15x faster │
│ QQuery 19 │ 55.59ms │ 57.97ms │ no change │
│ QQuery 20 │ 850.86ms │ 853.53ms │ no change │
│ QQuery 21 │ 1116.08ms │ 1105.99ms │ no change │
│ QQuery 22 │ 3147.33ms │ 3218.51ms │ no change │
│ QQuery 23 │ 7837.74ms │ 7632.39ms │ no change │
│ QQuery 24 │ 502.62ms │ 483.36ms │ no change │
│ QQuery 25 │ 497.66ms │ 505.86ms │ no change │
│ QQuery 26 │ 559.75ms │ 529.33ms │ +1.06x faster │
│ QQuery 27 │ 1317.98ms │ 1291.91ms │ no change │
│ QQuery 28 │ 9508.45ms │ 9513.32ms │ no change │
│ QQuery 29 │ 432.42ms │ 406.76ms │ +1.06x faster │
│ QQuery 30 │ 668.52ms │ 670.90ms │ no change │
│ QQuery 31 │ 679.62ms │ 696.56ms │ no change │
│ QQuery 32 │ 3171.05ms │ 3326.19ms │ no change │
│ QQuery 33 │ 3197.64ms │ 3022.01ms │ +1.06x faster │
│ QQuery 34 │ 2907.09ms │ 3069.23ms │ 1.06x slower │
│ QQuery 35 │ 714.22ms │ 702.46ms │ no change │
│ QQuery 36 │ 137.17ms │ 132.89ms │ no change │
│ QQuery 37 │ 101.83ms │ 99.71ms │ no change │
│ QQuery 38 │ 101.74ms │ 102.64ms │ no change │
│ QQuery 39 │ 254.02ms │ 251.36ms │ no change │
│ QQuery 40 │ 40.08ms │ 37.21ms │ +1.08x faster │
│ QQuery 41 │ 38.25ms │ 31.57ms │ +1.21x faster │
│ QQuery 42 │ 41.37ms │ 39.40ms │ no change │
└──────────────┴───────────┴───────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━┓
┃ Benchmark Summary ┃ ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━┩
│ Total Time (main) │ 49307.28ms │
│ Total Time (date-part-int) │ 48769.11ms │
│ Average Time (main) │ 1146.68ms │
│ Average Time (date-part-int) │ 1134.17ms │
│ Queries Faster │ 7 │
│ Queries Slower │ 3 │
│ Queries with No Change │ 33 │
└──────────────────────────────┴────────────┘
Note: Skipping /Users/bytedance/arrow-datafusion/benchmarks/results/main/clickbench_partitioned.json as /Users/bytedance/arrow-datafusion/benchmarks/results/date-part-int/clickbench_partitioned.json does not exist
Note: Skipping /Users/bytedance/arrow-datafusion/benchmarks/results/main/imdb.json as /Users/bytedance/arrow-datafusion/benchmarks/results/date-part-int/imdb.json does not exist
Note: Skipping /Users/bytedance/arrow-datafusion/benchmarks/results/main/tpch_mem_sf1.json as /Users/bytedance/arrow-datafusion/benchmarks/results/date-part-int/tpch_mem_sf1.json does not exist
Note: Skipping /Users/bytedance/arrow-datafusion/benchmarks/results/main/tpch_mem_sf10.json as /Users/bytedance/arrow-datafusion/benchmarks/results/date-part-int/tpch_mem_sf10.json does not exist
--------------------
Benchmark tpch_sf1.json
--------------------
┏━━━━━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ Query ┃ main ┃ date-part-int ┃ Change ┃
┡━━━━━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
│ QQuery 1 │ 106.95ms │ 98.68ms │ +1.08x faster │
│ QQuery 2 │ 27.55ms │ 26.60ms │ no change │
│ QQuery 3 │ 41.45ms │ 40.75ms │ no change │
│ QQuery 4 │ 29.59ms │ 25.12ms │ +1.18x faster │
│ QQuery 5 │ 61.08ms │ 56.22ms │ +1.09x faster │
│ QQuery 6 │ 20.54ms │ 18.17ms │ +1.13x faster │
│ QQuery 7 │ 76.95ms │ 70.63ms │ +1.09x faster │
│ QQuery 8 │ 58.13ms │ 56.18ms │ no change │
│ QQuery 9 │ 70.39ms │ 69.05ms │ no change │
│ QQuery 10 │ 64.87ms │ 62.71ms │ no change │
│ QQuery 11 │ 19.23ms │ 17.79ms │ +1.08x faster │
│ QQuery 12 │ 39.59ms │ 38.58ms │ no change │
│ QQuery 13 │ 33.14ms │ 35.80ms │ 1.08x slower │
│ QQuery 14 │ 31.71ms │ 28.79ms │ +1.10x faster │
│ QQuery 15 │ 48.16ms │ 45.50ms │ +1.06x faster │
│ QQuery 16 │ 19.27ms │ 19.69ms │ no change │
│ QQuery 17 │ 81.12ms │ 78.97ms │ no change │
│ QQuery 18 │ 116.53ms │ 115.46ms │ no change │
│ QQuery 19 │ 51.45ms │ 50.14ms │ no change │
│ QQuery 20 │ 43.01ms │ 41.61ms │ no change │
│ QQuery 21 │ 94.00ms │ 90.85ms │ no change │
│ QQuery 22 │ 21.32ms │ 20.42ms │ no change │
└──────────────┴──────────┴───────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ Benchmark Summary ┃ ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ Total Time (main) │ 1156.04ms │
│ Total Time (date-part-int) │ 1107.72ms │
│ Average Time (main) │ 52.55ms │
│ Average Time (date-part-int) │ 50.35ms │
│ Queries Faster │ 8 │
│ Queries Slower │ 1 │
│ Queries with No Change │ 13 │
└──────────────────────────────┴───────────┘
```
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "jayzhan211 (via GitHub)" <gi...@apache.org>.
jayzhan211 commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1846520457
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
```rust
(secs as f64 + ((subsecs % 1_000_000_000) as f64 / 1_000_000_000_f64))
* sf
```
Probably we still need f64 for seconds
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
```rust
let r: Float64Array = secs
.iter()
.zip(subsecs)
.map(|(secs, subsecs)| {
secs.map(|secs| {
let subsecs = subsecs.unwrap_or(0);
(secs as f64 + ((subsecs % 1_000_000_000) as f64 / 1_000_000_000_f64))
* sf
})
})
.collect();
```
Probably we still need f64 for 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@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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1848117064
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -223,6 +233,30 @@ impl ScalarUDFImpl for DatePartFunc {
}
}
+fn is_integar_part(part: &str) -> bool {
+ let part = part_normalization(part);
+ matches!(
+ part.to_lowercase().as_str(),
+ "year"
+ | "month"
+ | "week"
+ | "day"
+ | "hour"
+ | "minute"
+ | "qtr"
+ | "quarter"
+ | "doy"
+ | "dow"
Review Comment:
@jayzhan211 what about millisecond, micro, nano?
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "findepi (via GitHub)" <gi...@apache.org>.
findepi commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1846976118
##########
datafusion/sqllogictest/test_files/expr.slt:
##########
@@ -1487,32 +1487,32 @@ SELECT extract(epoch from arrow_cast('1969-12-31', 'Date64'))
# test_extract_interval
-query R
+query I
SELECT extract(year from arrow_cast('10 years', 'Interval(YearMonth)'))
----
10
-query R
+query I
Review Comment:
> Since `I` is for integer
yes i know
> need to make sure it is exactly i32 or i64
do we? do we not?
i think it may make difference, since it's 2x fewer bytes to keep in memory
up to you
--
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
Re: [PR] Return int32 for integer type date part [datafusion]
Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on code in PR #13466:
URL: https://github.com/apache/datafusion/pull/13466#discussion_r1850732512
##########
datafusion/functions/src/datetime/date_part.rs:
##########
@@ -261,14 +283,63 @@ fn get_date_part_doc() -> &'static Documentation {
})
}
-/// Invoke [`date_part`] and cast the result to Float64
-fn date_part_f64(array: &dyn Array, part: DatePart) -> Result<ArrayRef> {
- Ok(cast(date_part(array, part)?.as_ref(), &Float64)?)
+/// Invoke [`date_part`] on an `array` (e.g. Timestamp) and convert the
+/// result to a total number of seconds, milliseconds, microseconds or
+/// nanoseconds
+fn seconds_as_i32(array: &dyn Array, unit: TimeUnit) -> Result<ArrayRef> {
+ // Nanosecond is neither supported in Postgres nor DuckDB, to avoid to deal with overflow and precision issue we don't support nanosecond
+ if unit == Nanosecond {
+ return internal_err!("unit {unit:?} not supported");
+ }
+
+ let conversion_factor = match unit {
Review Comment:
we should probably factor out the common part for this conversion in future. its too many hardcoded conversions between second fraction and corresponding long value in the project.
--
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