You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ro...@apache.org on 2024/03/13 05:09:39 UTC
(iotdb) branch master updated: UDF: add "timestampPrecision" system parameter in UDFParameters (#12158)
This is an automated email from the ASF dual-hosted git repository.
rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git
The following commit(s) were added to refs/heads/master by this push:
new b61739ab41e UDF: add "timestampPrecision" system parameter in UDFParameters (#12158)
b61739ab41e is described below
commit b61739ab41eddaf678d8db67f6b913a7a8719441
Author: Zhijia Cao <ca...@126.com>
AuthorDate: Wed Mar 13 13:09:13 2024 +0800
UDF: add "timestampPrecision" system parameter in UDFParameters (#12158)
---
.../api/customizer/parameter/UDFParameters.java | 112 +++++++++++++++++----
.../execution/aggregation/UDAFAccumulator.java | 7 +-
.../dag/udf/UDAFInformationInferrer.java | 6 +-
.../dag/udf/UDFParametersFactory.java | 54 ++++++++++
.../transformation/dag/udf/UDTFExecutor.java | 6 +-
.../dag/udf/UDTFInformationInferrer.java | 7 +-
6 files changed, 158 insertions(+), 34 deletions(-)
diff --git a/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/customizer/parameter/UDFParameters.java b/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/customizer/parameter/UDFParameters.java
index b082d4cffb6..8bfd25a8571 100644
--- a/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/customizer/parameter/UDFParameters.java
+++ b/iotdb-api/udf-api/src/main/java/org/apache/iotdb/udf/api/customizer/parameter/UDFParameters.java
@@ -23,6 +23,7 @@ import org.apache.iotdb.udf.api.UDTF;
import org.apache.iotdb.udf.api.customizer.config.UDTFConfigurations;
import org.apache.iotdb.udf.api.type.Type;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -42,15 +43,25 @@ public class UDFParameters {
private final List<String> childExpressions;
private final List<Type> childExpressionDataTypes;
- private final Map<String, String> attributes;
+ private final Map<String, String> userAttributes;
+ private final Map<String, String> systemAttributes;
public UDFParameters(
List<String> childExpressions,
List<Type> childExpressionDataTypes,
- Map<String, String> attributes) {
+ Map<String, String> userAttributes) {
+ this(childExpressions, childExpressionDataTypes, userAttributes, new HashMap<>());
+ }
+
+ public UDFParameters(
+ List<String> childExpressions,
+ List<Type> childExpressionDataTypes,
+ Map<String, String> userAttributes,
+ Map<String, String> systemAttributes) {
this.childExpressions = childExpressions;
this.childExpressionDataTypes = childExpressionDataTypes;
- this.attributes = attributes;
+ this.userAttributes = userAttributes;
+ this.systemAttributes = systemAttributes;
}
public List<String> getChildExpressions() {
@@ -58,7 +69,7 @@ public class UDFParameters {
}
public Map<String, String> getAttributes() {
- return attributes;
+ return userAttributes;
}
public List<Type> getDataTypes() {
@@ -74,65 +85,132 @@ public class UDFParameters {
}
public boolean hasAttribute(String attributeKey) {
- return attributes.containsKey(attributeKey);
+ return userAttributes.containsKey(attributeKey);
}
public String getString(String key) {
- return attributes.get(key);
+ return userAttributes.get(key);
}
public Boolean getBoolean(String key) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? null : Boolean.parseBoolean(value);
}
public Integer getInt(String key) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? null : Integer.parseInt(value);
}
public Long getLong(String key) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? null : Long.parseLong(value);
}
public Float getFloat(String key) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? null : Float.parseFloat(value);
}
public Double getDouble(String key) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? null : Double.parseDouble(value);
}
public String getStringOrDefault(String key, String defaultValue) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? defaultValue : value;
}
public boolean getBooleanOrDefault(String key, boolean defaultValue) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? defaultValue : Boolean.parseBoolean(value);
}
public int getIntOrDefault(String key, int defaultValue) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? defaultValue : Integer.parseInt(value);
}
public long getLongOrDefault(String key, long defaultValue) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? defaultValue : Long.parseLong(value);
}
public float getFloatOrDefault(String key, float defaultValue) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
return value == null ? defaultValue : Float.parseFloat(value);
}
public double getDoubleOrDefault(String key, double defaultValue) {
- String value = attributes.get(key);
+ String value = userAttributes.get(key);
+ return value == null ? defaultValue : Double.parseDouble(value);
+ }
+
+ public boolean hasSystemAttribute(String attributeKey) {
+ return systemAttributes.containsKey(attributeKey);
+ }
+
+ public Map<String, String> getSystemAttributes() {
+ return systemAttributes;
+ }
+
+ public String getSystemString(String key) {
+ return systemAttributes.get(key);
+ }
+
+ public Boolean getSystemBoolean(String key) {
+ String value = systemAttributes.get(key);
+ return value == null ? null : Boolean.parseBoolean(value);
+ }
+
+ public Integer getSystemInt(String key) {
+ String value = systemAttributes.get(key);
+ return value == null ? null : Integer.parseInt(value);
+ }
+
+ public Long getSystemLong(String key) {
+ String value = systemAttributes.get(key);
+ return value == null ? null : Long.parseLong(value);
+ }
+
+ public Float getSystemFloat(String key) {
+ String value = systemAttributes.get(key);
+ return value == null ? null : Float.parseFloat(value);
+ }
+
+ public Double getSystemDouble(String key) {
+ String value = systemAttributes.get(key);
+ return value == null ? null : Double.parseDouble(value);
+ }
+
+ public String getSystemStringOrDefault(String key, String defaultValue) {
+ String value = systemAttributes.get(key);
+ return value == null ? defaultValue : value;
+ }
+
+ public boolean getSystemBooleanOrDefault(String key, boolean defaultValue) {
+ String value = systemAttributes.get(key);
+ return value == null ? defaultValue : Boolean.parseBoolean(value);
+ }
+
+ public int getSystemIntOrDefault(String key, int defaultValue) {
+ String value = systemAttributes.get(key);
+ return value == null ? defaultValue : Integer.parseInt(value);
+ }
+
+ public long getSystemLongOrDefault(String key, long defaultValue) {
+ String value = systemAttributes.get(key);
+ return value == null ? defaultValue : Long.parseLong(value);
+ }
+
+ public float getSystemFloatOrDefault(String key, float defaultValue) {
+ String value = systemAttributes.get(key);
+ return value == null ? defaultValue : Float.parseFloat(value);
+ }
+
+ public double getSystemDoubleOrDefault(String key, double defaultValue) {
+ String value = systemAttributes.get(key);
return value == null ? defaultValue : Double.parseDouble(value);
}
}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/aggregation/UDAFAccumulator.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/aggregation/UDAFAccumulator.java
index e9e875205f8..33b99e05947 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/aggregation/UDAFAccumulator.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/execution/aggregation/UDAFAccumulator.java
@@ -22,6 +22,7 @@ package org.apache.iotdb.db.queryengine.execution.aggregation;
import org.apache.iotdb.commons.udf.service.UDFManagementService;
import org.apache.iotdb.commons.udf.utils.UDFDataTypeTransformer;
import org.apache.iotdb.db.queryengine.plan.expression.Expression;
+import org.apache.iotdb.db.queryengine.transformation.dag.udf.UDFParametersFactory;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.file.metadata.statistics.Statistics;
import org.apache.iotdb.tsfile.read.common.block.column.Column;
@@ -93,10 +94,8 @@ public class UDAFAccumulator implements Accumulator {
state = udaf.createState();
final UDFParameters parameters =
- new UDFParameters(
- childExpressions,
- UDFDataTypeTransformer.transformToUDFDataTypeList(childExpressionDataTypes),
- attributes);
+ UDFParametersFactory.buildUdfParameters(
+ childExpressions, childExpressionDataTypes, attributes);
// Only validate for raw input
// There is no need to validate for partial input
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDAFInformationInferrer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDAFInformationInferrer.java
index b268d8ec416..a6d46ee922a 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDAFInformationInferrer.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDAFInformationInferrer.java
@@ -68,10 +68,8 @@ public class UDAFInformationInferrer {
UDAF udaf = (UDAF) UDFManagementService.getInstance().reflect(functionName);
UDFParameters parameters =
- new UDFParameters(
- childExpressions,
- UDFDataTypeTransformer.transformToUDFDataTypeList(childExpressionDataTypes),
- attributes);
+ UDFParametersFactory.buildUdfParameters(
+ childExpressions, childExpressionDataTypes, attributes);
udaf.validate(new UDFParameterValidator(parameters));
// currently UDAF configuration does not need Zone ID
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDFParametersFactory.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDFParametersFactory.java
new file mode 100644
index 00000000000..1225989886a
--- /dev/null
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDFParametersFactory.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.iotdb.db.queryengine.transformation.dag.udf;
+
+import org.apache.iotdb.commons.conf.CommonConfig;
+import org.apache.iotdb.commons.conf.CommonDescriptor;
+import org.apache.iotdb.commons.udf.utils.UDFDataTypeTransformer;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.udf.api.customizer.parameter.UDFParameters;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class UDFParametersFactory {
+
+ private static final CommonConfig CONFIG = CommonDescriptor.getInstance().getConfig();
+
+ public static final String TIMESTAMP_PRECISION = "timestampPrecision";
+
+ public static UDFParameters buildUdfParameters(
+ List<String> childExpressions,
+ List<TSDataType> childExpressionDataTypes,
+ Map<String, String> attributes) {
+ return new UDFParameters(
+ childExpressions,
+ UDFDataTypeTransformer.transformToUDFDataTypeList(childExpressionDataTypes),
+ attributes,
+ buildSystemAttributes());
+ }
+
+ private static Map<String, String> buildSystemAttributes() {
+ Map<String, String> systemAttributes = new HashMap<>();
+ systemAttributes.put(TIMESTAMP_PRECISION, CONFIG.getTimestampPrecision());
+ return systemAttributes;
+ }
+}
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDTFExecutor.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDTFExecutor.java
index 7f7a739a7d8..cb86a4bc5a1 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDTFExecutor.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDTFExecutor.java
@@ -85,10 +85,8 @@ public class UDTFExecutor {
udtf = (UDTF) UDFManagementService.getInstance().reflect(functionName);
final UDFParameters parameters =
- new UDFParameters(
- childExpressions,
- UDFDataTypeTransformer.transformToUDFDataTypeList(childExpressionDataTypes),
- attributes);
+ UDFParametersFactory.buildUdfParameters(
+ childExpressions, childExpressionDataTypes, attributes);
try {
udtf.validate(new UDFParameterValidator(parameters));
diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDTFInformationInferrer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDTFInformationInferrer.java
index 61a8e8c0876..3e054be475b 100644
--- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDTFInformationInferrer.java
+++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/udf/UDTFInformationInferrer.java
@@ -84,12 +84,9 @@ public class UDTFInformationInferrer {
Map<String, String> attributes)
throws Exception {
UDTF udtf = (UDTF) UDFManagementService.getInstance().reflect(functionName);
-
UDFParameters parameters =
- new UDFParameters(
- childExpressions,
- UDFDataTypeTransformer.transformToUDFDataTypeList(childExpressionDataTypes),
- attributes);
+ UDFParametersFactory.buildUdfParameters(
+ childExpressions, childExpressionDataTypes, attributes);
udtf.validate(new UDFParameterValidator(parameters));
// use ZoneId.systemDefault() because UDF's data type is ZoneId independent