You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ja...@apache.org on 2021/07/07 20:08:44 UTC
[incubator-pinot] branch master updated: Add datetime function with
2 arguments (#7116)
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/incubator-pinot.git
The following commit(s) were added to refs/heads/master by this push:
new 4e88da6 Add datetime function with 2 arguments (#7116)
4e88da6 is described below
commit 4e88da63949824abac0eea04baa1d6fe0292108f
Author: Kartik Khare <kh...@gmail.com>
AuthorDate: Thu Jul 8 01:38:30 2021 +0530
Add datetime function with 2 arguments (#7116)
Add dateTrunc function with 2 arguments
---
.../pinot/common/function/scalar/DateTimeFunctions.java | 11 +++++++++++
.../transform/function/DateTruncTransformFunction.java | 9 ++++++---
2 files changed, 17 insertions(+), 3 deletions(-)
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 350184d..a799d08 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
@@ -594,6 +594,17 @@ public class DateTimeFunctions {
}
/**
+ * The sql compatible date_trunc function for epoch time
+ * @param unit truncate to unit (millisecond, second, minute, hour, day, week, month, quarter, year)
+ * @param timeValue value to truncate
+ * @return truncated timeValue in TimeUnit.MILLISECONDS
+ */
+ @ScalarFunction
+ public long dateTrunc(String unit, long timeValue){
+ return dateTrunc(unit, timeValue, TimeUnit.MILLISECONDS.name());
+ }
+
+ /**
* The sql compatible date_trunc function for epoch time.
* @param unit truncate to unit (millisecond, second, minute, hour, day, week, month, quarter, year)
* @param timeValue value to truncate
diff --git a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/DateTruncTransformFunction.java b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/DateTruncTransformFunction.java
index a610687..7ee76f6 100644
--- a/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/DateTruncTransformFunction.java
+++ b/pinot-core/src/main/java/org/apache/pinot/core/operator/transform/function/DateTruncTransformFunction.java
@@ -30,6 +30,7 @@ import org.apache.pinot.core.plan.DocIdSetPlanNode;
import org.apache.pinot.segment.spi.datasource.DataSource;
import org.joda.time.DateTimeField;
+
/**
* The <code>DateTruncTransformationFunction</code> class implements the sql compatible date_trunc function for TIMESTAMP type.
* <p>
@@ -94,15 +95,17 @@ public class DateTruncTransformFunction extends BaseTransformFunction {
@Override
public void init(List<TransformFunction> arguments, Map<String, DataSource> dataSourceMap) {
- Preconditions.checkArgument(arguments.size() >= 3 && arguments.size() <= 5,
- "Between three to five arguments are required, example: %s", EXAMPLE_INVOCATION);
+ Preconditions.checkArgument(arguments.size() >= 2 && arguments.size() <= 5,
+ "Between two to five arguments are required, example: %s", EXAMPLE_INVOCATION);
String unit = ((LiteralTransformFunction) arguments.get(0)).getLiteral().toLowerCase();
TransformFunction valueArgument = arguments.get(1);
Preconditions.checkArgument(
!(valueArgument instanceof LiteralTransformFunction) && valueArgument.getResultMetadata().isSingleValue(),
"The second argument of dateTrunc transform function must be a single-valued column or a transform function");
_mainTransformFunction = valueArgument;
- String inputTimeUnitStr = ((LiteralTransformFunction) arguments.get(2)).getLiteral().toUpperCase();
+ String inputTimeUnitStr =
+ (arguments.size() >= 3) ? ((LiteralTransformFunction) arguments.get(2)).getLiteral().toUpperCase()
+ : TimeUnit.MILLISECONDS.name();
_inputTimeUnit = TimeUnit.valueOf(inputTimeUnitStr);
String timeZone = arguments.size() >= 4 ? ((LiteralTransformFunction) arguments.get(3)).getLiteral() : UTC_TZ;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org