This is an automated email from the ASF dual-hosted git repository.
xiangfu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new ea31137 Refactor toDateTime with time zone (#7558)
ea31137 is described below
commit ea3113773664f7533b672c18a0ff9c74e7143856
Author: Fritz Budiyanto <[email protected]>
AuthorDate: Wed Oct 13 11:00:39 2021 -0700
Refactor toDateTime with time zone (#7558)
* Refactor toDateTime with time zone
Hide parsing and formatter logic inside DateTimePatternHandler
* Refactor toDateTime with time zone
Hide parsing and formatter logic inside DateTimePatternHandler
* Use Joda DateTimeZone.getID() to get the time zone id
DateTimeZone.getID() is the prefered way of getting time zone id instead
of using DateTimeZone.toString()
---
.../pinot/common/function/DateTimePatternHandler.java | 18 +++++++++++++++---
.../common/function/scalar/DateTimeFunctions.java | 8 ++------
2 files changed, 17 insertions(+), 9 deletions(-)
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/function/DateTimePatternHandler.java
b/pinot-common/src/main/java/org/apache/pinot/common/function/DateTimePatternHandler.java
index 078c0ca..c88c3d8 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/function/DateTimePatternHandler.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/function/DateTimePatternHandler.java
@@ -18,6 +18,7 @@
*/
package org.apache.pinot.common.function;
+import org.joda.time.DateTimeZone;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
@@ -45,10 +46,21 @@ public class DateTimePatternHandler {
return dateTimeFormatter.print(millis);
}
- private static DateTimeFormatter getDateTimeFormatter(String pattern) {
- // Note: withZoneUTC is overwritten if the timezone is specified directly
in the pattern
+ /**
+ * Converts the millis representing seconds since epoch into a string of
passed pattern and time zone id
+ */
+ public static String parseEpochMillisToDateTimeString(long millis, String
pattern, String timezoneId) {
+ DateTimeFormatter dateTimeFormatter = getDateTimeFormatter(pattern,
timezoneId);
+ return dateTimeFormatter.print(millis);
+ }
+
+ private static DateTimeFormatter getDateTimeFormatter(String pattern, String
timezoneId) {
// This also leverages an internal cache so it won't generate a new
DateTimeFormatter for every row with
// the same pattern
- return DateTimeFormat.forPattern(pattern).withZoneUTC();
+ return
DateTimeFormat.forPattern(pattern).withZone(DateTimeZone.forID(timezoneId));
+ }
+
+ private static DateTimeFormatter getDateTimeFormatter(String pattern) {
+ return getDateTimeFormatter(pattern, DateTimeZone.UTC.getID());
}
}
diff --git
a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/DateTimeFunctions.java
b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/DateTimeFunctions.java
index 8f30bda..e875fa6 100644
---
a/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/DateTimeFunctions.java
+++
b/pinot-common/src/main/java/org/apache/pinot/common/function/scalar/DateTimeFunctions.java
@@ -28,7 +28,6 @@ import org.apache.pinot.spi.annotations.ScalarFunction;
import org.joda.time.DateTime;
import org.joda.time.DateTimeField;
import org.joda.time.DateTimeZone;
-import org.joda.time.format.DateTimeFormat;
/**
@@ -258,14 +257,11 @@ public class DateTimeFunctions {
}
/**
- * Converts epoch millis to DateTime string represented by pattern
- * and the time zone id.
+ * Converts epoch millis to DateTime string represented by pattern and the
time zone id.
*/
@ScalarFunction
public static String toDateTime(long millis, String pattern, String
timezoneId) {
- return DateTimeFormat
- .forPattern(pattern)
- .withZone(DateTimeZone.forID(timezoneId)).print(millis);
+ return DateTimePatternHandler.parseEpochMillisToDateTimeString(millis,
pattern, timezoneId);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]