[
https://issues.apache.org/jira/browse/DRILL-7668?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17076600#comment-17076600
]
ASF GitHub Bot commented on DRILL-7668:
---------------------------------------
cgivre commented on pull request #2040: DRILL-7668: Allow Time Bucket Function
to Accept Floats and Timestamps
URL: https://github.com/apache/drill/pull/2040#discussion_r404339305
##########
File path:
contrib/udfs/src/main/java/org/apache/drill/exec/udfs/TimeBucketFunctions.java
##########
@@ -97,9 +99,86 @@ public void eval() {
long timestamp = inputDate.value;
// Get the interval in milliseconds
- long intervalToAdd = interval.value;
+ long groupByInterval = interval.value;
- out.value = timestamp - (timestamp % intervalToAdd);
+ out.value = timestamp - (timestamp % groupByInterval);
+ }
+ }
+
+ /**
+ * This function is used for facilitating time series analysis by creating
buckets of time intervals. See
+ *
https://blog.timescale.com/blog/simplified-time-series-analytics-using-the-time_bucket-function/
for usage. The function takes two arguments:
+ * 1. The timestamp (as a Drill timestamp)
+ * 2. The desired bucket interval IN milliseconds
+ *
+ * The function returns a BIGINT of the nearest time bucket.
+ */
+ @FunctionTemplate(name = "time_bucket",
+ scope = FunctionTemplate.FunctionScope.SIMPLE,
+ nulls = FunctionTemplate.NullHandling.NULL_IF_NULL)
+ public static class TimestampTimeBucketFunction implements DrillSimpleFunc {
+
+ @Param
+ TimeStampHolder inputDate;
+
+ @Param
+ BigIntHolder interval;
+
+ @Output
+ TimeStampHolder out;
+
+ @Override
+ public void setup() {
+ }
+
+ @Override
+ public void eval() {
+ // Get the timestamp in milliseconds
+ long timestamp = inputDate.value;
+
+ // Get the interval in milliseconds
+ long groupByInterval = interval.value;
+
+ java.time.Instant instant = java.time.Instant.ofEpochMilli(timestamp -
(timestamp % groupByInterval));
Review comment:
Done.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
> Allow Time Bucket Function to Accept Floats and Timestamps
> ----------------------------------------------------------
>
> Key: DRILL-7668
> URL: https://issues.apache.org/jira/browse/DRILL-7668
> Project: Apache Drill
> Issue Type: Improvement
> Components: Functions - Drill
> Affects Versions: 1.18.0
> Reporter: Charles Givre
> Assignee: Charles Givre
> Priority: Minor
> Labels: ready-to-commit
> Fix For: 1.18.0
>
>
> Drill has a function `time_bucket()` which facilitates time series analysis.
> This PR extends this function to accept `FLOAT8` and `TIMESTAMPS` as input.
> Floats are typically not used for timestamps, however in the event that the
> data is coming from imperfect files, the numbers may be read as floats and
> hence require casting in queries. This PR makes this easier.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)