This is an automated email from the ASF dual-hosted git repository. rong pushed a commit to branch xianyi in repository https://gitbox.apache.org/repos/asf/iotdb.git
commit 47c0584178a4d52493e66a98293f928e528d9a7c Author: Steve Yurong Su <[email protected]> AuthorDate: Thu Nov 25 17:32:04 2021 +0800 add builtin udf en --- .../main/java/org/apache/iotdb/SessionExample.java | 38 +++++++++------ .../db/query/udf/builtin/BuiltinFunction.java | 2 +- .../apache/iotdb/db/query/udf/builtin/UDTFEn.java | 55 ++++++++++++++++++++++ 3 files changed, 79 insertions(+), 16 deletions(-) diff --git a/example/session/src/main/java/org/apache/iotdb/SessionExample.java b/example/session/src/main/java/org/apache/iotdb/SessionExample.java index f3fc703..2f60361 100644 --- a/example/session/src/main/java/org/apache/iotdb/SessionExample.java +++ b/example/session/src/main/java/org/apache/iotdb/SessionExample.java @@ -70,9 +70,9 @@ public class SessionExample { // createTimeseries(); // createMultiTimeseries(); // insertRecord(); - long start = System.currentTimeMillis(); - insertTablet(); - System.out.println(System.currentTimeMillis() - start); + // long start = System.currentTimeMillis(); + // insertTablet(); + // System.out.println(System.currentTimeMillis() - start); // insertTabletWithNullValues(); // insertTablets(); // insertRecords(); @@ -99,18 +99,26 @@ public class SessionExample { // query4Redirect(); // sessionEnableRedirect.close(); - start = System.currentTimeMillis(); - session.executeNonQueryStatement( - "select s1,s2,s3 into root.sg2.d1.s1,root.sg2.d1.s2,root.sg2.d1.s3" - + " from root.sg1.d1 where time>=2021-11-25T09:22:35.999+08:00 and time <= 2021-12-26T23:09:15.989+08:00"); - System.out.println(System.currentTimeMillis() - start); - - start = System.currentTimeMillis(); - session.executeNonQueryStatement( - "select sin(s1),sin(s2),sin(s3) into root.sg3.d1.s1,root.sg3.d1.s2,root.sg3.d1.s3" - + " from root.sg1.d1 where time>=2021-11-25T09:22:35.999+08:00 and time <= 2021-12-26T23:09:15.989+08:00"); - System.out.println(System.currentTimeMillis() - start); - + // long start = System.currentTimeMillis(); + // session.executeNonQueryStatement( + // "select s1,s2,s3 into root.sg2.d1.s1,root.sg2.d1.s2,root.sg2.d1.s3" + // + " from root.sg1.d1 where time>=2021-11-25T09:22:35.999+08:00 and time <= + // 2021-12-26T23:09:15.989+08:00"); + // System.out.println(System.currentTimeMillis() - start); + + // long start = System.currentTimeMillis(); + // session.executeNonQueryStatement(args[0]); + // "select sin(s1),sin(s2),sin(s3) into root.sg8.d1.s1,root.sg9.d1.s2,root.sg10.d1.s3 + // from root.sg1.d1 where time>=2021-11-25T09:22:35.999+08:00 and time <= + // 2021-12-26T23:09:15.989+08:00"); + // System.out.println(System.currentTimeMillis() - start); + // + // java -cp sql.jar org.apache.iotdb.SessionExample "select s1 into root.t1.d1.s1 from + // root.s1.d1 where time>=2021-11-25T09:22:35.999+08:00 and time <= + // 2021-12-26T23:09:15.989+08:00" + // java -cp sql.jar org.apache.iotdb.SessionExample "select s1,s2,s3 into root.ss1.d1.s1, + // root.ss2.d1.s2, root.ss3.d1.s3 from root.sg1.d1 where time>=2021-11-25T09:22:35.999+08:00 and + // time <= 2021-12-26T23:09:15.989+08:00" session.close(); } diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/BuiltinFunction.java b/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/BuiltinFunction.java index 65ac26e..981b57d 100644 --- a/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/BuiltinFunction.java +++ b/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/BuiltinFunction.java @@ -54,7 +54,7 @@ public enum BuiltinFunction { TOP_K("TOP_K", UDTFTopK.class), BOTTOM_K("BOTTOM_K", UDTFBottomK.class), CAST("CAST", UDTFCast.class), - ; + EN("EN", UDTFEn.class); private final String functionName; private final Class<?> functionClass; diff --git a/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFEn.java b/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFEn.java new file mode 100644 index 0000000..cb624a2 --- /dev/null +++ b/server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFEn.java @@ -0,0 +1,55 @@ +/* + * 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.query.udf.builtin; + +import org.apache.iotdb.db.query.udf.api.UDTF; +import org.apache.iotdb.db.query.udf.api.access.RowWindow; +import org.apache.iotdb.db.query.udf.api.collector.PointCollector; +import org.apache.iotdb.db.query.udf.api.customizer.config.UDTFConfigurations; +import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters; +import org.apache.iotdb.db.query.udf.api.customizer.strategy.SlidingTimeWindowAccessStrategy; +import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; + +import java.io.IOException; + +public class UDTFEn implements UDTF { + + @Override + public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations) { + configurations + .setAccessStrategy(new SlidingTimeWindowAccessStrategy("5m")) + .setOutputDataType(TSDataType.DOUBLE); + } + + @Override + public void transform(RowWindow rowWindow, PointCollector collector) throws IOException { + int windowSize = rowWindow.windowSize(); + if (windowSize != 30000) { + return; + } + + double quadraticSum = 0; + for (int i = 0; i < windowSize; ++i) { + double raw = rowWindow.getRow(i).getDouble(0); + quadraticSum += raw * raw; + } + collector.putDouble(rowWindow.getRow(0).getTime(), quadraticSum / windowSize); + } +}
