diff --git a/cpp/pom.xml b/cpp/pom.xml index c36997356..d538d3f13 100644 --- a/cpp/pom.xml +++ b/cpp/pom.xml @@ -22,7 +22,7 @@ org.apache.tsfile tsfile-parent - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT tsfile-cpp pom diff --git a/java/common/pom.xml b/java/common/pom.xml index fe503903c..7c17e7e59 100644 --- a/java/common/pom.xml +++ b/java/common/pom.xml @@ -24,7 +24,7 @@ org.apache.tsfile tsfile-java - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT common TsFile: Java: Common diff --git a/java/common/src/main/java/org/apache/tsfile/utils/Binary.java b/java/common/src/main/java/org/apache/tsfile/utils/Binary.java index f65d19c34..f80a385df 100644 --- a/java/common/src/main/java/org/apache/tsfile/utils/Binary.java +++ b/java/common/src/main/java/org/apache/tsfile/utils/Binary.java @@ -36,7 +36,7 @@ public class Binary implements Comparable, Serializable, Accountable { private static final long serialVersionUID = 6394197743397020735L; public static final Binary EMPTY_VALUE = new Binary(new byte[0]); - private byte[] values; + byte[] values; /** if the bytes v is modified, the modification is visible to this binary. */ public Binary(byte[] v) { @@ -70,7 +70,7 @@ public int compareTo(Binary other) { } // avoid overflow - private char getChar(byte[] val, int index) { + protected char getChar(byte[] val, int index) { return (char) (val[index] & 0xff); } @@ -92,9 +92,13 @@ public int hashCode() { } /** - * get length. + * Gets the actual payload length. * - * @return length + *

This method returns the effective length of the data (payload) stored in the byte array. If + * the byte array is null, it returns -1. Note that this length may be less than the total + * capacity of the byte array. + * + * @return the actual payload length, or -1 if the byte array is null */ public int getLength() { if (this.values == null) { @@ -103,6 +107,22 @@ public int getLength() { return this.values.length; } + /** + * Gets the total capacity of the byte array. + * + *

This method returns the total capacity of the underlying byte array. If the byte array is + * null, it returns -1. Note that the effective payload length (actual valid data) may be smaller + * than the total capacity of the array. + * + * @return the total capacity of the byte array, or -1 if the array is null + */ + public int getCapacity() { + if (this.values == null) { + return -1; + } + return this.values.length; + } + public String getStringValue(Charset charset) { return new String(this.values, charset); } @@ -117,6 +137,10 @@ public byte[] getValues() { return values; } + public Pair getValuesAndLength() { + return new Pair<>(values, values.length); + } + public void setValues(byte[] values) { this.values = values; } @@ -125,4 +149,12 @@ public void setValues(byte[] values) { public long ramBytesUsed() { return INSTANCE_SIZE + sizeOf(values); } + + public long ramShallowBytesUsed() { + return INSTANCE_SIZE; + } + + public boolean isNull() { + return values == null; + } } diff --git a/java/tsfile/src/main/java/org/apache/tsfile/utils/Pair.java b/java/common/src/main/java/org/apache/tsfile/utils/Pair.java similarity index 100% rename from java/tsfile/src/main/java/org/apache/tsfile/utils/Pair.java rename to java/common/src/main/java/org/apache/tsfile/utils/Pair.java diff --git a/java/common/src/main/java/org/apache/tsfile/utils/PooledBinary.java b/java/common/src/main/java/org/apache/tsfile/utils/PooledBinary.java index d66b283f3..c2af4b9bb 100644 --- a/java/common/src/main/java/org/apache/tsfile/utils/PooledBinary.java +++ b/java/common/src/main/java/org/apache/tsfile/utils/PooledBinary.java @@ -18,11 +18,11 @@ */ package org.apache.tsfile.utils; -import java.io.Serializable; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import static org.apache.tsfile.utils.RamUsageEstimator.shallowSizeOfInstance; +import static org.apache.tsfile.utils.RamUsageEstimator.sizeOf; /** * This class represents a pooled binary object for application layer. It is designed to improve @@ -31,13 +31,10 @@ * length of the underlying byte array. Always use getLength() instead of getValue().length to get * the correct length. */ -public class PooledBinary implements Comparable, Serializable, Accountable { +public class PooledBinary extends Binary { private static final long INSTANCE_SIZE = shallowSizeOfInstance(PooledBinary.class); private static final long serialVersionUID = 6394197743397020735L; - public static final PooledBinary EMPTY_VALUE = new PooledBinary(new byte[0]); - - private Binary binary; private int length; @@ -45,50 +42,21 @@ public class PooledBinary implements Comparable, Serializable, Acc /** if the bytes v is modified, the modification is visible to this binary. */ public PooledBinary(byte[] v) { - this.binary = new Binary(v); - this.length = binary.getLength(); + super(v); + this.length = values.length; } public PooledBinary(String s, Charset charset) { - this.binary = new Binary(s, charset); - this.length = binary.getLength(); + super(s, charset); + this.length = values.length; } public PooledBinary(byte[] v, int length, int arenaIndex) { - this.binary = new Binary(v); + super(v); this.length = length; this.arenaIndex = arenaIndex; } - @Override - public int compareTo(PooledBinary other) { - if (other == null) { - if (this.binary.getValues() == null) { - return 0; - } else { - return 1; - } - } - - // copied from StringLatin1.compareT0 - int len1 = getLength(); - int len2 = other.getLength(); - int lim = Math.min(len1, len2); - byte[] v0 = this.binary.getValues(); - byte[] v1 = other.binary.getValues(); - for (int k = 0; k < lim; k++) { - if (v0[k] != v1[k]) { - return getChar(v0, k) - getChar(v1, k); - } - } - return len1 - len2; - } - - // avoid overflow - private char getChar(byte[] val, int index) { - return (char) (val[index] & 0xff); - } - @Override public boolean equals(Object o) { if (this == o) { @@ -103,8 +71,8 @@ public boolean equals(Object o) { return false; } - byte[] v0 = binary.getValues(); - byte[] v1 = otherBinary.binary.getValues(); + byte[] v0 = values; + byte[] v1 = otherBinary.values; for (int i = 0; i < length; i++) { if (v0[i] != v1[i]) { @@ -118,26 +86,24 @@ public boolean equals(Object o) { @Override public int hashCode() { // copied from Arrays.hashCode - if (binary.getValues() == null) return 0; + if (values == null) return 0; int result = 1; - byte[] val = binary.getValues(); - for (int i = 0; i < length; i++) result = 31 * result + val[i]; + for (int i = 0; i < length; i++) { + result = 31 * result + values[i]; + } return result; } - /** - * get length. - * - * @return length - */ + @Override public int getLength() { return this.length; } + @Override public String getStringValue(Charset charset) { - return new String(this.binary.getValues(), 0, length, charset); + return new String(values, 0, length, charset); } @Override @@ -146,17 +112,19 @@ public String toString() { return getStringValue(StandardCharsets.UTF_8); } - public byte[] getValues() { - return binary.getValues(); + @Override + public Pair getValuesAndLength() { + return new Pair<>(values, length); } + @Override public void setValues(byte[] values) { - this.binary.setValues(values); - this.length = this.binary.getLength(); + super.setValues(values); + this.length = values.length; } public void setValues(byte[] values, int length) { - this.binary.setValues(values); + super.setValues(values); this.length = length; } @@ -166,10 +134,11 @@ public int getArenaIndex() { @Override public long ramBytesUsed() { - return INSTANCE_SIZE + binary.ramBytesUsed(); + return INSTANCE_SIZE + sizeOf(values); } - public Binary toBinary() { - return binary; + @Override + public long ramShallowBytesUsed() { + return INSTANCE_SIZE; } } diff --git a/java/examples/pom.xml b/java/examples/pom.xml index 9f7edaee9..e411052a4 100644 --- a/java/examples/pom.xml +++ b/java/examples/pom.xml @@ -24,7 +24,7 @@ org.apache.tsfile tsfile-java - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT examples pom @@ -37,7 +37,7 @@ org.apache.tsfile tsfile - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT diff --git a/java/pom.xml b/java/pom.xml index 21d5ff3a0..0bb32f1a2 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -24,10 +24,10 @@ org.apache.tsfile tsfile-parent - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT tsfile-java - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT pom TsFile: Java diff --git a/java/tools/pom.xml b/java/tools/pom.xml index e7e9de18c..f958dcef3 100644 --- a/java/tools/pom.xml +++ b/java/tools/pom.xml @@ -24,7 +24,7 @@ org.apache.tsfile tsfile-java - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT tools TsFile: Java: Tools @@ -32,7 +32,7 @@ org.apache.tsfile common - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT commons-cli @@ -50,7 +50,7 @@ org.apache.tsfile tsfile - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT ch.qos.logback diff --git a/java/tsfile/pom.xml b/java/tsfile/pom.xml index 6eeabcb4a..ba8796a39 100644 --- a/java/tsfile/pom.xml +++ b/java/tsfile/pom.xml @@ -24,7 +24,7 @@ org.apache.tsfile tsfile-java - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT tsfile TsFile: Java: TsFile @@ -38,7 +38,7 @@ org.apache.tsfile common - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT com.github.luben diff --git a/java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/DictionaryEncoder.java b/java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/DictionaryEncoder.java index 4a6fde552..48f316cf0 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/DictionaryEncoder.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/DictionaryEncoder.java @@ -21,6 +21,7 @@ import org.apache.tsfile.file.metadata.enums.TSEncoding; import org.apache.tsfile.utils.Binary; +import org.apache.tsfile.utils.BinaryUtils; import org.apache.tsfile.utils.ReadWriteForEncodingUtils; import org.slf4j.Logger; @@ -99,7 +100,7 @@ private void writeMap(ByteArrayOutputStream out) throws IOException { ReadWriteForEncodingUtils.writeVarInt(indexEntry.size(), out); for (Binary value : indexEntry) { ReadWriteForEncodingUtils.writeVarInt(value.getLength(), out); - out.write(value.getValues()); + BinaryUtils.serializeBytes(out, value); } } diff --git a/java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/PlainEncoder.java b/java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/PlainEncoder.java index 09c28cbef..4e7584195 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/PlainEncoder.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/encoding/encoder/PlainEncoder.java @@ -24,6 +24,7 @@ import org.apache.tsfile.exception.encoding.TsFileEncodingException; import org.apache.tsfile.file.metadata.enums.TSEncoding; import org.apache.tsfile.utils.Binary; +import org.apache.tsfile.utils.BinaryUtils; import org.apache.tsfile.utils.ReadWriteForEncodingUtils; import org.slf4j.Logger; @@ -92,7 +93,7 @@ public void encode(Binary value, ByteArrayOutputStream out) { // write the length of the bytes encode(value.getLength(), out); // write value - out.write(value.getValues()); + BinaryUtils.serializeBytes(out, value); } catch (IOException e) { logger.error( "tsfile-encoding PlainEncoder: error occurs when encode Binary value {}", value, e); diff --git a/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/statistics/BinaryStatistics.java b/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/statistics/BinaryStatistics.java index 34db11b93..3bdb86710 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/statistics/BinaryStatistics.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/statistics/BinaryStatistics.java @@ -54,7 +54,7 @@ public TSDataType getType() { /** The output of this method should be identical to the method "serializeStats(outputStream)". */ @Override public int getStatsSize() { - return 4 + firstValue.getValues().length + 4 + lastValue.getValues().length; + return 4 + firstValue.getLength() + 4 + lastValue.getLength(); } @Override diff --git a/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/statistics/StringStatistics.java b/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/statistics/StringStatistics.java index 5997fb9b4..f480d3865 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/statistics/StringStatistics.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/file/metadata/statistics/StringStatistics.java @@ -55,10 +55,10 @@ public TSDataType getType() { @Override public int getStatsSize() { return 4 * 4 - + firstValue.getValues().length - + lastValue.getValues().length - + minValue.getValues().length - + maxValue.getValues().length; + + firstValue.getLength() + + lastValue.getLength() + + minValue.getLength() + + maxValue.getLength(); } @Override diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/common/BatchData.java b/java/tsfile/src/main/java/org/apache/tsfile/read/common/BatchData.java index 504f7a9cb..1d3a602e0 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/common/BatchData.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/common/BatchData.java @@ -24,6 +24,7 @@ import org.apache.tsfile.read.TimeValuePair; import org.apache.tsfile.read.reader.IPointReader; import org.apache.tsfile.utils.Binary; +import org.apache.tsfile.utils.BinaryUtils; import org.apache.tsfile.utils.TsPrimitiveType; import org.apache.tsfile.utils.TsPrimitiveType.TsBinary; import org.apache.tsfile.utils.TsPrimitiveType.TsBoolean; @@ -703,7 +704,7 @@ public void serializeData(DataOutputStream outputStream) throws IOException { outputStream.writeLong(getTimeByIndex(i)); Binary binary = getBinaryByIndex(i); outputStream.writeInt(binary.getLength()); - outputStream.write(binary.getValues()); + BinaryUtils.serializeBytes(outputStream, binary); } break; case INT64: @@ -746,7 +747,7 @@ public void serializeData(DataOutputStream outputStream) throws IOException { case STRING: Binary binary = value.getBinary(); outputStream.writeInt(binary.getLength()); - outputStream.write(binary.getValues()); + BinaryUtils.serializeBytes(outputStream, binary); break; case INT64: case TIMESTAMP: diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/common/DescReadWriteBatchData.java b/java/tsfile/src/main/java/org/apache/tsfile/read/common/DescReadWriteBatchData.java index 1fd65740c..07774d3c5 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/common/DescReadWriteBatchData.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/common/DescReadWriteBatchData.java @@ -21,6 +21,7 @@ import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.utils.Binary; +import org.apache.tsfile.utils.BinaryUtils; import org.apache.tsfile.utils.TsPrimitiveType; import org.apache.tsfile.write.UnSupportedDataTypeException; @@ -444,7 +445,7 @@ public void serializeData(DataOutputStream outputStream) throws IOException { outputStream.writeLong(getTimeByIndex(i)); Binary binary = getBinaryByIndex(i); outputStream.writeInt(binary.getLength()); - outputStream.write(binary.getValues()); + BinaryUtils.serializeBytes(outputStream, binary); } break; case INT64: @@ -487,7 +488,7 @@ public void serializeData(DataOutputStream outputStream) throws IOException { case STRING: Binary binary = value.getBinary(); outputStream.writeInt(binary.getLength()); - outputStream.write(binary.getValues()); + BinaryUtils.serializeBytes(outputStream, binary); break; case INT64: case TIMESTAMP: diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/common/Field.java b/java/tsfile/src/main/java/org/apache/tsfile/read/common/Field.java index 01d4dcdbc..944df3a92 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/common/Field.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/common/Field.java @@ -22,7 +22,7 @@ import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.exception.NullFieldException; import org.apache.tsfile.utils.Binary; -import org.apache.tsfile.utils.BytesUtils; +import org.apache.tsfile.utils.BinaryUtils; import org.apache.tsfile.utils.DateUtils; import org.apache.tsfile.utils.TsPrimitiveType; import org.apache.tsfile.write.UnSupportedDataTypeException; @@ -184,7 +184,7 @@ public String getStringValue() { case STRING: return binaryV.toString(); case BLOB: - return BytesUtils.parseBlobByteArrayToString(binaryV.getValues()); + return BinaryUtils.parseBlobByteArrayToString(binaryV); default: throw new UnSupportedDataTypeException(dataType.toString()); } diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/common/block/column/BinaryArrayColumnEncoder.java b/java/tsfile/src/main/java/org/apache/tsfile/read/common/block/column/BinaryArrayColumnEncoder.java index c4bb38336..bf12a10db 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/common/block/column/BinaryArrayColumnEncoder.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/common/block/column/BinaryArrayColumnEncoder.java @@ -22,6 +22,7 @@ import org.apache.tsfile.block.column.Column; import org.apache.tsfile.enums.TSDataType; import org.apache.tsfile.utils.Binary; +import org.apache.tsfile.utils.BinaryUtils; import java.io.DataOutputStream; import java.io.IOException; @@ -83,7 +84,7 @@ public void writeColumn(DataOutputStream output, Column column) throws IOExcepti if (!column.isNull(i)) { Binary binary = column.getBinary(i); output.writeInt(binary.getLength()); - output.write(binary.getValues()); + BinaryUtils.serializeBytes(output, binary); } } } else { diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java index 8a28866de..6d96eb017 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/AbstractResultSet.java @@ -24,6 +24,7 @@ import org.apache.tsfile.exception.NullFieldException; import org.apache.tsfile.read.common.Field; import org.apache.tsfile.read.common.RowRecord; +import org.apache.tsfile.utils.Binary; import java.io.IOException; import java.time.LocalDate; @@ -134,14 +135,14 @@ public LocalDate getDate(int columnIndex) { } @TsFileApi - public byte[] getBinary(String columnName) { + public Binary getBinary(String columnName) { Integer columnIndex = columnNameToColumnIndexMap.get(columnName); return getBinary(columnIndex); } @TsFileApi - public byte[] getBinary(int columnIndex) { - return getNonNullField(columnIndex).getBinaryV().getValues(); + public Binary getBinary(int columnIndex) { + return getNonNullField(columnIndex).getBinaryV(); } @TsFileApi diff --git a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSet.java b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSet.java index 02f23071a..025694ea9 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSet.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/read/query/dataset/ResultSet.java @@ -20,6 +20,7 @@ package org.apache.tsfile.read.query.dataset; import org.apache.tsfile.common.TsFileApi; +import org.apache.tsfile.utils.Binary; import java.io.IOException; import java.time.LocalDate; @@ -75,10 +76,10 @@ public interface ResultSet extends AutoCloseable { LocalDate getDate(int columnIndex); @TsFileApi - byte[] getBinary(String columnName); + Binary getBinary(String columnName); @TsFileApi - byte[] getBinary(int columnIndex); + Binary getBinary(int columnIndex); @TsFileApi boolean isNull(String columnName); diff --git a/java/tsfile/src/main/java/org/apache/tsfile/utils/BinaryUtils.java b/java/tsfile/src/main/java/org/apache/tsfile/utils/BinaryUtils.java new file mode 100644 index 000000000..94e77be0e --- /dev/null +++ b/java/tsfile/src/main/java/org/apache/tsfile/utils/BinaryUtils.java @@ -0,0 +1,48 @@ +/* + * 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.tsfile.utils; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.nio.ByteBuffer; + +public class BinaryUtils { + public static String parseBlobByteArrayToString(Binary input) { + return BytesUtils.parseBlobByteArrayToString(input.values, 0, input.getLength()); + } + + public static void serializeBytes(OutputStream stream, Binary binary) throws IOException { + stream.write(binary.values, 0, binary.getLength()); + } + + public static void serializeBytes(ByteBuffer buffer, Binary binary) { + buffer.put(binary.values, 0, binary.getLength()); + } + + public static ByteBuffer wrapToByteBuffer(Binary binary) { + return ByteBuffer.wrap(binary.values, 0, binary.getLength()); + } + + public static InputStream wrapToByteStream(Binary binary) { + return new ByteArrayInputStream(binary.values, 0, binary.getLength()); + } +} diff --git a/java/tsfile/src/main/java/org/apache/tsfile/utils/BytesUtils.java b/java/tsfile/src/main/java/org/apache/tsfile/utils/BytesUtils.java index f38a0da19..7b62b2c19 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/utils/BytesUtils.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/utils/BytesUtils.java @@ -933,10 +933,14 @@ public static Binary valueOf(String value) { } public static String parseBlobByteArrayToString(byte[] input) { + return parseBlobByteArrayToString(input, 0, input.length); + } + + public static String parseBlobByteArrayToString(byte[] input, int offset, int length) { StringBuilder hexString = new StringBuilder("0x"); if (input != null) { - for (byte b : input) { - hexString.append(String.format("%02x", b)); + for (int i = offset; i < offset + length; i++) { + hexString.append(String.format("%02x", input[i])); } } return hexString.toString(); diff --git a/java/tsfile/src/main/java/org/apache/tsfile/utils/ReadWriteIOUtils.java b/java/tsfile/src/main/java/org/apache/tsfile/utils/ReadWriteIOUtils.java index 50aed1179..a5aff840a 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/utils/ReadWriteIOUtils.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/utils/ReadWriteIOUtils.java @@ -287,7 +287,7 @@ public static int write(short n, ByteBuffer buffer) { */ public static int write(Binary n, ByteBuffer buffer) { buffer.putInt(n.getLength()); - buffer.put(n.getValues()); + BinaryUtils.serializeBytes(buffer, n); return INT_LEN + n.getLength(); } @@ -304,10 +304,10 @@ public static int write(int n, OutputStream outputStream) throws IOException { /** write the size (int) of the binary and then the bytes in binary */ public static int write(Binary binary, OutputStream outputStream) throws IOException { - byte[] size = BytesUtils.intToBytes(binary.getValues().length); + byte[] size = BytesUtils.intToBytes(binary.getLength()); outputStream.write(size); - outputStream.write(binary.getValues()); - return size.length + binary.getValues().length; + BinaryUtils.serializeBytes(outputStream, binary); + return size.length + binary.getLength(); } /** @@ -1162,9 +1162,9 @@ public static void writeObject(Object value, DataOutputStream outputStream) { outputStream.writeFloat((Float) value); } else if (value instanceof Binary) { outputStream.write(BINARY.ordinal()); - byte[] bytes = ((Binary) value).getValues(); - outputStream.writeInt(bytes.length); - outputStream.write(bytes); + Binary binary = ((Binary) value); + outputStream.writeInt(binary.getLength()); + BinaryUtils.serializeBytes(outputStream, binary); } else if (value instanceof Boolean) { outputStream.write(BOOLEAN.ordinal()); outputStream.write(Boolean.TRUE.equals(value) ? 1 : 0); @@ -1196,9 +1196,9 @@ public static void writeObject(Object value, ByteBuffer byteBuffer) { byteBuffer.putFloat((Float) value); } else if (value instanceof Binary) { byteBuffer.putInt(BINARY.ordinal()); - byte[] bytes = ((Binary) value).getValues(); - byteBuffer.putInt(bytes.length); - byteBuffer.put(bytes); + Binary binary = ((Binary) value); + byteBuffer.putInt(binary.getLength()); + BinaryUtils.serializeBytes(byteBuffer, binary); } else if (value instanceof Boolean) { byteBuffer.putInt(BOOLEAN.ordinal()); byteBuffer.put(Boolean.TRUE.equals(value) ? (byte) 1 : (byte) 0); diff --git a/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java b/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java index 4acf943b1..e086213cc 100644 --- a/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java +++ b/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java @@ -796,7 +796,7 @@ public static BitMap[] readBitMapsFromBuffer(ByteBuffer byteBuffer, int columns) if (hasBitMap) { final int size = ReadWriteIOUtils.readInt(byteBuffer); final Binary valueBinary = ReadWriteIOUtils.readBinary(byteBuffer); - bitMaps[i] = new BitMap(size, valueBinary.getValues()); + bitMaps[i] = new BitMap(size, valueBinary.getValuesAndLength().left); } } return bitMaps; diff --git a/pom.xml b/pom.xml index ce3b16156..6dffdadef 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ org.apache.tsfile tsfile-parent - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT pom Apache TsFile Project Parent POM diff --git a/python/pom.xml b/python/pom.xml index f02e50218..56a47a27f 100644 --- a/python/pom.xml +++ b/python/pom.xml @@ -22,7 +22,7 @@ org.apache.tsfile tsfile-parent - 1.2.0-SNAPSHOT + 1.3.0-SNAPSHOT tsfile-python pom