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/03 16:56:11 UTC

[GitHub] [iotdb] huangyuxiang03 opened a new pull request #5010: Add encoding algorithms: RLBE, RAKE and SPRINTZ

huangyuxiang03 opened a new pull request #5010:
URL: https://github.com/apache/iotdb/pull/5010


   ## Description
   We add encoding algorithms: RLBE, RAKE and SPRINTZ to IoTDB. This work is supported by SRT 2022.
   
   ### Content1 ...
   Encoding classes are added and updated. We create new classes: RLBE, SprintzEncoder and RAKEEncoder extends the class Encoder. Subclasses of handling different datatype extend the three new encoding classes.
   ### Content2 ...
   Decoding classes are added and updated. We create new classes to decode RLBE, RAKE and Sprintz code words, and subclasses of handling different datatype extend the decode classes are also created.
   ### Content3 ...
   TSEncoding class is updated to support new encoding algorithms, SQL lexical analyse parts are also updated to support new encoding algorithms.
   
   <!--
   In each section, please describe design decisions made, including:
    - Choice of algorithms
    - Behavioral aspects. What configuration values are acceptable? How are corner cases and error 
       conditions handled, such as when there are insufficient resources?
    - Class organization and design (how the logic is split between classes, inheritance, composition, 
       design patterns)
    - Method organization and design (how the logic is split between methods, parameters and return types)
    - Naming (class, method, API, configuration, HTTP endpoint, names of emitted metrics)
   -->
   
   
   <!-- It's good to describe an alternative design (or mention an alternative name) for every design 
   (or naming) decision point and compare the alternatives with the designs that you've implemented 
   (or the names you've chosen) to highlight the advantages of the chosen designs and names. -->
   
   <!-- If there was a discussion of the design of the feature implemented in this PR elsewhere 
   (e. g. a "Proposal" issue, any other issue, or a thread in the development mailing list), 
   link to that discussion from this PR description and explain what have changed in your final design 
   compared to your original proposal or the consensus version in the end of the discussion. 
   If something hasn't changed since the original discussion, you can omit a detailed discussion of 
   those aspects of the design here, perhaps apart from brief mentioning for the sake of readability 
   of this PR description. -->
   
   <!-- Some of the aspects mentioned above may be omitted for simple and small changes. -->
   
   <hr>
   
   This PR has:
   - [x] been self-reviewed.
       - [ ] concurrent read
       - [ ] concurrent write
       - [ ] concurrent read and write 
   - [x] added documentation for new or modified features or behaviors.
   - [ ] added Javadocs for most classes and all non-trivial methods. 
   - [x] added or updated version, __license__, or notice information
   - [x] added comments explaining the "why" and the intent of the code wherever would not be obvious 
     for an unfamiliar reader.
   - [x] added unit tests or modified existing tests to cover new code paths, ensuring the threshold 
     for code coverage.
   - [ ] added integration tests.
   - [ ] been tested in a test IoTDB cluster.
   
   <!-- Check the items by putting "x" in the brackets for the done things. Not all of these items 
   apply to every PR. Remove the items which are not done or not relevant to the PR. None of the items 
   from the checklist above are strictly necessary, but it would be very helpful if you at least 
   self-review the PR. -->
   
   <hr>
   
   ##### Key changed/added classes (or packages if there are too many classes) in this PR
   


-- 
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] huangyuxiang03 closed pull request #5010: Add encoding algorithms: RLBE, RAKE and SPRINTZ

Posted by GitBox <gi...@apache.org>.
huangyuxiang03 closed pull request #5010:
URL: https://github.com/apache/iotdb/pull/5010


   


-- 
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 #5010: Add encoding algorithms: RLBE, RAKE and SPRINTZ

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


   
   [![Coverage Status](https://coveralls.io/builds/46208047/badge)](https://coveralls.io/builds/46208047)
   
   Coverage decreased (-0.004%) to 67.688% when pulling **1b1e98253e22093e781c01214e4c2dea16047fdc on huangyuxiang03:master** into **d3319754b2f9e057ca99e921daf3423506b762c5 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] jt2594838 commented on a change in pull request #5010: Add encoding algorithms: RLBE, RAKE and SPRINTZ

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



##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/DoubleRLBEDecoder.java
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.tsfile.encoding.decoder;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import java.nio.ByteBuffer;
+
+public class DoubleRLBEDecoder extends Decoder {
+  /** constructor of DoubleRLBEDecoder */
+  public DoubleRLBEDecoder() {
+    super(TSEncoding.RLBE);
+    numberLeftInBuffer = 0;
+    byteBuffer = 0;
+  }
+
+  /** how many numbers expected to decode in following block */
+  private int blocksize;
+
+  /** origin values are stored in data */
+  private double[] data;
+
+  /** whether the first value is decoded */
+  private int writeindex = -1;
+
+  /** the pointer of current last value */
+  private int readindex = -1;
+
+  /** fibonacci values are stored in fibonacci */
+  private long[] fibonacci;
+
+  /** read bits from input stream to byteBuffer and get bit from byteBuffer */
+  private byte byteBuffer;
+
+  /** valid bits in byteBuffer */
+  private int numberLeftInBuffer;
+
+  /**
+   * read the header of a block, determine the size of block and malloc space values
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readhead(ByteBuffer buffer) {
+    for (int i = 0; i <= writeindex; i++) {
+      data[i] = 0;
+    }

Review comment:
       You have re-initialized `data` in line 68 so it seems pointless to operate it here.

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/DoubleRLBEDecoder.java
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.tsfile.encoding.decoder;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import java.nio.ByteBuffer;
+
+public class DoubleRLBEDecoder extends Decoder {
+  /** constructor of DoubleRLBEDecoder */
+  public DoubleRLBEDecoder() {
+    super(TSEncoding.RLBE);
+    numberLeftInBuffer = 0;
+    byteBuffer = 0;
+  }
+
+  /** how many numbers expected to decode in following block */
+  private int blocksize;
+
+  /** origin values are stored in data */
+  private double[] data;
+
+  /** whether the first value is decoded */
+  private int writeindex = -1;
+
+  /** the pointer of current last value */
+  private int readindex = -1;
+
+  /** fibonacci values are stored in fibonacci */
+  private long[] fibonacci;

Review comment:
       Fibonacci numbers are mathematically constant so it is not necessary for each decoder to have a separate copy. Maybe you can make it a static field and initialize it properly at the system startup.

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/DoubleRLBEDecoder.java
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.tsfile.encoding.decoder;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import java.nio.ByteBuffer;
+
+public class DoubleRLBEDecoder extends Decoder {
+  /** constructor of DoubleRLBEDecoder */
+  public DoubleRLBEDecoder() {
+    super(TSEncoding.RLBE);
+    numberLeftInBuffer = 0;
+    byteBuffer = 0;
+  }
+
+  /** how many numbers expected to decode in following block */
+  private int blocksize;
+
+  /** origin values are stored in data */
+  private double[] data;
+
+  /** whether the first value is decoded */
+  private int writeindex = -1;
+
+  /** the pointer of current last value */
+  private int readindex = -1;
+
+  /** fibonacci values are stored in fibonacci */
+  private long[] fibonacci;
+
+  /** read bits from input stream to byteBuffer and get bit from byteBuffer */
+  private byte byteBuffer;
+
+  /** valid bits in byteBuffer */
+  private int numberLeftInBuffer;
+
+  /**
+   * read the header of a block, determine the size of block and malloc space values
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readhead(ByteBuffer buffer) {
+    for (int i = 0; i <= writeindex; i++) {
+      data[i] = 0;
+    }
+    writeindex = -1;
+    readindex = -1;
+    clearBuffer(buffer);
+    readblocksize(buffer);
+    data = new double[blocksize * 2 + 1];
+    fibonacci = new long[blocksize * 2 + 1];
+    for (int i = 0; i < blocksize * 2; i++) {
+      data[i] = 0;
+      fibonacci[i] = 0;
+    }

Review comment:
       Java will initialize arrays for you so this can be removed.

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/DoubleRLBEDecoder.java
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.tsfile.encoding.decoder;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import java.nio.ByteBuffer;
+
+public class DoubleRLBEDecoder extends Decoder {
+  /** constructor of DoubleRLBEDecoder */
+  public DoubleRLBEDecoder() {
+    super(TSEncoding.RLBE);
+    numberLeftInBuffer = 0;
+    byteBuffer = 0;
+  }
+
+  /** how many numbers expected to decode in following block */
+  private int blocksize;
+
+  /** origin values are stored in data */
+  private double[] data;
+
+  /** whether the first value is decoded */
+  private int writeindex = -1;
+
+  /** the pointer of current last value */
+  private int readindex = -1;
+
+  /** fibonacci values are stored in fibonacci */
+  private long[] fibonacci;
+
+  /** read bits from input stream to byteBuffer and get bit from byteBuffer */
+  private byte byteBuffer;
+
+  /** valid bits in byteBuffer */
+  private int numberLeftInBuffer;
+
+  /**
+   * read the header of a block, determine the size of block and malloc space values
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readhead(ByteBuffer buffer) {
+    for (int i = 0; i <= writeindex; i++) {
+      data[i] = 0;
+    }
+    writeindex = -1;
+    readindex = -1;
+    clearBuffer(buffer);
+    readblocksize(buffer);
+    data = new double[blocksize * 2 + 1];
+    fibonacci = new long[blocksize * 2 + 1];
+    for (int i = 0; i < blocksize * 2; i++) {
+      data[i] = 0;
+      fibonacci[i] = 0;
+    }
+    fibonacci[0] = 1;
+    fibonacci[1] = 1;
+  }
+
+  /**
+   * read a block from inputstream buffer
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readT(ByteBuffer buffer) {
+    // read the header of the block
+    readhead(buffer);
+    while (writeindex < blocksize - 1) {
+      int seglength = 0, runlength = 0;
+      // read first 7 bits: length of each binary words.
+      for (int j = 6; j >= 0; j--) {
+        seglength |= (readbit(buffer) << j);
+      }
+
+      // generate repeat time of rle on delta
+      int now = readbit(buffer);
+      int next = readbit(buffer);
+
+      int j = 1;
+      while (true) {
+        if (j > 1) fibonacci[j] = fibonacci[j - 1] + fibonacci[j - 2];
+        if (now == 1) runlength += fibonacci[j];
+        // when now and next are both 1, the 1 of next is the symbol of ending of fibonacci code
+        if (now == 1 && next == 1) break;
+        j++;
+        now = next;
+        next = readbit(buffer);
+      }
+      // read the delta value one by one
+      for (int i = 1; i <= runlength; i++) {
+
+        long readlongtemp = 0;
+        for (int k = seglength - 1; k >= 0; k--) {
+          readlongtemp += ((long) readbit(buffer) << k);
+        }

Review comment:
       Optional improvement: reading bits one by one is not that efficient since it invokes methods. Maybe you can read 1, 2, or 4 bytes once according to the remaining length.

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/DoubleRLBEDecoder.java
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.tsfile.encoding.decoder;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import java.nio.ByteBuffer;
+
+public class DoubleRLBEDecoder extends Decoder {
+  /** constructor of DoubleRLBEDecoder */
+  public DoubleRLBEDecoder() {
+    super(TSEncoding.RLBE);
+    numberLeftInBuffer = 0;
+    byteBuffer = 0;
+  }
+
+  /** how many numbers expected to decode in following block */
+  private int blocksize;
+
+  /** origin values are stored in data */
+  private double[] data;
+
+  /** whether the first value is decoded */
+  private int writeindex = -1;
+
+  /** the pointer of current last value */
+  private int readindex = -1;
+
+  /** fibonacci values are stored in fibonacci */
+  private long[] fibonacci;
+
+  /** read bits from input stream to byteBuffer and get bit from byteBuffer */
+  private byte byteBuffer;
+
+  /** valid bits in byteBuffer */
+  private int numberLeftInBuffer;
+
+  /**
+   * read the header of a block, determine the size of block and malloc space values
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readhead(ByteBuffer buffer) {
+    for (int i = 0; i <= writeindex; i++) {
+      data[i] = 0;
+    }
+    writeindex = -1;
+    readindex = -1;
+    clearBuffer(buffer);
+    readblocksize(buffer);
+    data = new double[blocksize * 2 + 1];
+    fibonacci = new long[blocksize * 2 + 1];
+    for (int i = 0; i < blocksize * 2; i++) {
+      data[i] = 0;
+      fibonacci[i] = 0;
+    }
+    fibonacci[0] = 1;
+    fibonacci[1] = 1;
+  }
+
+  /**
+   * read a block from inputstream buffer
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readT(ByteBuffer buffer) {
+    // read the header of the block
+    readhead(buffer);
+    while (writeindex < blocksize - 1) {
+      int seglength = 0, runlength = 0;
+      // read first 7 bits: length of each binary words.
+      for (int j = 6; j >= 0; j--) {
+        seglength |= (readbit(buffer) << j);
+      }
+
+      // generate repeat time of rle on delta
+      int now = readbit(buffer);
+      int next = readbit(buffer);
+
+      int j = 1;
+      while (true) {
+        if (j > 1) fibonacci[j] = fibonacci[j - 1] + fibonacci[j - 2];
+        if (now == 1) runlength += fibonacci[j];
+        // when now and next are both 1, the 1 of next is the symbol of ending of fibonacci code
+        if (now == 1 && next == 1) break;
+        j++;
+        now = next;
+        next = readbit(buffer);
+      }
+      // read the delta value one by one
+      for (int i = 1; i <= runlength; i++) {
+
+        long readlongtemp = 0;
+        for (int k = seglength - 1; k >= 0; k--) {
+          readlongtemp += ((long) readbit(buffer) << k);
+        }
+        if (seglength == 64) readlongtemp -= ((long) 1 << 63);
+        double readdoubletemp = Double.longBitsToDouble(readlongtemp);
+        if (writeindex == -1) {
+          data[++writeindex] = readdoubletemp;
+        } else {
+          ++writeindex;
+          data[writeindex] = data[writeindex - 1] + readdoubletemp;
+        }
+      }
+    }
+  }
+
+  @Override
+  public double readDouble(ByteBuffer buffer) {
+    if (readindex < writeindex) {
+      return data[++readindex];
+    } else {
+      readT(buffer);
+      return data[++readindex];
+    }
+  }
+
+  @Override
+  public boolean hasNext(ByteBuffer buffer) {
+    return (buffer.remaining() > 0 || readindex < writeindex);
+  }
+
+  @Override
+  public void reset() {
+    // do nothing
+  }
+
+  /**
+   * get a bit from byteBuffer, when there is no bit in byteBuffer, get new 8 bits from inputstream
+   * buffer
+   *
+   * @param buffer inputstream buffer
+   * @return the top bit of byteBuffer
+   */
+  private int readbit(ByteBuffer buffer) {
+    if (numberLeftInBuffer == 0) {
+      loadBuffer(buffer);
+      numberLeftInBuffer = 8;
+    }
+    int top = ((byteBuffer >> 7) & 1);
+    byteBuffer <<= 1;
+    numberLeftInBuffer--;
+    return top;
+  }
+
+  /**
+   * get 8 bits from inputstream buffer to byteBuffer
+   *
+   * @param buffer inputstream buffer
+   */
+  private void loadBuffer(ByteBuffer buffer) {
+    byteBuffer = buffer.get();
+  }
+
+  /**
+   * clear all remaining bits in byteBuffer
+   *
+   * @param buffer inputstream buffer
+   */
+  private void clearBuffer(ByteBuffer buffer) {
+    while (numberLeftInBuffer > 0) {
+      readbit(buffer);
+    }
+  }

Review comment:
       Why not simply set `numberLeftInBuffer` to zero?

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/DoubleSprintzDecoder.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.tsfile.encoding.decoder;
+
+import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
+import org.apache.iotdb.tsfile.encoding.bitpacking.LongPacker;
+import org.apache.iotdb.tsfile.encoding.fire.LongFire;
+import org.apache.iotdb.tsfile.utils.ReadWriteForEncodingUtils;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+public class DoubleSprintzDecoder extends SprintzDecoder {
+  LongPacker packer;
+  LongFire firePred;
+  private double preValue;
+  private final double[] currentBuffer;
+  private final long[] convertBuffer;
+  private double currentValue;
+  private final String predictScheme =
+      TSFileDescriptor.getInstance().getConfig().getSprintzPredictScheme();
+
+  public DoubleSprintzDecoder() {
+    super();
+    currentBuffer = new double[Block_size + 1];
+    convertBuffer = new long[Block_size];
+    firePred = new LongFire(3);
+    reset();
+  }
+
+  @Override
+  public boolean hasNext(ByteBuffer buffer) throws IOException {
+    // int minLenth = Long.BYTES + 1;
+    return (isBlockReaded && currentCount < Block_size) || buffer.remaining() > 0;
+  }
+
+  @Override
+  public void reset() {
+    super.reset();
+    preValue = 0;
+    currentValue = 0;
+    currentCount = 0;
+    Arrays.fill(currentBuffer, 0);
+    Arrays.fill(convertBuffer, 0);
+  }
+
+  @Override
+  protected void decodeBlock(ByteBuffer in) throws IOException {
+    bitWidth = ReadWriteForEncodingUtils.readIntLittleEndianPaddedOnBitWidth(in, 1);
+    if ((bitWidth & (1 << 7)) != 0) {
+      decodeSize = bitWidth & ~(1 << 7);
+      DoublePrecisionDecoderV2 decoder = new DoublePrecisionDecoderV2();
+      for (int i = 0; i < decodeSize; i++) {
+        currentBuffer[i] = decoder.readDouble(in);
+      }
+    } else {
+      decodeSize = Block_size + 1;
+      preValue = in.getDouble();
+      currentBuffer[0] = preValue;
+      long[] tmpBuffer = new long[8];
+      packer = new LongPacker(bitWidth);
+      byte[] packcle = new byte[bitWidth];
+      for (int i = 0; i < bitWidth; i++) {
+        packcle[i] = in.get();
+      }
+      packer.unpack8Values(packcle, 0, tmpBuffer);
+      for (int i = 0; i < 8; i++) convertBuffer[i] = tmpBuffer[i];

Review comment:
       Why not just unpack into convertBuffer?

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/DoubleRLBEDecoder.java
##########
@@ -0,0 +1,197 @@
+/*
+ * 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.tsfile.encoding.decoder;
+
+import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding;
+
+import java.nio.ByteBuffer;
+
+public class DoubleRLBEDecoder extends Decoder {
+  /** constructor of DoubleRLBEDecoder */
+  public DoubleRLBEDecoder() {
+    super(TSEncoding.RLBE);
+    numberLeftInBuffer = 0;
+    byteBuffer = 0;
+  }
+
+  /** how many numbers expected to decode in following block */
+  private int blocksize;
+
+  /** origin values are stored in data */
+  private double[] data;
+
+  /** whether the first value is decoded */
+  private int writeindex = -1;
+
+  /** the pointer of current last value */
+  private int readindex = -1;
+
+  /** fibonacci values are stored in fibonacci */
+  private long[] fibonacci;
+
+  /** read bits from input stream to byteBuffer and get bit from byteBuffer */
+  private byte byteBuffer;
+
+  /** valid bits in byteBuffer */
+  private int numberLeftInBuffer;
+
+  /**
+   * read the header of a block, determine the size of block and malloc space values
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readhead(ByteBuffer buffer) {
+    for (int i = 0; i <= writeindex; i++) {
+      data[i] = 0;
+    }
+    writeindex = -1;
+    readindex = -1;
+    clearBuffer(buffer);
+    readblocksize(buffer);
+    data = new double[blocksize * 2 + 1];
+    fibonacci = new long[blocksize * 2 + 1];
+    for (int i = 0; i < blocksize * 2; i++) {
+      data[i] = 0;
+      fibonacci[i] = 0;
+    }
+    fibonacci[0] = 1;
+    fibonacci[1] = 1;
+  }
+
+  /**
+   * read a block from inputstream buffer
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readT(ByteBuffer buffer) {
+    // read the header of the block
+    readhead(buffer);
+    while (writeindex < blocksize - 1) {
+      int seglength = 0, runlength = 0;
+      // read first 7 bits: length of each binary words.
+      for (int j = 6; j >= 0; j--) {
+        seglength |= (readbit(buffer) << j);
+      }
+
+      // generate repeat time of rle on delta
+      int now = readbit(buffer);
+      int next = readbit(buffer);
+
+      int j = 1;
+      while (true) {
+        if (j > 1) fibonacci[j] = fibonacci[j - 1] + fibonacci[j - 2];
+        if (now == 1) runlength += fibonacci[j];
+        // when now and next are both 1, the 1 of next is the symbol of ending of fibonacci code
+        if (now == 1 && next == 1) break;
+        j++;
+        now = next;
+        next = readbit(buffer);
+      }
+      // read the delta value one by one
+      for (int i = 1; i <= runlength; i++) {
+
+        long readlongtemp = 0;
+        for (int k = seglength - 1; k >= 0; k--) {
+          readlongtemp += ((long) readbit(buffer) << k);
+        }
+        if (seglength == 64) readlongtemp -= ((long) 1 << 63);
+        double readdoubletemp = Double.longBitsToDouble(readlongtemp);
+        if (writeindex == -1) {
+          data[++writeindex] = readdoubletemp;
+        } else {
+          ++writeindex;
+          data[writeindex] = data[writeindex - 1] + readdoubletemp;
+        }
+      }
+    }
+  }
+
+  @Override
+  public double readDouble(ByteBuffer buffer) {
+    if (readindex < writeindex) {
+      return data[++readindex];
+    } else {
+      readT(buffer);
+      return data[++readindex];
+    }
+  }
+
+  @Override
+  public boolean hasNext(ByteBuffer buffer) {
+    return (buffer.remaining() > 0 || readindex < writeindex);
+  }
+
+  @Override
+  public void reset() {
+    // do nothing
+  }
+
+  /**
+   * get a bit from byteBuffer, when there is no bit in byteBuffer, get new 8 bits from inputstream
+   * buffer
+   *
+   * @param buffer inputstream buffer
+   * @return the top bit of byteBuffer
+   */
+  private int readbit(ByteBuffer buffer) {
+    if (numberLeftInBuffer == 0) {
+      loadBuffer(buffer);
+      numberLeftInBuffer = 8;
+    }
+    int top = ((byteBuffer >> 7) & 1);
+    byteBuffer <<= 1;
+    numberLeftInBuffer--;
+    return top;
+  }
+
+  /**
+   * get 8 bits from inputstream buffer to byteBuffer
+   *
+   * @param buffer inputstream buffer
+   */
+  private void loadBuffer(ByteBuffer buffer) {
+    byteBuffer = buffer.get();
+  }
+
+  /**
+   * clear all remaining bits in byteBuffer
+   *
+   * @param buffer inputstream buffer
+   */
+  private void clearBuffer(ByteBuffer buffer) {
+    while (numberLeftInBuffer > 0) {
+      readbit(buffer);
+    }
+  }
+
+  /**
+   * read the first integer of the block: blocksize
+   *
+   * @param buffer inputstream buffer
+   */
+  private void readblocksize(ByteBuffer buffer) {
+    blocksize = 0;
+    for (int i = 31; i >= 0; i--) {
+      if (readbit(buffer) == 1) {
+        blocksize |= (1 << i);
+      }
+    }
+  }
+}

Review comment:
       Is this different from `ByteBuffer.getInt`?

##########
File path: tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/DoubleSprintzDecoder.java
##########
@@ -0,0 +1,139 @@
+/*
+ * 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.tsfile.encoding.decoder;
+
+import org.apache.iotdb.tsfile.common.conf.TSFileDescriptor;
+import org.apache.iotdb.tsfile.encoding.bitpacking.LongPacker;
+import org.apache.iotdb.tsfile.encoding.fire.LongFire;
+import org.apache.iotdb.tsfile.utils.ReadWriteForEncodingUtils;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Arrays;
+
+public class DoubleSprintzDecoder extends SprintzDecoder {
+  LongPacker packer;
+  LongFire firePred;
+  private double preValue;
+  private final double[] currentBuffer;
+  private final long[] convertBuffer;
+  private double currentValue;
+  private final String predictScheme =
+      TSFileDescriptor.getInstance().getConfig().getSprintzPredictScheme();
+
+  public DoubleSprintzDecoder() {
+    super();
+    currentBuffer = new double[Block_size + 1];
+    convertBuffer = new long[Block_size];
+    firePred = new LongFire(3);
+    reset();
+  }
+
+  @Override
+  public boolean hasNext(ByteBuffer buffer) throws IOException {
+    // int minLenth = Long.BYTES + 1;
+    return (isBlockReaded && currentCount < Block_size) || buffer.remaining() > 0;
+  }
+
+  @Override
+  public void reset() {
+    super.reset();
+    preValue = 0;
+    currentValue = 0;
+    currentCount = 0;
+    Arrays.fill(currentBuffer, 0);
+    Arrays.fill(convertBuffer, 0);
+  }
+
+  @Override
+  protected void decodeBlock(ByteBuffer in) throws IOException {
+    bitWidth = ReadWriteForEncodingUtils.readIntLittleEndianPaddedOnBitWidth(in, 1);
+    if ((bitWidth & (1 << 7)) != 0) {
+      decodeSize = bitWidth & ~(1 << 7);
+      DoublePrecisionDecoderV2 decoder = new DoublePrecisionDecoderV2();
+      for (int i = 0; i < decodeSize; i++) {
+        currentBuffer[i] = decoder.readDouble(in);
+      }
+    } else {
+      decodeSize = Block_size + 1;
+      preValue = in.getDouble();
+      currentBuffer[0] = preValue;
+      long[] tmpBuffer = new long[8];
+      packer = new LongPacker(bitWidth);
+      byte[] packcle = new byte[bitWidth];
+      for (int i = 0; i < bitWidth; i++) {
+        packcle[i] = in.get();
+      }

Review comment:
       `bitWidth` or `byteWidth`?




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