This is an automated email from the ASF dual-hosted git repository.

leirui pushed a commit to branch research/M4-visualization
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit b5da3b7640be0a197e5a1d7beaedfd780f548a8d
Author: Lei Rui <[email protected]>
AuthorDate: Tue Jan 24 20:52:24 2023 +0800

    fix
---
 .../dataset/groupby/LocalGroupByExecutor4CPV.java  |  63 ++++++-----
 .../org/apache/iotdb/db/utils/FileLoaderUtils.java |   3 +-
 .../file/metadata/statistics/Statistics.java       | 123 +++++++--------------
 .../file/metadata/statistics/StepRegress.java      |  92 ++++++++-------
 .../statistics/TimeExactOrderStatistics.java       |   7 +-
 5 files changed, 129 insertions(+), 159 deletions(-)

diff --git 
a/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor4CPV.java
 
b/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor4CPV.java
index da129d78ed..545190e8fe 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor4CPV.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/query/dataset/groupby/LocalGroupByExecutor4CPV.java
@@ -19,14 +19,6 @@
 
 package org.apache.iotdb.db.query.dataset.groupby;
 
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.Map;
-import java.util.Set;
 import org.apache.iotdb.db.engine.querycontext.QueryDataSource;
 import org.apache.iotdb.db.exception.StorageEngineException;
 import org.apache.iotdb.db.exception.query.QueryProcessException;
@@ -58,6 +50,15 @@ import org.apache.iotdb.tsfile.read.reader.page.PageReader;
 import org.apache.iotdb.tsfile.utils.Pair;
 import org.apache.iotdb.tsfile.utils.TsPrimitiveType;
 
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.ListIterator;
+import java.util.Map;
+import java.util.Set;
+
 /**
  * Sql format: SELECT min_time(s0), max_time(s0), first_value(s0), 
last_value(s0), min_value(s0),
  * max_value(s0) ROM root.xx group by ([tqs,tqe),IntervalLength). 
Requirements: (1) Don't change the
@@ -82,7 +83,7 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
 
   private TSDataType tsDataType;
 
-//  private PriorityMergeReader mergeReader;
+  //  private PriorityMergeReader mergeReader;
 
   public LocalGroupByExecutor4CPV(
       PartialPath path,
@@ -95,7 +96,7 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
       throws StorageEngineException, QueryProcessException {
 
     this.tsDataType = dataType;
-//    this.mergeReader = new PriorityMergeReader();
+    //    this.mergeReader = new PriorityMergeReader();
 
     // get all data sources
     QueryDataSource queryDataSource =
@@ -200,9 +201,9 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
 
   /**
    * @param curStartTime closed
-   * @param curEndTime   open
-   * @param startTime    closed
-   * @param endTime      open
+   * @param curEndTime open
+   * @param startTime closed
+   * @param endTime open
    */
   @Override
   public List<AggregateResult> calcResult(
@@ -227,9 +228,7 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
     return results;
   }
 
-  /**
-   * 对BatchData应用deletes操作,获得更新的BatchData和statistics赋值到chunkSuit4CPV中
-   */
+  /** 对BatchData应用deletes操作,获得更新的BatchData和statistics赋值到chunkSuit4CPV中 */
   private void updateBatchData(ChunkSuit4CPV chunkSuit4CPV, TSDataType 
dataType) {
     if (chunkSuit4CPV.getBatchData() != null) {
       BatchData batchData1 = BatchDataFactory.createBatchData(dataType, true, 
false);
@@ -326,8 +325,8 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
           new Comparator<ChunkSuit4CPV>() { // TODO double check the sort 
order logic for version
             public int compare(ChunkSuit4CPV o1, ChunkSuit4CPV o2) {
               return new MergeReaderPriority(
-                  o2.getChunkMetadata().getVersion(),
-                  o2.getChunkMetadata().getOffsetOfChunkHeader())
+                      o2.getChunkMetadata().getVersion(),
+                      o2.getChunkMetadata().getOffsetOfChunkHeader())
                   .compareTo(
                       new MergeReaderPriority(
                           o1.getChunkMetadata().getVersion(),
@@ -414,7 +413,7 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
                 .get(4) // TODO check: minTimestamp, maxTimestamp, firstValue, 
lastValue,
                 // minValue[bottomTimestamp], maxValue[topTimestamp]
                 .updateResultUsingValues(
-                    new long[]{candidateTimestamp}, 1, new 
Object[]{candidateValue});
+                    new long[] {candidateTimestamp}, 1, new Object[] 
{candidateValue});
             // TODO check updateResult
             return; // 计算结束
           } else { // 是被overlap,则partial scan所有这些overlap的块
@@ -458,7 +457,7 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
                   .get(4) // TODO check: minTimestamp, maxTimestamp, 
firstValue, lastValue,
                   // minValue[bottomTimestamp], maxValue[topTimestamp]
                   .updateResultUsingValues(
-                      new long[]{candidateTimestamp}, 1, new 
Object[]{candidateValue});
+                      new long[] {candidateTimestamp}, 1, new Object[] 
{candidateValue});
               // TODO check updateResult
               return; // 计算结束
             } else { // 找到这样的点,于是标记candidate point所在块为lazy
@@ -524,8 +523,8 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
           new Comparator<ChunkSuit4CPV>() { // TODO double check the sort 
order logic for version
             public int compare(ChunkSuit4CPV o1, ChunkSuit4CPV o2) {
               return new MergeReaderPriority(
-                  o2.getChunkMetadata().getVersion(),
-                  o2.getChunkMetadata().getOffsetOfChunkHeader())
+                      o2.getChunkMetadata().getVersion(),
+                      o2.getChunkMetadata().getOffsetOfChunkHeader())
                   .compareTo(
                       new MergeReaderPriority(
                           o1.getChunkMetadata().getVersion(),
@@ -612,7 +611,7 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
                 .get(5) // TODO check: minTimestamp, maxTimestamp, firstValue, 
lastValue,
                 // minValue[bottomTimestamp], maxValue[topTimestamp]
                 .updateResultUsingValues(
-                    new long[]{candidateTimestamp}, 1, new 
Object[]{candidateValue});
+                    new long[] {candidateTimestamp}, 1, new Object[] 
{candidateValue});
             // TODO check updateResult
             return; // 计算结束
           } else { // 是被overlap,则partial scan所有这些overlap的块
@@ -656,7 +655,7 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
                   .get(5) // TODO check: minTimestamp, maxTimestamp, 
firstValue, lastValue,
                   // minValue[bottomTimestamp], maxValue[topTimestamp]
                   .updateResultUsingValues(
-                      new long[]{candidateTimestamp}, 1, new 
Object[]{candidateValue});
+                      new long[] {candidateTimestamp}, 1, new Object[] 
{candidateValue});
               // TODO check updateResult
               return; // 计算结束
             } else { // 找到这样的点,于是标记candidate point所在块为lazy
@@ -704,8 +703,8 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
                 return res;
               } else {
                 return new MergeReaderPriority(
-                    o2.getChunkMetadata().getVersion(),
-                    o2.getChunkMetadata().getOffsetOfChunkHeader())
+                        o2.getChunkMetadata().getVersion(),
+                        o2.getChunkMetadata().getOffsetOfChunkHeader())
                     .compareTo(
                         new MergeReaderPriority(
                             o1.getChunkMetadata().getVersion(),
@@ -770,11 +769,11 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
           results
               .get(0)
               .updateResultUsingValues(
-                  new long[]{candidateTimestamp}, 1, new 
Object[]{candidateValue});
+                  new long[] {candidateTimestamp}, 1, new Object[] 
{candidateValue});
           results
               .get(2)
               .updateResultUsingValues(
-                  new long[]{candidateTimestamp}, 1, new 
Object[]{candidateValue});
+                  new long[] {candidateTimestamp}, 1, new Object[] 
{candidateValue});
           return;
         }
       }
@@ -801,8 +800,8 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
                 return res;
               } else {
                 return new MergeReaderPriority(
-                    o2.getChunkMetadata().getVersion(),
-                    o2.getChunkMetadata().getOffsetOfChunkHeader())
+                        o2.getChunkMetadata().getVersion(),
+                        o2.getChunkMetadata().getOffsetOfChunkHeader())
                     .compareTo(
                         new MergeReaderPriority(
                             o1.getChunkMetadata().getVersion(),
@@ -867,11 +866,11 @@ public class LocalGroupByExecutor4CPV implements 
GroupByExecutor {
           results
               .get(1)
               .updateResultUsingValues(
-                  new long[]{candidateTimestamp}, 1, new 
Object[]{candidateValue});
+                  new long[] {candidateTimestamp}, 1, new Object[] 
{candidateValue});
           results
               .get(3)
               .updateResultUsingValues(
-                  new long[]{candidateTimestamp}, 1, new 
Object[]{candidateValue});
+                  new long[] {candidateTimestamp}, 1, new Object[] 
{candidateValue});
           return;
         }
       }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/utils/FileLoaderUtils.java 
b/server/src/main/java/org/apache/iotdb/db/utils/FileLoaderUtils.java
index b871ee2ba2..52c7f8ff9c 100644
--- a/server/src/main/java/org/apache/iotdb/db/utils/FileLoaderUtils.java
+++ b/server/src/main/java/org/apache/iotdb/db/utils/FileLoaderUtils.java
@@ -177,7 +177,8 @@ public class FileLoaderUtils {
       } else {
         Chunk chunk = chunkLoader.loadChunk(chunkMetaData); // loads chunk 
data from disk to memory
         chunk.setFromOldFile(chunkMetaData.isFromOldTsFile());
-        chunkReader = new ChunkReader(chunk, timeFilter); // decompress page 
data, split time&value buffers
+        chunkReader =
+            new ChunkReader(chunk, timeFilter); // decompress page data, split 
time&value buffers
         chunkReader.hasNextSatisfiedPage();
       }
       long duration = System.nanoTime() - start;
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java
index 397fed5e5c..8991e5816d 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/Statistics.java
@@ -18,26 +18,28 @@
  */
 package org.apache.iotdb.tsfile.file.metadata.statistics;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.util.Objects;
 import org.apache.iotdb.tsfile.exception.filter.StatisticsClassException;
 import org.apache.iotdb.tsfile.exception.write.UnknownColumnTypeException;
 import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
 import org.apache.iotdb.tsfile.utils.Binary;
 import org.apache.iotdb.tsfile.utils.ReadWriteForEncodingUtils;
 import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
+
 import org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+
 /**
  * This class is used for recording statistic information of each measurement 
in a delta file. While
  * writing processing, the processor records the statistics information. 
Statistics includes
- * maximum, minimum and null value count up to version 0.0.1.<br> Each data 
type extends this
- * Statistic as super class.<br>
+ * maximum, minimum and null value count up to version 0.0.1.<br>
+ * Each data type extends this Statistic as super class.<br>
  * <br>
  * For the statistics in the Unseq file TimeSeriesMetadata, only firstValue, 
lastValue, startTime
  * and endTime can be used.</br>
@@ -50,9 +52,7 @@ public abstract class Statistics<T> {
    */
   protected boolean isEmpty = true;
 
-  /**
-   * number of time-value points
-   */
+  /** number of time-value points */
   private int count = 0;
 
   private long startTime = Long.MAX_VALUE;
@@ -60,9 +60,7 @@ public abstract class Statistics<T> {
 
   private StepRegress stepRegress = new StepRegress();
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   final String OPERATION_NOT_SUPPORT_FORMAT = "%s statistics does not support 
operation: %s";
 
   /**
@@ -146,37 +144,27 @@ public abstract class Statistics<T> {
 
   abstract int serializeStats(OutputStream outputStream) throws IOException;
 
-  /**
-   * read data from the inputStream.
-   */
+  /** read data from the inputStream. */
   public abstract void deserialize(InputStream inputStream) throws IOException;
 
   public abstract void deserialize(ByteBuffer byteBuffer);
 
   //  public abstract void setMinMaxFromBytes(byte[] minBytes, byte[] 
maxBytes);
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public abstract MinMaxInfo<T> getMinInfo();
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public abstract MinMaxInfo<T> getMaxInfo();
 
   public abstract T getMinValue();
 
   public abstract T getMaxValue();
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public abstract long getBottomTimestamp();
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public abstract long getTopTimestamp();
 
   public abstract T getFirstValue();
@@ -224,7 +212,8 @@ public abstract class Statistics<T> {
       this.count += stats.count;
       mergeStatisticsValue(stats);
       // TODO M4-LSM assumes that there is always only one page in a chunk
-      // TODO M4-LSM if there are more than one chunk in a time series, then 
access each chunkMetadata anyway
+      // TODO M4-LSM if there are more than one chunk in a time series, then 
access each
+      // chunkMetadata anyway
       this.stepRegress = stats.stepRegress;
       isEmpty = false;
     } else {
@@ -248,9 +237,7 @@ public abstract class Statistics<T> {
     updateStepRegress(time);
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public void update(long time, int value) {
     if (time < this.startTime) {
       startTime = time;
@@ -263,9 +250,7 @@ public abstract class Statistics<T> {
     updateStepRegress(time);
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public void update(long time, long value) {
     if (time < this.startTime) {
       startTime = time;
@@ -278,9 +263,7 @@ public abstract class Statistics<T> {
     updateStepRegress(time);
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public void update(long time, float value) {
     if (time < this.startTime) {
       startTime = time;
@@ -293,9 +276,7 @@ public abstract class Statistics<T> {
     updateStepRegress(time);
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public void update(long time, double value) {
     if (time < this.startTime) {
       startTime = time;
@@ -332,9 +313,7 @@ public abstract class Statistics<T> {
     updateStepRegress(time, batchSize);
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public void update(long[] time, int[] values, int batchSize) {
     if (time[0] < startTime) {
       startTime = time[0];
@@ -347,9 +326,7 @@ public abstract class Statistics<T> {
     updateStepRegress(time, batchSize);
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public void update(long[] time, long[] values, int batchSize) {
     if (time[0] < startTime) {
       startTime = time[0];
@@ -362,9 +339,7 @@ public abstract class Statistics<T> {
     updateStepRegress(time, batchSize);
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public void update(long[] time, float[] values, int batchSize) {
     if (time[0] < startTime) {
       startTime = time[0];
@@ -377,9 +352,7 @@ public abstract class Statistics<T> {
     updateStepRegress(time, batchSize);
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public void update(long[] time, double[] values, int batchSize) {
     if (time[0] < startTime) {
       startTime = time[0];
@@ -414,14 +387,10 @@ public abstract class Statistics<T> {
     isEmpty = empty;
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public abstract void updateMinInfo(T val, long timestamp);
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   public abstract void updateMaxInfo(T val, long timestamp);
 
   void updateStats(boolean value) {
@@ -438,30 +407,22 @@ public abstract class Statistics<T> {
     }
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   void updateStats(int value, long timestamp) {
     throw new UnsupportedOperationException();
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   void updateStats(long value, long timestamp) {
     throw new UnsupportedOperationException();
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   void updateStats(float value, long timestamp) {
     throw new UnsupportedOperationException();
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   void updateStats(double value, long timestamp) {
     throw new UnsupportedOperationException();
   }
@@ -474,30 +435,22 @@ public abstract class Statistics<T> {
     throw new UnsupportedOperationException();
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   void updateStats(int[] values, long[] timestamps, int batchSize) {
     throw new UnsupportedOperationException();
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   void updateStats(long[] values, long[] timestamps, int batchSize) {
     throw new UnsupportedOperationException();
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   void updateStats(float[] values, long[] timestamps, int batchSize) {
     throw new UnsupportedOperationException();
   }
 
-  /**
-   * @author Yuyuan Kang
-   */
+  /** @author Yuyuan Kang */
   void updateStats(double[] values, long[] timestamps, int batchSize) {
     throw new UnsupportedOperationException();
   }
@@ -510,7 +463,7 @@ public abstract class Statistics<T> {
    * @param min min timestamp
    * @param max max timestamp
    * @author Yuyuan Kang This method with two parameters is only used by 
{@code unsequence} which
-   * updates/inserts/deletes timestamp.
+   *     updates/inserts/deletes timestamp.
    */
   public void updateStats(long min, long bottomTimestamp, long max, long 
topTimestamp) {
     throw new UnsupportedOperationException();
@@ -539,7 +492,7 @@ public abstract class Statistics<T> {
   }
 
   void deserializeStepRegress(ByteBuffer byteBuffer) {
-    this.stepRegress.setSlope(ReadWriteIOUtils.readDouble(byteBuffer)); //K
+    this.stepRegress.setSlope(ReadWriteIOUtils.readDouble(byteBuffer)); // K
     int m = ReadWriteIOUtils.readInt(byteBuffer); // m
     DoubleArrayList segmentKeys = new DoubleArrayList();
     segmentKeys.add(this.startTime); // t1
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/StepRegress.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/StepRegress.java
index 96d2736fb3..4d70c4b795 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/StepRegress.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/StepRegress.java
@@ -18,12 +18,13 @@
  */
 package org.apache.iotdb.tsfile.file.metadata.statistics;
 
-import java.io.IOException;
-import java.util.Arrays;
 import org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList;
 import org.eclipse.collections.impl.list.mutable.primitive.IntArrayList;
 import org.eclipse.collections.impl.list.mutable.primitive.LongArrayList;
 
+import java.io.IOException;
+import java.util.Arrays;
+
 public class StepRegress {
 
   private double slope;
@@ -89,9 +90,7 @@ public class StepRegress {
     this.segmentIntercepts.add(1 - slope * timestamps.get(0)); // b1
   }
 
-  /**
-   * learn the parameters of the step regression function for the loaded data.
-   */
+  /** learn the parameters of the step regression function for the loaded 
data. */
   public void learn() throws IOException {
     initForLearn();
 
@@ -109,21 +108,26 @@ public class StepRegress {
       int nextPos = i + 2;
 
       // 1) determine the type of the current interval
-      // level condition: big interval && the right endpoint of the interval 
is under the latest tilt line.
+      // level condition: big interval && the right endpoint of the interval 
is under the latest
+      // tilt line.
       // Note the right endpoint, not the left endpoint.
       // "the right endpoint of the interval is under the latest tilt line" is 
to ensure the
-      // monotonically decreasing order of tilt intercepts (the last interval 
running through the last point
+      // monotonically decreasing order of tilt intercepts (the last interval 
running through the
+      // last point
       // is handled using post-processing to avoid disorder of tilt intercepts)
-      boolean isLevel = isBigInterval(delta) && (nextPos < slope * nextT + 
segmentIntercepts.get(
-          tiltLatestSegmentID));
+      boolean isLevel =
+          isBigInterval(delta)
+              && (nextPos < slope * nextT + 
segmentIntercepts.get(tiltLatestSegmentID));
       // to avoid TLTLTLTL... causing trivial segments, add extra rule for tilt
       if (!isLevel) {
         if (previousIntervalType == IntervalType.level) { // when previous 
interval is level
           if (i < intervals.size() - 1) { // when having next interval
             long nextDelta = intervals.get(i + 1);
-            if (isBigInterval(nextDelta) && (nextPos + 1
-                < slope * timestamps.get(i + 2) + segmentIntercepts.get(
-                tiltLatestSegmentID))) { // when next interval is also level
+            if (isBigInterval(nextDelta)
+                && (nextPos + 1
+                    < slope * timestamps.get(i + 2)
+                        + segmentIntercepts.get(
+                            tiltLatestSegmentID))) { // when next interval is 
also level
               isLevel = true; // then fix type from tilt to level, LTL=>LLL
             }
           }
@@ -138,7 +142,8 @@ public class StepRegress {
           previousIntervalType = IntervalType.level;
           // 3) to determine the intercept, let the level function run through 
(t,pos)
           double intercept = pos; // b2i=pos
-          // 4) to determine the segment key, let the level function and the 
previous tilt function intersect
+          // 4) to determine the segment key, let the level function and the 
previous tilt function
+          // intersect
           segmentKeys.add((intercept - segmentIntercepts.getLast()) / slope); 
// x2i=(b2i-b2i-1)/K
           // then add intercept to segmentIntercepts, do not change the order 
of codes here
           segmentIntercepts.add(
@@ -147,12 +152,15 @@ public class StepRegress {
         // deal with the last interval to make sure the last point is hit
         // TODO create examples to debug this
         if (i == intervals.size() - 1) {
-          // 3) to determine the intercept, let the level function run through 
(timestamps.getLast(),timestamps.size())
+          // 3) to determine the intercept, let the level function run through
+          // (timestamps.getLast(),timestamps.size())
           double intercept = timestamps.size(); // b2i=pos
-          // 4) to determine the segment key, let the level function and the 
previous tilt function intersect
+          // 4) to determine the segment key, let the level function and the 
previous tilt function
+          // intersect
           // Note that here is rewrite instead of add.
           // Note taht here is not getLast
-          segmentKeys.set(segmentKeys.size() - 1,
+          segmentKeys.set(
+              segmentKeys.size() - 1,
               (intercept - segmentIntercepts.get(segmentIntercepts.size() - 2))
                   / slope); // x2i=(b2i-b2i-1)/K TODO debug here not getLast!
           // then add intercept to segmentIntercepts, do not change the order 
of codes here
@@ -166,7 +174,8 @@ public class StepRegress {
           previousIntervalType = IntervalType.tilt;
           // 3) to determine the intercept, let the tilt function run through 
(t,pos)
           double intercept = pos - slope * t; // b2i+1=pos-K*t
-          // 4) to determine the segment key, let the level function and the 
previous tilt function intersect
+          // 4) to determine the segment key, let the level function and the 
previous tilt function
+          // intersect
           segmentKeys.add((segmentIntercepts.getLast() - intercept) / slope); 
// x2i+1=(b2i-b2i+1)/K
           // then add intercept to segmentIntercepts, do not change the order 
of codes here
           segmentIntercepts.add(intercept);
@@ -178,19 +187,21 @@ public class StepRegress {
         if (i == intervals.size() - 1) {
           if (segmentIntercepts.size() == 1) { // all TTTTTT, only one segment 
info
             // remove all segment info, and directly connect the first and the 
last point
-            this.slope =
-                (timestamps.size() - 1.0) / (timestamps.getLast() - 
timestamps.getFirst());
+            this.slope = (timestamps.size() - 1.0) / (timestamps.getLast() - 
timestamps.getFirst());
             this.segmentKeys = new DoubleArrayList();
             this.segmentIntercepts = new DoubleArrayList();
             this.segmentKeys.add(timestamps.get(0)); // t1
             this.segmentIntercepts.add(1 - slope * timestamps.get(0)); // b1
           } else {
-            // 3) to determine the intercept, let the tilt function run 
through (timestamps.getLast(),timestamps.size())
+            // 3) to determine the intercept, let the tilt function run through
+            // (timestamps.getLast(),timestamps.size())
             double intercept = timestamps.size() - slope * 
timestamps.getLast(); // b2i+1=pos-K*t
-            // 4) to determine the segment key, let the level function and the 
previous tilt function intersect
+            // 4) to determine the segment key, let the level function and the 
previous tilt
+            // function intersect
             // Note that here is rewrite instead of add.
             // Note taht here is not getLast
-            segmentKeys.set(segmentKeys.size() - 1,
+            segmentKeys.set(
+                segmentKeys.size() - 1,
                 (segmentIntercepts.get(segmentIntercepts.size() - 2) - 
intercept)
                     / slope); // x2i+1=(b2i-b2i+1)/K TODO debug here not 
getLast!
             // then add intercept to segmentIntercepts, do not change the 
order of codes here
@@ -198,7 +209,8 @@ public class StepRegress {
             segmentIntercepts.set(segmentIntercepts.size() - 1, intercept);
 
             // now check to remove possible disorders
-            // search from back to front to find the first tilt intercept that 
is equal to or larger than the current intercept
+            // search from back to front to find the first tilt intercept that 
is equal to or larger
+            // than the current intercept
             int start = segmentIntercepts.size() - 3; // TODO debug
             // TODO consider only one T
             boolean equals = false;
@@ -225,13 +237,16 @@ public class StepRegress {
               if (!equals) {
                 // remove all segment information after start+1 id, i.e., 
remove from start+2~end
                 // note that the level after start tilt is kept since 
equals=false.
-                segmentIntercepts = DoubleArrayList.newListWith(
-                    Arrays.copyOfRange(segmentIntercepts.toArray(), 0, start + 
2));
-                segmentKeys = DoubleArrayList.newListWith(
-                    Arrays.copyOfRange(segmentKeys.toArray(), 0, start + 2));
+                segmentIntercepts =
+                    DoubleArrayList.newListWith(
+                        Arrays.copyOfRange(segmentIntercepts.toArray(), 0, 
start + 2));
+                segmentKeys =
+                    DoubleArrayList.newListWith(
+                        Arrays.copyOfRange(segmentKeys.toArray(), 0, start + 
2));
 
                 // Add new segment info for TL&T
-                // 4) to determine the segment key, let the level function and 
the previous tilt function intersect
+                // 4) to determine the segment key, let the level function and 
the previous tilt
+                // function intersect
                 // Note that here is add and getLast again!
                 segmentKeys.add(
                     (segmentIntercepts.getLast() - intercept) / slope); // 
x2i+1=(b2i-b2i+1)/K
@@ -241,14 +256,17 @@ public class StepRegress {
               } else {
                 // remove all segment information after start id, i.e., remove 
from start+1~end
                 // note that the level after start tilt is NOT kept since 
equal==true
-                segmentIntercepts = DoubleArrayList.newListWith(
-                    Arrays.copyOfRange(segmentIntercepts.toArray(), 0, start + 
1));
-                segmentKeys = DoubleArrayList.newListWith(
-                    Arrays.copyOfRange(segmentKeys.toArray(), 0, start + 1));
+                segmentIntercepts =
+                    DoubleArrayList.newListWith(
+                        Arrays.copyOfRange(segmentIntercepts.toArray(), 0, 
start + 1));
+                segmentKeys =
+                    DoubleArrayList.newListWith(
+                        Arrays.copyOfRange(segmentKeys.toArray(), 0, start + 
1));
                 // TODO debug the first status is level, b1
               }
             }
-            // otherwise start==segmentIntercepts.size()-3 means result is 
already ready, no disorder to handle
+            // otherwise start==segmentIntercepts.size()-3 means result is 
already ready, no
+            // disorder to handle
           }
         }
       }
@@ -340,8 +358,8 @@ public class StepRegress {
    * infer m-1 intercepts b1,b2,...,bm-1 given the slope and m segmentKeys 
t1,t2,...,tm (tm is not
    * used)
    */
-  public static DoubleArrayList inferInterceptsFromSegmentKeys(double slope,
-      DoubleArrayList segmentKeys) {
+  public static DoubleArrayList inferInterceptsFromSegmentKeys(
+      double slope, DoubleArrayList segmentKeys) {
     DoubleArrayList segmentIntercepts = new DoubleArrayList();
     segmentIntercepts.add(1 - slope * segmentKeys.get(0)); // b1=1-K*t1
     for (int i = 1; i < segmentKeys.size() - 1; i++) { // b2,b3,...,bm-1
@@ -363,8 +381,8 @@ public class StepRegress {
   public double infer(double t) throws IOException {
     if (t < segmentKeys.get(0) || t > segmentKeys.getLast()) {
       throw new IOException(
-          String.format("t out of range. input within [%s,%s]", 
segmentKeys.get(0),
-              segmentKeys.getLast()));
+          String.format(
+              "t out of range. input within [%s,%s]", segmentKeys.get(0), 
segmentKeys.getLast()));
     }
     int seg = 0;
     for (; seg < segmentKeys.size() - 1; seg++) {
diff --git 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/TimeExactOrderStatistics.java
 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/TimeExactOrderStatistics.java
index 58e2fa0bf6..768baafb3b 100644
--- 
a/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/TimeExactOrderStatistics.java
+++ 
b/tsfile/src/main/java/org/apache/iotdb/tsfile/file/metadata/statistics/TimeExactOrderStatistics.java
@@ -18,15 +18,14 @@
  */
 package org.apache.iotdb.tsfile.file.metadata.statistics;
 
-import java.util.NoSuchElementException;
 import org.eclipse.collections.impl.list.mutable.primitive.DoubleArrayList;
 import org.eclipse.collections.impl.list.mutable.primitive.FloatArrayList;
 import org.eclipse.collections.impl.list.mutable.primitive.IntArrayList;
 import org.eclipse.collections.impl.list.mutable.primitive.LongArrayList;
 
-/**
- * Util for computing median, MAD, percentile
- */
+import java.util.NoSuchElementException;
+
+/** Util for computing median, MAD, percentile */
 public class TimeExactOrderStatistics {
 
   private LongArrayList longArrayList;

Reply via email to