Skip to content

Commit 97401d3

Browse files
authored
Fix encoder and decoder construction of RLBE (#162)
1 parent 6a94370 commit 97401d3

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

java/tsfile/src/main/java/org/apache/tsfile/encoding/decoder/Decoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,9 @@ public static Decoder getDecoderByType(TSEncoding encoding, TSDataType dataType)
171171
case TIMESTAMP:
172172
return new LongRLBEDecoder();
173173
case FLOAT:
174+
return new FloatRLBEDecoder();
174175
case DOUBLE:
175-
return new FloatDecoder(TSEncoding.valueOf(encoding.toString()), dataType);
176+
return new DoubleRLBEDecoder();
176177
default:
177178
throw new TsFileDecodingException(String.format(ERROR_MSG, encoding, dataType));
178179
}

java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/TSEncodingBuilder.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,6 @@ public void initFromProps(Map<String, String> props) {
342342

343343
public static class RLBE extends TSEncodingBuilder {
344344

345-
private int maxPointNumber = 0;
346-
347345
@Override
348346
public Encoder getEncoder(TSDataType type) {
349347
switch (type) {
@@ -354,8 +352,9 @@ public Encoder getEncoder(TSDataType type) {
354352
case TIMESTAMP:
355353
return new LongRLBE();
356354
case FLOAT:
355+
return new FloatRLBE();
357356
case DOUBLE:
358-
return new FloatEncoder(TSEncoding.RLBE, type, maxPointNumber);
357+
return new DoubleRLBE();
359358
default:
360359
throw new UnSupportedDataTypeException("RLBE doesn't support data type: " + type);
361360
}

java/tsfile/src/test/java/org/apache/tsfile/encoding/decoder/RLBEDecoderTest.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@
1818
*/
1919
package org.apache.tsfile.encoding.decoder;
2020

21-
import org.apache.tsfile.encoding.encoder.DoublePrecisionEncoderV1;
2221
import org.apache.tsfile.encoding.encoder.DoubleRLBE;
2322
import org.apache.tsfile.encoding.encoder.Encoder;
2423
import org.apache.tsfile.encoding.encoder.FloatRLBE;
24+
import org.apache.tsfile.encoding.encoder.TSEncodingBuilder;
25+
import org.apache.tsfile.enums.TSDataType;
26+
import org.apache.tsfile.file.metadata.enums.TSEncoding;
2527

2628
import org.junit.After;
2729
import org.junit.Before;
@@ -179,7 +181,8 @@ public void testFloat() throws IOException {
179181

180182
@Test
181183
public void testDouble() throws IOException {
182-
Encoder encoder = new DoublePrecisionEncoderV1();
184+
Encoder encoder =
185+
TSEncodingBuilder.RLBE.getEncodingBuilder(TSEncoding.RLBE).getEncoder(TSDataType.DOUBLE);
183186
ByteArrayOutputStream baos = new ByteArrayOutputStream();
184187
double value = 7.101f;
185188
int num = 1000;
@@ -188,7 +191,7 @@ public void testDouble() throws IOException {
188191
}
189192
encoder.flush(baos);
190193
ByteBuffer buffer = ByteBuffer.wrap(baos.toByteArray());
191-
Decoder decoder = new DoublePrecisionDecoderV1();
194+
Decoder decoder = Decoder.getDecoderByType(TSEncoding.RLBE, TSDataType.DOUBLE);
192195
for (int i = 0; i < num; i++) {
193196
if (decoder.hasNext(buffer)) {
194197
assertEquals(value + 2 * i, decoder.readDouble(buffer), delta);
@@ -228,7 +231,8 @@ private void testFloatLength(List<Float> valueList, boolean isDebug, int repeatC
228231

229232
private void testDoubleLength(List<Double> valueList, boolean isDebug, int repeatCount)
230233
throws Exception {
231-
Encoder encoder = new DoublePrecisionEncoderV1();
234+
Encoder encoder =
235+
TSEncodingBuilder.RLBE.getEncodingBuilder(TSEncoding.RLBE).getEncoder(TSDataType.DOUBLE);
232236
ByteArrayOutputStream baos = new ByteArrayOutputStream();
233237
for (int i = 0; i < repeatCount; i++) {
234238
for (double value : valueList) {
@@ -240,7 +244,7 @@ private void testDoubleLength(List<Double> valueList, boolean isDebug, int repea
240244
ByteBuffer buffer = ByteBuffer.wrap(baos.toByteArray());
241245

242246
for (int i = 0; i < repeatCount; i++) {
243-
Decoder decoder = new DoublePrecisionDecoderV1();
247+
Decoder decoder = Decoder.getDecoderByType(TSEncoding.RLBE, TSDataType.DOUBLE);
244248
for (double value : valueList) {
245249
if (decoder.hasNext(buffer)) {
246250
double value_ = decoder.readDouble(buffer);

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@
668668
<cmake.generator>Unix Makefiles</cmake.generator>
669669
<python.venv.bin>venv/bin/</python.venv.bin>
670670
<python.exe.bin>python3</python.exe.bin>
671-
<python.compiler.argument> </python.compiler.argument>
671+
<python.compiler.argument/>
672672
</properties>
673673
</profile>
674674
<!-- Profile for linux amd64 (mainly AMD Processors) (Self-Enabling) -->
@@ -687,7 +687,7 @@
687687
<cmake.generator>Unix Makefiles</cmake.generator>
688688
<python.venv.bin>venv/bin/</python.venv.bin>
689689
<python.exe.bin>python3</python.exe.bin>
690-
<python.compiler.argument> </python.compiler.argument>
690+
<python.compiler.argument/>
691691
</properties>
692692
</profile>
693693
<!-- Profile for linux aarch64 (mainly newer Mac or Raspberry PI Processors) (Self-Enabling) -->
@@ -706,7 +706,7 @@
706706
<cmake.generator>Unix Makefiles</cmake.generator>
707707
<python.venv.bin>venv/bin/</python.venv.bin>
708708
<python.exe.bin>python3</python.exe.bin>
709-
<python.compiler.argument> </python.compiler.argument>
709+
<python.compiler.argument/>
710710
</properties>
711711
</profile>
712712
<!-- Profile for mac x86_64 (mainly Intel Processors) (Self-Enabling) -->
@@ -724,7 +724,7 @@
724724
<cmake.generator>Unix Makefiles</cmake.generator>
725725
<python.venv.bin>venv/bin/</python.venv.bin>
726726
<python.exe.bin>python3</python.exe.bin>
727-
<python.compiler.argument> </python.compiler.argument>
727+
<python.compiler.argument/>
728728
</properties>
729729
</profile>
730730
<!-- Profile for mac aarch64 (mainly AMD Processors) (Self-Enabling) -->
@@ -742,7 +742,7 @@
742742
<cmake.generator>Unix Makefiles</cmake.generator>
743743
<python.venv.bin>venv/bin/</python.venv.bin>
744744
<python.exe.bin>python3</python.exe.bin>
745-
<python.compiler.argument> </python.compiler.argument>
745+
<python.compiler.argument/>
746746
</properties>
747747
</profile>
748748
<!-- profile for windows x86_64 (mainly Intel Processors) (Self-Enabling) -->

0 commit comments

Comments
 (0)