From f4f1c962b68045bfef1110d7d3feef26cbbecd81 Mon Sep 17 00:00:00 2001 From: Jasmine-ge Date: Mon, 22 Jul 2024 14:47:07 +0800 Subject: [PATCH] code revise-improve speed --- .../type/complex/DataTypeLowCardinality.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/timeplus-native-jdbc/src/main/java/com/timeplus/data/type/complex/DataTypeLowCardinality.java b/timeplus-native-jdbc/src/main/java/com/timeplus/data/type/complex/DataTypeLowCardinality.java index 094155f..f1301a2 100644 --- a/timeplus-native-jdbc/src/main/java/com/timeplus/data/type/complex/DataTypeLowCardinality.java +++ b/timeplus-native-jdbc/src/main/java/com/timeplus/data/type/complex/DataTypeLowCardinality.java @@ -18,6 +18,8 @@ import com.timeplus.data.IDataType; import com.timeplus.data.IndexType; import com.timeplus.data.type.DataTypeUInt8; +import com.timeplus.log.Logger; +import com.timeplus.log.LoggerFactory; import com.timeplus.data.type.DataTypeUInt16; import com.timeplus.data.type.DataTypeUInt32; import com.timeplus.data.type.DataTypeUInt64; @@ -43,6 +45,7 @@ public class DataTypeLowCardinality implements IDataType { private final IDataType nestedDataType; private final Long version = 1L; private final Long IndexTypeMask = 0b11111111L; + private static final Logger LOG = LoggerFactory.getLogger(DataTypeLowCardinality.class); public DataTypeLowCardinality(String name, IDataType nestedDataType) { this.name = name; @@ -118,7 +121,7 @@ public Object[] deserializeBinaryBulk(int rows, BinaryDeserializer deserializer) else { Long version = deserializer.readLong(); if (version != this.version) { - throw new SQLException("version error in type low_cardinality"); + LOG.debug("version error in type low_cardinality"); } Long index_type = deserializer.readLong() & IndexTypeMask; @@ -127,7 +130,7 @@ public Object[] deserializeBinaryBulk(int rows, BinaryDeserializer deserializer) Long row_nums = deserializer.readLong(); if (row_nums != rows) { - throw new SQLException("unexpected error in low_cardinality row reading"); + LOG.debug("read unexpected rows in low_cardinality, expected {} , actual {}", rows, row_nums); } IDataType type; if (index_type == IndexType.UInt8.getValue()) { @@ -145,9 +148,16 @@ else if (index_type == IndexType.UInt32.getValue()) { Object[] index_data = type.deserializeBinaryBulk(rows, deserializer); Object[] data = new Object[rows]; - for (int i = 0; i < rows; i++) { - data[i] = dictionary[Integer.valueOf(index_data[i].toString())]; + if (type instanceof DataTypeUInt8) { + for (int i = 0; i < rows; i++) { + data[i] = dictionary[(short) index_data[i]]; + } } + else { + for (int i = 0; i < rows; i++) { + data[i] = dictionary[(int) index_data[i]]; + } + } return data; } }