Skip to content

Commit

Permalink
code revise-improve speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Jasmine-ge committed Jul 22, 2024
1 parent 7b1f7af commit f4f1c96
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -43,6 +45,7 @@ public class DataTypeLowCardinality implements IDataType<Object, Object> {
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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()) {
Expand All @@ -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;
}
}
Expand Down

0 comments on commit f4f1c96

Please sign in to comment.