You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2022/02/28 12:57:18 UTC

[GitHub] [iotdb] flashzxi opened a new pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

flashzxi opened a new pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136


   ## issue 2597
   ### Overview
   Add four function to calculate intervals in which data points always satisfy some specific conditions.
   - zero_duration 
   - non_zero_duration
   - zero_count
   - non_zero_count
   
   ### Details 
   `zero_duration` will take two parameters `min`(default value **0**) and `max`(default value Long.MAX_VALUE),
   It will return intervals' start times and duration times (`end_time - start_time`) in which the value is always 0(false), and the duration time `t` satisfy `t >= min && t <= max`. The unit of `t` is ms.
   
   `non_zeroDuration` is similar to `zero_duration`, only with points always not 0;
   
   `zero_count` will take two parameters `min`(default value **1**) and `max`(default value Long.MAX_VALUE);
   It will return intervals' start times and the number of data points in the interval in which the value is always 0(false), and the number n satisfy `n >= min && n <= max`;
   
   `non_zero_count` is similar
   
   ### example
   ```
   IoTDB> select s1, zero_count(s1) from root.sg.d2;
   +-----------------------------+-------------+-------------------------+
   |                         Time|root.sg.d2.s1|zero_count(root.sg.d2.s1)|
   +-----------------------------+-------------+-------------------------+
   |1970-01-01T08:00:00.000+08:00|            0|                        1|
   |1970-01-01T08:00:00.001+08:00|            1|                     null|
   |1970-01-01T08:00:00.002+08:00|            1|                     null|
   |1970-01-01T08:00:00.003+08:00|            0|                        1|
   |1970-01-01T08:00:00.004+08:00|            1|                     null|
   |1970-01-01T08:00:00.005+08:00|            0|                        2|
   |1970-01-01T08:00:00.006+08:00|            0|                     null|
   |1970-01-01T08:00:00.007+08:00|            1|                     null|
   +-----------------------------+-------------+-------------------------+
   
   ```


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#issuecomment-1054329512


   Please resolve the conflict :)


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#issuecomment-1054292868


   
   [![Coverage Status](https://coveralls.io/builds/46957603/badge)](https://coveralls.io/builds/46957603)
   
   Coverage decreased (-0.02%) to 67.73% when pulling **52ec5aa7d912592331a2325b723d403317a097dc on flashzxi:issue2597** into **9d33535d23fbb98b6c41e7eaa52a7bc2e81b435e on apache:master**.
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#issuecomment-1054292868


   
   [![Coverage Status](https://coveralls.io/builds/47037836/badge)](https://coveralls.io/builds/47037836)
   
   Coverage decreased (-0.09%) to 67.656% when pulling **7b4011b4bc3f7519f8a6a4c72a6eeaab92cd27db on flashzxi:issue2597** into **9d33535d23fbb98b6c41e7eaa52a7bc2e81b435e on apache:master**.
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#issuecomment-1054292868


   
   [![Coverage Status](https://coveralls.io/builds/47005685/badge)](https://coveralls.io/builds/47005685)
   
   Coverage decreased (-0.01%) to 67.732% when pulling **b71eb9cbc5e625fc59ca165fdf1019f709165016 on flashzxi:issue2597** into **9d33535d23fbb98b6c41e7eaa52a7bc2e81b435e on apache:master**.
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#issuecomment-1054292868


   
   [![Coverage Status](https://coveralls.io/builds/46956279/badge)](https://coveralls.io/builds/46956279)
   
   Coverage increased (+0.009%) to 67.736% when pulling **4249662b033ed774c4c795d04fe6bb34c244c64d on flashzxi:issue2597** into **e44835f0b60ad7c360f87125a2ad4e63f383b250 on apache:master**.
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#discussion_r817320728



##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.exception.metadata.MetadataException;
+import org.apache.iotdb.db.query.udf.api.UDTF;
+import org.apache.iotdb.db.query.udf.api.access.Row;
+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.UDFParameterValidator;
+import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.db.query.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.db.query.udf.api.exception.UDFException;
+import org.apache.iotdb.db.query.udf.api.exception.UDFInputSeriesDataTypeNotValidException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public abstract class UDTFContinuouslySatisfy implements UDTF {
+  protected Long min;
+  protected Long max;
+  protected Long defaultMax = Long.MAX_VALUE;
+  protected Long defaultMin = 0L;
+  protected TSDataType dataType;
+  protected Long satisfyValueCount;
+  protected Long satisfyValueLastTime;
+  protected Long satisfyValueStartTime;
+
+  @Override
+  public void validate(UDFParameterValidator validator) throws UDFException {
+    setDefaultValue();
+    validator
+        .validateInputSeriesNumber(1)
+        .validateInputSeriesDataType(
+            0,
+            TSDataType.INT32,
+            TSDataType.INT64,
+            TSDataType.FLOAT,
+            TSDataType.DOUBLE,
+            TSDataType.BOOLEAN)
+        .validate(
+            args -> (Long) args[1] >= (Long) args[0],
+            "max can not be smaller than min.",
+            validator.getParameters().getLongOrDefault("min", defaultMin),
+            validator.getParameters().getLongOrDefault("max", defaultMax))
+        .validate(
+            min -> (Long) min >= defaultMin,
+            "min can not be smaller than " + defaultMin + ".",
+            validator.getParameters().getLongOrDefault("min", defaultMin));
+  }
+
+  protected abstract void setDefaultValue();
+
+  protected void setDefaultMax(Long defaultMax) {
+    this.defaultMax = defaultMax;
+  }
+
+  protected void setDefaultMin(Long defaultMin) {
+    this.defaultMin = defaultMin;
+  }
+
+  @Override
+  public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations)
+      throws MetadataException, UDFInputSeriesDataTypeNotValidException {
+    satisfyValueCount = 0L;
+    satisfyValueStartTime = 0L;
+    satisfyValueLastTime = -1L;
+    intervals = new ArrayList<>(0);
+
+    dataType = parameters.getDataType(0);
+    min = parameters.getLongOrDefault("min", defaultMin);
+    max = parameters.getLongOrDefault("max", defaultMax);
+    configurations
+        .setAccessStrategy(new RowByRowAccessStrategy())
+        .setOutputDataType(TSDataType.INT64);
+  }
+
+  @Override
+  public void transform(Row row, PointCollector collector)
+      throws IOException, UDFInputSeriesDataTypeNotValidException {
+    switch (dataType) {
+      case INT32:
+        transformInt(row.getTime(), row.getInt(0));
+        break;
+      case INT64:
+        transformLong(row.getTime(), row.getLong(0));
+        break;
+      case FLOAT:
+        transformFloat(row.getTime(), row.getFloat(0));
+        break;
+      case DOUBLE:
+        transformDouble(row.getTime(), row.getDouble(0));
+        break;
+      case BOOLEAN:
+        transformBoolean(row.getTime(), row.getBoolean(0));
+        break;
+      default:
+        // This will not happen
+        throw new UDFInputSeriesDataTypeNotValidException(
+            0, dataType, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE);
+    }
+  }
+
+  protected void transformDouble(long time, double value) {
+    if (satisfyDouble(value) && satisfyValueCount == 0L) {
+      satisfyValueCount++;
+      satisfyValueStartTime = time;
+      satisfyValueLastTime = time;
+    } else if (satisfyDouble(value)) {
+      satisfyValueCount++;
+      satisfyValueLastTime = time;
+    } else {
+      if (getRecord() >= min && getRecord() <= max && satisfyValueCount > 0) {
+        intervals.add(new Pair<>(satisfyValueStartTime, getRecord()));

Review comment:
       Yes, we do memory control in PointCollector.




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] flashzxi commented on a change in pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
flashzxi commented on a change in pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#discussion_r817341437



##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.exception.metadata.MetadataException;
+import org.apache.iotdb.db.query.udf.api.UDTF;
+import org.apache.iotdb.db.query.udf.api.access.Row;
+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.UDFParameterValidator;
+import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.db.query.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.db.query.udf.api.exception.UDFException;
+import org.apache.iotdb.db.query.udf.api.exception.UDFInputSeriesDataTypeNotValidException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public abstract class UDTFContinuouslySatisfy implements UDTF {
+  protected Long min;
+  protected Long max;
+  protected Long defaultMax = Long.MAX_VALUE;
+  protected Long defaultMin = 0L;

Review comment:
       The problem is defaultMin is different in zero_duration and zero_count. For example, if 0 appeared only once, the duration will be 0 meanwhile count will 1. So defaultMax may be redundant but not defaultMin.
   But i can delete them and use two abstract method to get the default values.




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#discussion_r817752879



##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -0,0 +1,243 @@
+/*
+ * 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.exception.metadata.MetadataException;
+import org.apache.iotdb.db.query.udf.api.UDTF;
+import org.apache.iotdb.db.query.udf.api.access.Row;
+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.UDFParameterValidator;
+import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.db.query.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.db.query.udf.api.exception.UDFException;
+import org.apache.iotdb.db.query.udf.api.exception.UDFInputSeriesDataTypeNotValidException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.io.IOException;
+
+public abstract class UDTFContinuouslySatisfy implements UDTF {
+  protected long min;
+  protected long max;
+  protected TSDataType dataType;
+  protected long satisfyValueCount;
+  protected long satisfyValueLastTime;
+  protected long satisfyValueStartTime;
+  protected Pair<Long, Long> interval;
+
+  @Override
+  public void validate(UDFParameterValidator validator) throws UDFException {
+    validator
+        .validateInputSeriesNumber(1)
+        .validateInputSeriesDataType(
+            0,
+            TSDataType.INT32,
+            TSDataType.INT64,
+            TSDataType.FLOAT,
+            TSDataType.DOUBLE,
+            TSDataType.BOOLEAN)
+        .validate(
+            args -> (Long) args[1] >= (Long) args[0],
+            "max can not be smaller than min.",
+            validator.getParameters().getLongOrDefault("min", getDefaultMin()),
+            validator.getParameters().getLongOrDefault("max", getDefaultMax()))
+        .validate(
+            min -> (Long) min >= getDefaultMin(),
+            "min can not be smaller than " + getDefaultMin() + ".",
+            validator.getParameters().getLongOrDefault("min", getDefaultMin()));
+  }
+
+  protected abstract long getDefaultMin();
+
+  protected abstract long getDefaultMax();
+
+  @Override
+  public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations)
+      throws MetadataException, UDFInputSeriesDataTypeNotValidException {
+    satisfyValueCount = 0L;
+    satisfyValueStartTime = 0L;
+    satisfyValueLastTime = -1L;
+
+    dataType = parameters.getDataType(0);
+    min = parameters.getLongOrDefault("min", getDefaultMin());
+    max = parameters.getLongOrDefault("max", getDefaultMax());
+    configurations
+        .setAccessStrategy(new RowByRowAccessStrategy())
+        .setOutputDataType(TSDataType.INT64);
+  }
+
+  @Override
+  public void transform(Row row, PointCollector collector)
+      throws IOException, UDFInputSeriesDataTypeNotValidException {
+    boolean needAddNewRecord;
+    switch (dataType) {
+      case INT32:
+        needAddNewRecord = transformInt(row.getTime(), row.getInt(0));
+        break;
+      case INT64:
+        needAddNewRecord = transformLong(row.getTime(), row.getLong(0));
+        break;
+      case FLOAT:
+        needAddNewRecord = transformFloat(row.getTime(), row.getFloat(0));
+        break;
+      case DOUBLE:
+        needAddNewRecord = transformDouble(row.getTime(), row.getDouble(0));
+        break;
+      case BOOLEAN:
+        needAddNewRecord = transformBoolean(row.getTime(), row.getBoolean(0));
+        break;
+      default:
+        // This will not happen
+        throw new UDFInputSeriesDataTypeNotValidException(
+            0, dataType, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE);
+    }
+    if (needAddNewRecord) collector.putLong(interval.left, interval.right);

Review comment:
       Please add the {} here.

##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -0,0 +1,243 @@
+/*
+ * 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.exception.metadata.MetadataException;
+import org.apache.iotdb.db.query.udf.api.UDTF;
+import org.apache.iotdb.db.query.udf.api.access.Row;
+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.UDFParameterValidator;
+import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.db.query.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.db.query.udf.api.exception.UDFException;
+import org.apache.iotdb.db.query.udf.api.exception.UDFInputSeriesDataTypeNotValidException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.io.IOException;
+
+public abstract class UDTFContinuouslySatisfy implements UDTF {
+  protected long min;
+  protected long max;
+  protected TSDataType dataType;
+  protected long satisfyValueCount;
+  protected long satisfyValueLastTime;
+  protected long satisfyValueStartTime;
+  protected Pair<Long, Long> interval;
+
+  @Override
+  public void validate(UDFParameterValidator validator) throws UDFException {
+    validator
+        .validateInputSeriesNumber(1)
+        .validateInputSeriesDataType(
+            0,
+            TSDataType.INT32,
+            TSDataType.INT64,
+            TSDataType.FLOAT,
+            TSDataType.DOUBLE,
+            TSDataType.BOOLEAN)
+        .validate(
+            args -> (Long) args[1] >= (Long) args[0],
+            "max can not be smaller than min.",
+            validator.getParameters().getLongOrDefault("min", getDefaultMin()),
+            validator.getParameters().getLongOrDefault("max", getDefaultMax()))
+        .validate(
+            min -> (Long) min >= getDefaultMin(),
+            "min can not be smaller than " + getDefaultMin() + ".",
+            validator.getParameters().getLongOrDefault("min", getDefaultMin()));
+  }
+
+  protected abstract long getDefaultMin();
+
+  protected abstract long getDefaultMax();
+
+  @Override
+  public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations)
+      throws MetadataException, UDFInputSeriesDataTypeNotValidException {
+    satisfyValueCount = 0L;
+    satisfyValueStartTime = 0L;
+    satisfyValueLastTime = -1L;
+
+    dataType = parameters.getDataType(0);
+    min = parameters.getLongOrDefault("min", getDefaultMin());
+    max = parameters.getLongOrDefault("max", getDefaultMax());
+    configurations
+        .setAccessStrategy(new RowByRowAccessStrategy())
+        .setOutputDataType(TSDataType.INT64);
+  }
+
+  @Override
+  public void transform(Row row, PointCollector collector)
+      throws IOException, UDFInputSeriesDataTypeNotValidException {
+    boolean needAddNewRecord;
+    switch (dataType) {
+      case INT32:
+        needAddNewRecord = transformInt(row.getTime(), row.getInt(0));
+        break;
+      case INT64:
+        needAddNewRecord = transformLong(row.getTime(), row.getLong(0));
+        break;
+      case FLOAT:
+        needAddNewRecord = transformFloat(row.getTime(), row.getFloat(0));
+        break;
+      case DOUBLE:
+        needAddNewRecord = transformDouble(row.getTime(), row.getDouble(0));
+        break;
+      case BOOLEAN:
+        needAddNewRecord = transformBoolean(row.getTime(), row.getBoolean(0));
+        break;
+      default:
+        // This will not happen
+        throw new UDFInputSeriesDataTypeNotValidException(
+            0, dataType, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE);
+    }
+    if (needAddNewRecord) collector.putLong(interval.left, interval.right);
+  }
+
+  protected boolean transformDouble(long time, double value) {
+    if (satisfyDouble(value) && satisfyValueCount == 0L) {

Review comment:
       Try to do the judge satisfyDouble only once.

##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -0,0 +1,243 @@
+/*
+ * 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.exception.metadata.MetadataException;
+import org.apache.iotdb.db.query.udf.api.UDTF;
+import org.apache.iotdb.db.query.udf.api.access.Row;
+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.UDFParameterValidator;
+import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.db.query.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.db.query.udf.api.exception.UDFException;
+import org.apache.iotdb.db.query.udf.api.exception.UDFInputSeriesDataTypeNotValidException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.io.IOException;
+
+public abstract class UDTFContinuouslySatisfy implements UDTF {
+  protected long min;
+  protected long max;
+  protected TSDataType dataType;
+  protected long satisfyValueCount;
+  protected long satisfyValueLastTime;
+  protected long satisfyValueStartTime;
+  protected Pair<Long, Long> interval;
+
+  @Override
+  public void validate(UDFParameterValidator validator) throws UDFException {
+    validator
+        .validateInputSeriesNumber(1)
+        .validateInputSeriesDataType(
+            0,
+            TSDataType.INT32,
+            TSDataType.INT64,
+            TSDataType.FLOAT,
+            TSDataType.DOUBLE,
+            TSDataType.BOOLEAN)
+        .validate(
+            args -> (Long) args[1] >= (Long) args[0],
+            "max can not be smaller than min.",
+            validator.getParameters().getLongOrDefault("min", getDefaultMin()),
+            validator.getParameters().getLongOrDefault("max", getDefaultMax()))
+        .validate(
+            min -> (Long) min >= getDefaultMin(),
+            "min can not be smaller than " + getDefaultMin() + ".",
+            validator.getParameters().getLongOrDefault("min", getDefaultMin()));
+  }
+
+  protected abstract long getDefaultMin();
+
+  protected abstract long getDefaultMax();
+
+  @Override
+  public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations)
+      throws MetadataException, UDFInputSeriesDataTypeNotValidException {
+    satisfyValueCount = 0L;
+    satisfyValueStartTime = 0L;
+    satisfyValueLastTime = -1L;
+
+    dataType = parameters.getDataType(0);
+    min = parameters.getLongOrDefault("min", getDefaultMin());
+    max = parameters.getLongOrDefault("max", getDefaultMax());
+    configurations
+        .setAccessStrategy(new RowByRowAccessStrategy())
+        .setOutputDataType(TSDataType.INT64);
+  }
+
+  @Override
+  public void transform(Row row, PointCollector collector)
+      throws IOException, UDFInputSeriesDataTypeNotValidException {
+    boolean needAddNewRecord;
+    switch (dataType) {
+      case INT32:
+        needAddNewRecord = transformInt(row.getTime(), row.getInt(0));
+        break;
+      case INT64:
+        needAddNewRecord = transformLong(row.getTime(), row.getLong(0));
+        break;
+      case FLOAT:
+        needAddNewRecord = transformFloat(row.getTime(), row.getFloat(0));
+        break;
+      case DOUBLE:
+        needAddNewRecord = transformDouble(row.getTime(), row.getDouble(0));
+        break;
+      case BOOLEAN:
+        needAddNewRecord = transformBoolean(row.getTime(), row.getBoolean(0));
+        break;
+      default:
+        // This will not happen
+        throw new UDFInputSeriesDataTypeNotValidException(
+            0, dataType, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE);
+    }
+    if (needAddNewRecord) collector.putLong(interval.left, interval.right);
+  }
+
+  protected boolean transformDouble(long time, double value) {
+    if (satisfyDouble(value) && satisfyValueCount == 0L) {
+      satisfyValueCount++;
+      satisfyValueStartTime = time;
+      satisfyValueLastTime = time;
+    } else if (satisfyDouble(value)) {
+      satisfyValueCount++;
+      satisfyValueLastTime = time;
+    } else {
+      if (getRecord() >= min && getRecord() <= max && satisfyValueCount > 0) {
+        interval = new Pair<>(satisfyValueStartTime, getRecord());
+        satisfyValueCount = 0L;
+        return true;
+      }
+      satisfyValueCount = 0L;
+    }
+    return false;
+  }
+
+  protected boolean transformFloat(long time, float value) {
+    if (satisfyFloat(value) && satisfyValueCount == 0L) {
+      satisfyValueCount++;
+      satisfyValueStartTime = time;
+      satisfyValueLastTime = time;
+    } else if (satisfyFloat(value)) {
+      satisfyValueCount++;
+      satisfyValueLastTime = time;
+    } else {
+      if (getRecord() >= min && getRecord() <= max && satisfyValueCount > 0) {
+        interval = new Pair<>(satisfyValueStartTime, getRecord());
+        satisfyValueCount = 0L;
+        return true;
+      }
+      satisfyValueCount = 0L;
+    }
+    return false;
+  }
+
+  protected boolean transformLong(long time, long value) {
+    if (satisfyLong(value) && satisfyValueCount == 0L) {
+      satisfyValueCount++;
+      satisfyValueStartTime = time;
+      satisfyValueLastTime = time;
+    } else if (satisfyLong(value)) {
+      satisfyValueCount++;
+      satisfyValueLastTime = time;
+    } else {
+      if (getRecord() >= min && getRecord() <= max && satisfyValueCount > 0) {
+        interval = new Pair<>(satisfyValueStartTime, getRecord());
+        satisfyValueCount = 0L;
+        return true;
+      }
+      satisfyValueCount = 0L;
+    }
+    return false;
+  }
+
+  protected boolean transformInt(long time, int value) {
+    if (satisfyInt(value) && satisfyValueCount == 0L) {
+      satisfyValueCount++;
+      satisfyValueStartTime = time;
+      satisfyValueLastTime = time;
+    } else if (satisfyInt(value)) {
+      satisfyValueCount++;
+      satisfyValueLastTime = time;
+    } else {
+      if (getRecord() >= min && getRecord() <= max && satisfyValueCount > 0) {
+        interval = new Pair<>(satisfyValueStartTime, getRecord());
+        satisfyValueCount = 0L;
+        return true;
+      }
+      satisfyValueCount = 0L;
+    }
+    return false;
+  }
+
+  protected boolean transformBoolean(long time, boolean value) {
+    if (satisfyBoolean(value) && satisfyValueCount == 0L) {
+      satisfyValueCount++;
+      satisfyValueStartTime = time;
+      satisfyValueLastTime = time;
+    } else if (satisfyBoolean(value)) {
+      satisfyValueCount++;
+      satisfyValueLastTime = time;
+    } else {
+      if (getRecord() >= min && getRecord() <= max && satisfyValueCount > 0) {
+        interval = new Pair<>(satisfyValueStartTime, getRecord());
+        satisfyValueCount = 0L;
+        return true;
+      }
+      satisfyValueCount = 0L;
+    }
+    return false;
+  }
+
+  protected abstract Long getRecord();
+

Review comment:
       Please explain the meaning of record by add some comments here.




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls commented on pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
coveralls commented on pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#issuecomment-1054292868


   
   [![Coverage Status](https://coveralls.io/builds/46933160/badge)](https://coveralls.io/builds/46933160)
   
   Coverage decreased (-0.01%) to 67.713% when pulling **d902c7a8fdf63f341f8e59e989a6b791d5ff802e on flashzxi:issue2597** into **e44835f0b60ad7c360f87125a2ad4e63f383b250 on apache:master**.
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#issuecomment-1054292868


   
   [![Coverage Status](https://coveralls.io/builds/46935651/badge)](https://coveralls.io/builds/46935651)
   
   Coverage decreased (-0.03%) to 67.699% when pulling **24fc85ff0d9ca709d057d2a15b6f8610697dc0f1 on flashzxi:issue2597** into **e44835f0b60ad7c360f87125a2ad4e63f383b250 on apache:master**.
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#discussion_r817316545



##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.exception.metadata.MetadataException;
+import org.apache.iotdb.db.query.udf.api.UDTF;
+import org.apache.iotdb.db.query.udf.api.access.Row;
+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.UDFParameterValidator;
+import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.db.query.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.db.query.udf.api.exception.UDFException;
+import org.apache.iotdb.db.query.udf.api.exception.UDFInputSeriesDataTypeNotValidException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public abstract class UDTFContinuouslySatisfy implements UDTF {
+  protected Long min;
+  protected Long max;
+  protected Long defaultMax = Long.MAX_VALUE;
+  protected Long defaultMin = 0L;

Review comment:
       These 2 fields can be static final. And... Does it seem that we can merge min(max) and defaultMin(defaultMax) into 1 field?

##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.exception.metadata.MetadataException;
+import org.apache.iotdb.db.query.udf.api.UDTF;
+import org.apache.iotdb.db.query.udf.api.access.Row;
+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.UDFParameterValidator;
+import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.db.query.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.db.query.udf.api.exception.UDFException;
+import org.apache.iotdb.db.query.udf.api.exception.UDFInputSeriesDataTypeNotValidException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public abstract class UDTFContinuouslySatisfy implements UDTF {
+  protected Long min;
+  protected Long max;
+  protected Long defaultMax = Long.MAX_VALUE;
+  protected Long defaultMin = 0L;
+  protected TSDataType dataType;
+  protected Long satisfyValueCount;
+  protected Long satisfyValueLastTime;
+  protected Long satisfyValueStartTime;
+
+  @Override
+  public void validate(UDFParameterValidator validator) throws UDFException {
+    setDefaultValue();
+    validator
+        .validateInputSeriesNumber(1)
+        .validateInputSeriesDataType(
+            0,
+            TSDataType.INT32,
+            TSDataType.INT64,
+            TSDataType.FLOAT,
+            TSDataType.DOUBLE,
+            TSDataType.BOOLEAN)
+        .validate(
+            args -> (Long) args[1] >= (Long) args[0],
+            "max can not be smaller than min.",
+            validator.getParameters().getLongOrDefault("min", defaultMin),
+            validator.getParameters().getLongOrDefault("max", defaultMax))
+        .validate(
+            min -> (Long) min >= defaultMin,
+            "min can not be smaller than " + defaultMin + ".",
+            validator.getParameters().getLongOrDefault("min", defaultMin));
+  }
+
+  protected abstract void setDefaultValue();
+
+  protected void setDefaultMax(Long defaultMax) {
+    this.defaultMax = defaultMax;
+  }
+
+  protected void setDefaultMin(Long defaultMin) {
+    this.defaultMin = defaultMin;
+  }
+
+  @Override
+  public void beforeStart(UDFParameters parameters, UDTFConfigurations configurations)
+      throws MetadataException, UDFInputSeriesDataTypeNotValidException {
+    satisfyValueCount = 0L;
+    satisfyValueStartTime = 0L;
+    satisfyValueLastTime = -1L;
+    intervals = new ArrayList<>(0);
+
+    dataType = parameters.getDataType(0);
+    min = parameters.getLongOrDefault("min", defaultMin);
+    max = parameters.getLongOrDefault("max", defaultMax);
+    configurations
+        .setAccessStrategy(new RowByRowAccessStrategy())
+        .setOutputDataType(TSDataType.INT64);
+  }
+
+  @Override
+  public void transform(Row row, PointCollector collector)
+      throws IOException, UDFInputSeriesDataTypeNotValidException {
+    switch (dataType) {
+      case INT32:
+        transformInt(row.getTime(), row.getInt(0));
+        break;
+      case INT64:
+        transformLong(row.getTime(), row.getLong(0));
+        break;
+      case FLOAT:
+        transformFloat(row.getTime(), row.getFloat(0));
+        break;
+      case DOUBLE:
+        transformDouble(row.getTime(), row.getDouble(0));
+        break;
+      case BOOLEAN:
+        transformBoolean(row.getTime(), row.getBoolean(0));
+        break;
+      default:
+        // This will not happen
+        throw new UDFInputSeriesDataTypeNotValidException(
+            0, dataType, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE);
+    }
+  }
+
+  protected void transformDouble(long time, double value) {
+    if (satisfyDouble(value) && satisfyValueCount == 0L) {
+      satisfyValueCount++;
+      satisfyValueStartTime = time;
+      satisfyValueLastTime = time;
+    } else if (satisfyDouble(value)) {
+      satisfyValueCount++;
+      satisfyValueLastTime = time;
+    } else {
+      if (getRecord() >= min && getRecord() <= max && satisfyValueCount > 0) {
+        intervals.add(new Pair<>(satisfyValueStartTime, getRecord()));

Review comment:
       Try to output the result to PointCollector here. It's not recommended to keep all results in memory, because there is a risk to cause OOM.

##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -0,0 +1,240 @@
+/*
+ * 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.exception.metadata.MetadataException;
+import org.apache.iotdb.db.query.udf.api.UDTF;
+import org.apache.iotdb.db.query.udf.api.access.Row;
+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.UDFParameterValidator;
+import org.apache.iotdb.db.query.udf.api.customizer.parameter.UDFParameters;
+import org.apache.iotdb.db.query.udf.api.customizer.strategy.RowByRowAccessStrategy;
+import org.apache.iotdb.db.query.udf.api.exception.UDFException;
+import org.apache.iotdb.db.query.udf.api.exception.UDFInputSeriesDataTypeNotValidException;
+import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
+import org.apache.iotdb.tsfile.utils.Pair;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
+public abstract class UDTFContinuouslySatisfy implements UDTF {
+  protected Long min;
+  protected Long max;

Review comment:
       For better performance, always try your best to use `long` instead of `Long`. 




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu commented on a change in pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
SteveYurongSu commented on a change in pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#discussion_r818747134



##########
File path: server/src/main/java/org/apache/iotdb/db/query/udf/builtin/UDTFContinuouslySatisfy.java
##########
@@ -109,104 +109,115 @@ public void transform(Row row, PointCollector collector)
         throw new UDFInputSeriesDataTypeNotValidException(
             0, dataType, TSDataType.INT32, TSDataType.INT64, TSDataType.FLOAT, TSDataType.DOUBLE);
     }
-    if (needAddNewRecord) collector.putLong(interval.left, interval.right);
+    if (needAddNewRecord) {
+      collector.putLong(interval.left, interval.right);
+    }
   }
 
   protected boolean transformDouble(long time, double value) {
-    if (satisfyDouble(value) && satisfyValueCount == 0L) {
-      satisfyValueCount++;
-      satisfyValueStartTime = time;
-      satisfyValueLastTime = time;
-    } else if (satisfyDouble(value)) {
-      satisfyValueCount++;
-      satisfyValueLastTime = time;
-    } else {
-      if (getRecord() >= min && getRecord() <= max && satisfyValueCount > 0) {
-        interval = new Pair<>(satisfyValueStartTime, getRecord());
-        satisfyValueCount = 0L;
-        return true;
+    if (satisfyDouble(value)) {
+      if (satisfyValueCount == 0L) {
+        satisfyValueCount++;
+        satisfyValueStartTime = time;
+        satisfyValueLastTime = time;
+      } else {
+        satisfyValueCount++;
+        satisfyValueLastTime = time;

Review comment:
       These 2 lines can be moved out of the if else




-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] coveralls edited a comment on pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
coveralls edited a comment on pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136#issuecomment-1054292868


   
   [![Coverage Status](https://coveralls.io/builds/47072036/badge)](https://coveralls.io/builds/47072036)
   
   Coverage decreased (-0.1%) to 67.638% when pulling **2bb7f9f50355abd2bc521dd13380fec4cb2ea556 on flashzxi:issue2597** into **9d33535d23fbb98b6c41e7eaa52a7bc2e81b435e on apache:master**.
   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [iotdb] SteveYurongSu merged pull request #5136: [IOTDB-2597] Add four functions to find suitable intervals

Posted by GitBox <gi...@apache.org>.
SteveYurongSu merged pull request #5136:
URL: https://github.com/apache/iotdb/pull/5136


   


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org