This is an automated email from the ASF dual-hosted git repository.
jackie 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 86b3b3e1c5 [feature] multi-value datetime transform variants (#10841)
86b3b3e1c5 is described below
commit 86b3b3e1c5bad5092f357358888ff28903ab05df
Author: Evan Galpin <[email protected]>
AuthorDate: Fri Jun 9 18:51:18 2023 -0700
[feature] multi-value datetime transform variants (#10841)
---
.../common/function/scalar/DateTimeFunctions.java | 575 +++++++++++++++++++++
1 file changed, 575 insertions(+)
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 8330cbbe68..77db5d7fcd 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
@@ -79,6 +79,15 @@ public class DateTimeFunctions {
return TimeUnit.MILLISECONDS.toSeconds(millis);
}
+ @ScalarFunction
+ public static long[] toEpochSecondsMV(long[] millis) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochSeconds(millis[i]);
+ }
+ return results;
+ }
+
/**
* Convert epoch millis to epoch minutes
*/
@@ -87,6 +96,15 @@ public class DateTimeFunctions {
return TimeUnit.MILLISECONDS.toMinutes(millis);
}
+ @ScalarFunction
+ public static long[] toEpochMinutesMV(long[] millis) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochMinutes(millis[i]);
+ }
+ return results;
+ }
+
/**
* Convert epoch millis to epoch hours
*/
@@ -95,6 +113,15 @@ public class DateTimeFunctions {
return TimeUnit.MILLISECONDS.toHours(millis);
}
+ @ScalarFunction
+ public static long[] toEpochHoursMV(long[] millis) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochHours(millis[i]);
+ }
+ return results;
+ }
+
/**
* Convert epoch millis to epoch days
*/
@@ -103,6 +130,15 @@ public class DateTimeFunctions {
return TimeUnit.MILLISECONDS.toDays(millis);
}
+ @ScalarFunction
+ public static long[] toEpochDaysMV(long[] millis) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochDays(millis[i]);
+ }
+ return results;
+ }
+
/**
* Convert epoch millis to epoch seconds, round to nearest rounding bucket
*/
@@ -111,6 +147,16 @@ public class DateTimeFunctions {
return (TimeUnit.MILLISECONDS.toSeconds(millis) / roundToNearest) *
roundToNearest;
}
+ @ScalarFunction
+ public static long[] toEpochSecondsRoundedMV(long[] millis, long
roundToNearest) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochSecondsRounded(millis[i], roundToNearest);
+ }
+ return results;
+ }
+
+
/**
* Convert epoch millis to epoch minutes, round to nearest rounding bucket
*/
@@ -119,6 +165,16 @@ public class DateTimeFunctions {
return (TimeUnit.MILLISECONDS.toMinutes(millis) / roundToNearest) *
roundToNearest;
}
+ @ScalarFunction
+ public static long[] toEpochMinutesRoundedMV(long[] millis, long
roundToNearest) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochMinutesRounded(millis[i], roundToNearest);
+ }
+ return results;
+ }
+
+
/**
* Convert epoch millis to epoch hours, round to nearest rounding bucket
*/
@@ -127,6 +183,16 @@ public class DateTimeFunctions {
return (TimeUnit.MILLISECONDS.toHours(millis) / roundToNearest) *
roundToNearest;
}
+ @ScalarFunction
+ public static long[] toEpochHoursRoundedMV(long[] millis, long
roundToNearest) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochHoursRounded(millis[i], roundToNearest);
+ }
+ return results;
+ }
+
+
/**
* Convert epoch millis to epoch days, round to nearest rounding bucket
*/
@@ -135,6 +201,16 @@ public class DateTimeFunctions {
return (TimeUnit.MILLISECONDS.toDays(millis) / roundToNearest) *
roundToNearest;
}
+ @ScalarFunction
+ public static long[] toEpochDaysRoundedMV(long[] millis, long
roundToNearest) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochDaysRounded(millis[i], roundToNearest);
+ }
+ return results;
+ }
+
+
/**
* Convert epoch millis to epoch seconds, divided by given bucket, to get
nSecondsSinceEpoch
*/
@@ -143,6 +219,16 @@ public class DateTimeFunctions {
return TimeUnit.MILLISECONDS.toSeconds(millis) / bucket;
}
+ @ScalarFunction
+ public static long[] toEpochSecondsBucketMV(long[] millis, long bucket) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochSecondsBucket(millis[i], bucket);
+ }
+ return results;
+ }
+
+
/**
* Convert epoch millis to epoch minutes, divided by given bucket, to get
nMinutesSinceEpoch
*/
@@ -151,6 +237,16 @@ public class DateTimeFunctions {
return TimeUnit.MILLISECONDS.toMinutes(millis) / bucket;
}
+ @ScalarFunction
+ public static long[] toEpochMinutesBucketMV(long[] millis, long bucket) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochMinutesBucket(millis[i], bucket);
+ }
+ return results;
+ }
+
+
/**
* Convert epoch millis to epoch hours, divided by given bucket, to get
nHoursSinceEpoch
*/
@@ -159,6 +255,16 @@ public class DateTimeFunctions {
return TimeUnit.MILLISECONDS.toHours(millis) / bucket;
}
+ @ScalarFunction
+ public static long[] toEpochHoursBucketMV(long[] millis, long bucket) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochHoursBucket(millis[i], bucket);
+ }
+ return results;
+ }
+
+
/**
* Convert epoch millis to epoch days, divided by given bucket, to get
nDaysSinceEpoch
*/
@@ -167,6 +273,16 @@ public class DateTimeFunctions {
return TimeUnit.MILLISECONDS.toDays(millis) / bucket;
}
+ @ScalarFunction
+ public static long[] toEpochDaysBucketMV(long[] millis, long bucket) {
+ long[] results = new long[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toEpochDaysBucket(millis[i], bucket);
+ }
+ return results;
+ }
+
+
/**
* Converts epoch seconds to epoch millis
*/
@@ -175,6 +291,15 @@ public class DateTimeFunctions {
return TimeUnit.SECONDS.toMillis(seconds);
}
+ @ScalarFunction
+ public static long[] fromEpochSecondsMV(long[] seconds) {
+ long[] results = new long[seconds.length];
+ for (int i = 0; i < seconds.length; i++) {
+ results[i] = fromEpochSeconds(seconds[i]);
+ }
+ return results;
+ }
+
/**
* Converts epoch minutes to epoch millis
*/
@@ -183,6 +308,15 @@ public class DateTimeFunctions {
return TimeUnit.MINUTES.toMillis(minutes);
}
+ @ScalarFunction
+ public static long[] fromEpochMinutesMV(long[] minutes) {
+ long[] results = new long[minutes.length];
+ for (int i = 0; i < minutes.length; i++) {
+ results[i] = fromEpochMinutes(minutes[i]);
+ }
+ return results;
+ }
+
/**
* Converts epoch hours to epoch millis
*/
@@ -191,6 +325,15 @@ public class DateTimeFunctions {
return TimeUnit.HOURS.toMillis(hours);
}
+ @ScalarFunction
+ public static long[] fromEpochHoursMV(long[] hours) {
+ long[] results = new long[hours.length];
+ for (int i = 0; i < hours.length; i++) {
+ results[i] = fromEpochHours(hours[i]);
+ }
+ return results;
+ }
+
/**
* Converts epoch days to epoch millis
*/
@@ -199,6 +342,15 @@ public class DateTimeFunctions {
return TimeUnit.DAYS.toMillis(days);
}
+ @ScalarFunction
+ public static long[] fromEpochDaysMV(long[] days) {
+ long[] results = new long[days.length];
+ for (int i = 0; i < days.length; i++) {
+ results[i] = fromEpochDays(days[i]);
+ }
+ return results;
+ }
+
/**
* Converts nSecondsSinceEpoch (seconds that have been divided by a bucket),
to epoch millis
*/
@@ -207,6 +359,15 @@ public class DateTimeFunctions {
return TimeUnit.SECONDS.toMillis(seconds * bucket);
}
+ @ScalarFunction
+ public static long[] fromEpochSecondsBucketMV(long[] seconds, long bucket) {
+ long[] results = new long[seconds.length];
+ for (int i = 0; i < seconds.length; i++) {
+ results[i] = fromEpochSecondsBucket(seconds[i], bucket);
+ }
+ return results;
+ }
+
/**
* Converts nMinutesSinceEpoch (minutes that have been divided by a bucket),
to epoch millis
*/
@@ -215,6 +376,15 @@ public class DateTimeFunctions {
return TimeUnit.MINUTES.toMillis(minutes * bucket);
}
+ @ScalarFunction
+ public static long[] fromEpochMinutesBucketMV(long[] minutes, long bucket) {
+ long[] results = new long[minutes.length];
+ for (int i = 0; i < minutes.length; i++) {
+ results[i] = fromEpochMinutesBucket(minutes[i], bucket);
+ }
+ return results;
+ }
+
/**
* Converts nHoursSinceEpoch (hours that have been divided by a bucket), to
epoch millis
*/
@@ -223,6 +393,15 @@ public class DateTimeFunctions {
return TimeUnit.HOURS.toMillis(hours * bucket);
}
+ @ScalarFunction
+ public static long[] fromEpochHoursBucketMV(long[] hours, long bucket) {
+ long[] results = new long[hours.length];
+ for (int i = 0; i < hours.length; i++) {
+ results[i] = fromEpochHoursBucket(hours[i], bucket);
+ }
+ return results;
+ }
+
/**
* Converts nDaysSinceEpoch (days that have been divided by a bucket), to
epoch millis
*/
@@ -231,6 +410,15 @@ public class DateTimeFunctions {
return TimeUnit.DAYS.toMillis(days * bucket);
}
+ @ScalarFunction
+ public static long[] fromEpochDaysBucketMV(long[] days, long bucket) {
+ long[] results = new long[days.length];
+ for (int i = 0; i < days.length; i++) {
+ results[i] = fromEpochDaysBucket(days[i], bucket);
+ }
+ return results;
+ }
+
/**
* Converts epoch millis to Timestamp
*/
@@ -239,6 +427,15 @@ public class DateTimeFunctions {
return new Timestamp(millis);
}
+ @ScalarFunction
+ public static Timestamp[] toTimestampMV(long[] millis) {
+ Timestamp[] results = new Timestamp[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toTimestamp(millis[i]);
+ }
+ return results;
+ }
+
/**
* Converts Timestamp to epoch millis
*/
@@ -247,6 +444,15 @@ public class DateTimeFunctions {
return timestamp.getTime();
}
+ @ScalarFunction
+ public static long[] fromTimestampMV(Timestamp[] timestamp) {
+ long[] results = new long[timestamp.length];
+ for (int i = 0; i < timestamp.length; i++) {
+ results[i] = fromTimestamp(timestamp[i]);
+ }
+ return results;
+ }
+
/**
* Converts epoch millis to DateTime string represented by pattern
*/
@@ -255,6 +461,15 @@ public class DateTimeFunctions {
return DateTimePatternHandler.parseEpochMillisToDateTimeString(millis,
pattern);
}
+ @ScalarFunction
+ public static String[] toDateTimeMV(long[] millis, String pattern) {
+ String[] results = new String[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toDateTime(millis[i], pattern);
+ }
+ return results;
+ }
+
/**
* Converts epoch millis to DateTime string represented by pattern and the
time zone id.
*/
@@ -263,6 +478,15 @@ public class DateTimeFunctions {
return DateTimePatternHandler.parseEpochMillisToDateTimeString(millis,
pattern, timezoneId);
}
+ @ScalarFunction
+ public static String[] toDateTimeMV(long[] millis, String pattern, String
timezoneId) {
+ String[] results = new String[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = toDateTime(millis[i], pattern, timezoneId);
+ }
+ return results;
+ }
+
/**
* Converts DateTime string represented by pattern to epoch millis
*/
@@ -271,6 +495,15 @@ public class DateTimeFunctions {
return
DateTimePatternHandler.parseDateTimeStringToEpochMillis(dateTimeString,
pattern);
}
+ @ScalarFunction
+ public static long[] fromDateTimeMV(String[] dateTimeString, String pattern)
{
+ long[] results = new long[dateTimeString.length];
+ for (int i = 0; i < dateTimeString.length; i++) {
+ results[i] = fromDateTime(dateTimeString[i], pattern);
+ }
+ return results;
+ }
+
/**
* Converts DateTime string represented by pattern to epoch millis
*/
@@ -279,6 +512,15 @@ public class DateTimeFunctions {
return
DateTimePatternHandler.parseDateTimeStringToEpochMillis(dateTimeString,
pattern, timeZoneId);
}
+ @ScalarFunction
+ public static long[] fromDateTimeMV(String[] dateTimeString, String pattern,
String timeZoneId) {
+ long[] results = new long[dateTimeString.length];
+ for (int i = 0; i < dateTimeString.length; i++) {
+ results[i] = fromDateTime(dateTimeString[i], pattern, timeZoneId);
+ }
+ return results;
+ }
+
/**
* Round the given time value to nearest multiple
* @return the original value but rounded to the nearest multiple of @param
roundToNearest
@@ -288,6 +530,15 @@ public class DateTimeFunctions {
return (timeValue / roundToNearest) * roundToNearest;
}
+ @ScalarFunction
+ public static long[] roundMV(long[] timeValue, long roundToNearest) {
+ long[] results = new long[timeValue.length];
+ for (int i = 0; i < timeValue.length; i++) {
+ results[i] = round(timeValue[i], roundToNearest);
+ }
+ return results;
+ }
+
/**
* Return current time as epoch millis
* TODO: Consider changing the return type to Timestamp
@@ -315,6 +566,15 @@ public class DateTimeFunctions {
return System.currentTimeMillis() - period.toMillis();
}
+ @ScalarFunction
+ public static long[] agoMV(String[] periodString) {
+ long[] results = new long[periodString.length];
+ for (int i = 0; i < periodString.length; i++) {
+ results[i] = ago(periodString[i]);
+ }
+ return results;
+ }
+
/**
* The {@code timezoneId} for the following methods must be of a Joda-Time
format:
* https://www.joda.org/joda-time/timezones.html
@@ -328,6 +588,14 @@ public class DateTimeFunctions {
return timezoneHour(timezoneId, 0);
}
+ @ScalarFunction
+ public static int[] timezoneHourMV(String[] timezoneId) {
+ int[] results = new int[timezoneId.length];
+ for (int i = 0; i < timezoneId.length; i++) {
+ results[i] = timezoneHour(timezoneId[i], 0);
+ }
+ return results;
+ }
/**
* Returns the hour of the time zone offset, for the UTC timestamp at {@code
millis}. This will
* properly handle daylight savings time.
@@ -337,6 +605,15 @@ public class DateTimeFunctions {
return (int)
TimeUnit.MILLISECONDS.toHours(DateTimeZone.forID(timezoneId).getOffset(millis));
}
+ @ScalarFunction
+ public static int[] timezoneHourMV(String timezoneId, long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = timezoneHour(timezoneId, millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the minute of the time zone offset.
*/
@@ -345,6 +622,15 @@ public class DateTimeFunctions {
return timezoneMinute(timezoneId, 0);
}
+ @ScalarFunction
+ public static int[] timezoneMinuteMV(String[] timezoneId) {
+ int[] results = new int[timezoneId.length];
+ for (int i = 0; i < timezoneId.length; i++) {
+ results[i] = timezoneMinute(timezoneId[i], 0);
+ }
+ return results;
+ }
+
/**
* Returns the minute of the time zone offset, for the UTC timestamp at
{@code millis}. This will
* properly handle daylight savings time
@@ -354,6 +640,15 @@ public class DateTimeFunctions {
return (int)
TimeUnit.MILLISECONDS.toMinutes(DateTimeZone.forID(timezoneId).getOffset(millis))
% 60;
}
+ @ScalarFunction
+ public static int[] timezoneMinuteMV(String timezoneId, long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = timezoneMinute(timezoneId, millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the year from the given epoch millis in UTC timezone.
*/
@@ -362,6 +657,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getYear();
}
+ @ScalarFunction
+ public static int[] yearMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = year(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the year from the given epoch millis and timezone id.
*/
@@ -370,6 +674,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.forID(timezoneId)).getYear();
}
+ @ScalarFunction
+ public static int[] yearMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = year(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the year of the ISO week from the given epoch millis in UTC
timezone.
*/
@@ -378,6 +691,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getWeekyear();
}
+ @ScalarFunction(names = {"yearOfWeekMV", "year_of_week_mv", "yowmv"})
+ public static int[] yearOfWeekMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = yearOfWeek(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the year of the ISO week from the given epoch millis and timezone
id.
*/
@@ -386,6 +708,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.forID(timezoneId)).getWeekyear();
}
+ @ScalarFunction(names = {"yearOfWeekMV", "year_of_week_mv", "yowmv"})
+ public static int[] yearOfWeekMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = yearOfWeek(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the quarter of the year from the given epoch millis in UTC
timezone. The value ranges from 1 to 4.
*/
@@ -394,6 +725,15 @@ public class DateTimeFunctions {
return (monthOfYear(millis) - 1) / 3 + 1;
}
+ @ScalarFunction
+ public static int[] quarterMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = quarter(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the quarter of the year from the given epoch millis and timezone
id. The value ranges from 1 to 4.
*/
@@ -402,6 +742,15 @@ public class DateTimeFunctions {
return (monthOfYear(millis, timezoneId) - 1) / 3 + 1;
}
+ @ScalarFunction
+ public static int[] quarterMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = quarter(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the month of the year from the given epoch millis in UTC
timezone. The value ranges from 1 to 12.
*/
@@ -410,6 +759,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getMonthOfYear();
}
+ @ScalarFunction(names = {"monthMV", "month_of_year_mv", "monthOfYearMV"})
+ public static int[] monthOfYearMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = monthOfYear(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the month of the year from the given epoch millis and timezone
id. The value ranges from 1 to 12.
*/
@@ -418,6 +776,15 @@ public class DateTimeFunctions {
return new DateTime(millis,
DateTimeZone.forID(timezoneId)).getMonthOfYear();
}
+ @ScalarFunction(names = {"monthMV", "month_of_year_mv", "monthOfYearMV"})
+ public static int[] monthOfYearMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = monthOfYear(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the ISO week of the year from the given epoch millis in UTC
timezone.The value ranges from 1 to 53.
*/
@@ -426,6 +793,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getWeekOfWeekyear();
}
+ @ScalarFunction(names = {"weekOfYearMV", "week_of_year_mv", "weekMV"})
+ public static int[] weekOfYearMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = weekOfYear(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the ISO week of the year from the given epoch millis and timezone
id. The value ranges from 1 to 53.
*/
@@ -434,6 +810,15 @@ public class DateTimeFunctions {
return new DateTime(millis,
DateTimeZone.forID(timezoneId)).getWeekOfWeekyear();
}
+ @ScalarFunction(names = {"weekOfYearMV", "week_of_year_mv", "weekMV"})
+ public static int[] weekOfYearMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = weekOfYear(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the day of the year from the given epoch millis in UTC timezone.
The value ranges from 1 to 366.
*/
@@ -442,6 +827,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getDayOfYear();
}
+ @ScalarFunction(names = {"dayOfYearMV", "day_of_year_mv", "doyMV"})
+ public static int[] dayOfYear(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = dayOfYear(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the day of the year from the given epoch millis and timezone id.
The value ranges from 1 to 366.
*/
@@ -450,6 +844,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.forID(timezoneId)).getDayOfYear();
}
+ @ScalarFunction(names = {"dayOfYearMV", "day_of_year_mv", "doyMV"})
+ public static int[] dayOfYear(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = dayOfYear(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the day of the month from the given epoch millis in UTC timezone.
The value ranges from 1 to 31.
*/
@@ -458,6 +861,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getDayOfMonth();
}
+ @ScalarFunction(names = {"dayMV", "dayOfMonthMV", "day_of_month_mv"})
+ public static int[] dayOfMonthMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = dayOfMonth(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the day of the month from the given epoch millis and timezone id.
The value ranges from 1 to 31.
*/
@@ -466,6 +878,15 @@ public class DateTimeFunctions {
return new DateTime(millis,
DateTimeZone.forID(timezoneId)).getDayOfMonth();
}
+ @ScalarFunction(names = {"dayMV", "dayOfMonthMV", "day_of_month_mv"})
+ public static int[] dayOfMonthMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = dayOfMonth(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the day of the week from the given epoch millis in UTC timezone.
The value ranges from 1 (Monday) to 7
* (Sunday).
@@ -475,6 +896,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getDayOfWeek();
}
+ @ScalarFunction(names = {"dayOfWeekMV", "day_of_week_mv", "dowMV"})
+ public static int[] dayOfWeekMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = dayOfWeek(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the day of the week from the given epoch millis and timezone id.
The value ranges from 1 (Monday) to 7
* (Sunday).
@@ -484,6 +914,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.forID(timezoneId)).getDayOfWeek();
}
+ @ScalarFunction(names = {"dayOfWeekMV", "day_of_week_mv", "dowMV"})
+ public static int[] dayOfWeekMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = dayOfWeek(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the hour of the day from the given epoch millis in UTC timezone.
The value ranges from 0 to 23.
*/
@@ -492,6 +931,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getHourOfDay();
}
+ @ScalarFunction
+ public static int[] hourMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = hour(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the hour of the day from the given epoch millis and timezone id.
The value ranges from 0 to 23.
*/
@@ -500,6 +948,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.forID(timezoneId)).getHourOfDay();
}
+ @ScalarFunction
+ public static int[] hourMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = hour(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the minute of the hour from the given epoch millis in UTC
timezone. The value ranges from 0 to 59.
*/
@@ -508,6 +965,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getMinuteOfHour();
}
+ @ScalarFunction
+ public static int[] minuteMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = minute(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the minute of the hour from the given epoch millis and timezone
id. The value ranges from 0 to 59.
*/
@@ -516,6 +982,15 @@ public class DateTimeFunctions {
return new DateTime(millis,
DateTimeZone.forID(timezoneId)).getMinuteOfHour();
}
+ @ScalarFunction
+ public static int[] minuteMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = minute(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the second of the minute from the given epoch millis in UTC
timezone. The value ranges from 0 to 59.
*/
@@ -524,6 +999,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getSecondOfMinute();
}
+ @ScalarFunction
+ public static int[] secondMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = second(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the second of the minute from the given epoch millis and timezone
id. The value ranges from 0 to 59.
*/
@@ -532,6 +1016,15 @@ public class DateTimeFunctions {
return new DateTime(millis,
DateTimeZone.forID(timezoneId)).getSecondOfMinute();
}
+ @ScalarFunction
+ public static int[] secondMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = second(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* Returns the millisecond of the second from the given epoch millis in UTC
timezone. The value ranges from 0 to 999.
*/
@@ -540,6 +1033,15 @@ public class DateTimeFunctions {
return new DateTime(millis, DateTimeZone.UTC).getMillisOfSecond();
}
+ @ScalarFunction
+ public static int[] millisecondMV(long[] millis) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = millisecond(millis[i]);
+ }
+ return results;
+ }
+
/**
* Returns the millisecond of the second from the given epoch millis and
timezone id. The value ranges from 0 to 999.
*/
@@ -548,6 +1050,15 @@ public class DateTimeFunctions {
return new DateTime(millis,
DateTimeZone.forID(timezoneId)).getMillisOfSecond();
}
+ @ScalarFunction
+ public static int[] millisecondMV(long[] millis, String timezoneId) {
+ int[] results = new int[millis.length];
+ for (int i = 0; i < millis.length; i++) {
+ results[i] = millisecond(millis[i], timezoneId);
+ }
+ return results;
+ }
+
/**
* The sql compatible date_trunc function for epoch time.
*
@@ -561,6 +1072,15 @@ public class DateTimeFunctions {
TimeUnit.MILLISECONDS.name());
}
+ @ScalarFunction
+ public static long[] dateTruncMV(String unit, long[] timeValue) {
+ long[] results = new long[timeValue.length];
+ for (int i = 0; i < timeValue.length; i++) {
+ results[i] = dateTrunc(unit, timeValue[i]);
+ }
+ return results;
+ }
+
/**
* The sql compatible date_trunc function for epoch time.
*
@@ -574,6 +1094,15 @@ public class DateTimeFunctions {
return dateTrunc(unit, timeValue, inputTimeUnit,
ISOChronology.getInstanceUTC(), inputTimeUnit);
}
+ @ScalarFunction
+ public static long[] dateTruncMV(String unit, long[] timeValue, String
inputTimeUnit) {
+ long[] results = new long[timeValue.length];
+ for (int i = 0; i < timeValue.length; i++) {
+ results[i] = dateTrunc(unit, timeValue[i], inputTimeUnit);
+ }
+ return results;
+ }
+
/**
* The sql compatible date_trunc function for epoch time.
*
@@ -589,6 +1118,15 @@ public class DateTimeFunctions {
inputTimeUnit);
}
+ @ScalarFunction
+ public static long[] dateTruncMV(String unit, long[] timeValue, String
inputTimeUnit, String timeZone) {
+ long[] results = new long[timeValue.length];
+ for (int i = 0; i < timeValue.length; i++) {
+ results[i] = dateTrunc(unit, timeValue[i], inputTimeUnit, timeZone);
+ }
+ return results;
+ }
+
/**
* The sql compatible date_trunc function for epoch time.
*
@@ -607,6 +1145,16 @@ public class DateTimeFunctions {
DateTimeUtils.getChronology(TimeZoneKey.getTimeZoneKey(timeZone)),
outputTimeUnit);
}
+ @ScalarFunction
+ public static long[] dateTruncMV(String unit, long[] timeValue, String
inputTimeUnit, String timeZone,
+ String outputTimeUnit) {
+ long[] results = new long[timeValue.length];
+ for (int i = 0; i < timeValue.length; i++) {
+ results[i] = dateTrunc(unit, timeValue[i], inputTimeUnit, timeZone,
outputTimeUnit);
+ }
+ return results;
+ }
+
private static long dateTrunc(String unit, long timeValue, String
inputTimeUnit, ISOChronology chronology,
String outputTimeUnit) {
return
TimeUnit.valueOf(outputTimeUnit.toUpperCase()).convert(DateTimeUtils.getTimestampField(chronology,
unit)
@@ -629,6 +1177,15 @@ public class DateTimeFunctions {
return millis;
}
+ @ScalarFunction(names = {"timestampAddMV", "dateAddMV"})
+ public static long[] timestampAddMV(String unit, long interval, long[]
timestamp) {
+ long[] results = new long[timestamp.length];
+ for (int i = 0; i < timestamp.length; i++) {
+ results[i] = timestampAdd(unit, interval, timestamp[i]);
+ }
+ return results;
+ }
+
/**
* Get difference between two timestamps and return the result in the
specified timeunit.
* e.g. timestampDiff('days', ago('10D'), ago('2D')) will return 8 i.e. 8
days
@@ -642,4 +1199,22 @@ public class DateTimeFunctions {
ISOChronology chronology = ISOChronology.getInstanceUTC();
return DateTimeUtils.getTimestampField(chronology,
unit).getDifferenceAsLong(timestamp2, timestamp1);
}
+
+ @ScalarFunction(names = {"timestampDiffMV", "dateDiffMV"})
+ public static long[] timestampDiffMV(String unit, long[] timestamp1, long
timestamp2) {
+ long[] results = new long[timestamp1.length];
+ for (int i = 0; i < timestamp1.length; i++) {
+ results[i] = timestampDiff(unit, timestamp1[i], timestamp2);
+ }
+ return results;
+ }
+
+ @ScalarFunction(names = {"timestampDiffMVReverse", "dateDiffMVReverse"})
+ public static long[] timestampDiffMVReverse(String unit, long timestamp1,
long[] timestamp2) {
+ long[] results = new long[timestamp2.length];
+ for (int i = 0; i < timestamp2.length; i++) {
+ results[i] = timestampDiff(unit, timestamp1, timestamp2[i]);
+ }
+ return results;
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]