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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]