This is an automated email from the ASF dual-hosted git repository. nehapawar pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push: new 159e24e Function to round a time value (#5575) 159e24e is described below commit 159e24e6200c276704e683a9324a1351a35bb533 Author: Neha Pawar <neha.pawa...@gmail.com> AuthorDate: Tue Jun 16 14:46:23 2020 -0700 Function to round a time value (#5575) --- .../org/apache/pinot/common/function/DateTimeFunctions.java | 11 +++++++++++ .../apache/pinot/core/data/function/InbuiltFunctionsTest.java | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/pinot-common/src/main/java/org/apache/pinot/common/function/DateTimeFunctions.java b/pinot-common/src/main/java/org/apache/pinot/common/function/DateTimeFunctions.java index 66caafd..ce53773 100644 --- a/pinot-common/src/main/java/org/apache/pinot/common/function/DateTimeFunctions.java +++ b/pinot-common/src/main/java/org/apache/pinot/common/function/DateTimeFunctions.java @@ -241,6 +241,17 @@ public class DateTimeFunctions { return DateTimePatternHandler.parseDateTimeStringToEpochMillis(dateTimeString, pattern); } + + /** + * Round the given time value to nearest multiple + * @return the original value but rounded to the nearest multiple of @param roundToNearest + */ + @ScalarFunction + static Long round(Long timeValue, Number roundToNearest) { + long roundingValue = roundToNearest.longValue(); + return (timeValue / roundingValue) * roundingValue; + } + /** * Return current time as epoch millis */ diff --git a/pinot-core/src/test/java/org/apache/pinot/core/data/function/InbuiltFunctionsTest.java b/pinot-core/src/test/java/org/apache/pinot/core/data/function/InbuiltFunctionsTest.java index a156089..dabef53 100644 --- a/pinot-core/src/test/java/org/apache/pinot/core/data/function/InbuiltFunctionsTest.java +++ b/pinot-core/src/test/java/org/apache/pinot/core/data/function/InbuiltFunctionsTest.java @@ -47,6 +47,12 @@ public class InbuiltFunctionsTest { @DataProvider(name = "dateTimeFunctionsTestDataProvider") public Object[][] dateTimeFunctionsDataProvider() { List<Object[]> inputs = new ArrayList<>(); + // round epoch millis to nearest 15 minutes + GenericRow row0_0 = new GenericRow(); + row0_0.putValue("timestamp", 1578685189000L); + // round to 15 minutes, but keep in milliseconds: Fri Jan 10 2020 19:39:49 becomes Fri Jan 10 2020 19:30:00 + inputs.add(new Object[]{"round(timestamp, 900000)", Lists.newArrayList( + "timestamp"), row0_0, 1578684600000L}); // toEpochSeconds GenericRow row1_0 = new GenericRow(); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@pinot.apache.org For additional commands, e-mail: commits-h...@pinot.apache.org