Skip to content

Commit beace6c

Browse files
committed
Optimize retained memory size calculation for getRegion method of BinaryColumn
1 parent a608201 commit beace6c

File tree

1 file changed

+30
-1
lines changed
  • java/tsfile/src/main/java/org/apache/tsfile/read/common/block/column

1 file changed

+30
-1
lines changed

java/tsfile/src/main/java/org/apache/tsfile/read/common/block/column/BinaryColumn.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,34 @@ public BinaryColumn(int positionCount, Optional<boolean[]> valueIsNull, Binary[]
7878
retainedSizeInBytes = INSTANCE_SIZE + sizeOfBooleanArray(positionCount) + sizeOf(values);
7979
}
8080

81+
// called by getRegion which already knows the underlying retainedSizeInBytes
82+
private BinaryColumn(
83+
int arrayOffset,
84+
int positionCount,
85+
boolean[] valueIsNull,
86+
Binary[] values,
87+
long retainedSizeInBytes) {
88+
if (arrayOffset < 0) {
89+
throw new IllegalArgumentException("arrayOffset is negative");
90+
}
91+
this.arrayOffset = arrayOffset;
92+
if (positionCount < 0) {
93+
throw new IllegalArgumentException("positionCount is negative");
94+
}
95+
this.positionCount = positionCount;
96+
97+
if (values.length - arrayOffset < positionCount) {
98+
throw new IllegalArgumentException("values length is less than positionCount");
99+
}
100+
this.values = values;
101+
102+
if (valueIsNull != null && valueIsNull.length - arrayOffset < positionCount) {
103+
throw new IllegalArgumentException("isNull length is less than positionCount");
104+
}
105+
this.valueIsNull = valueIsNull;
106+
this.retainedSizeInBytes = retainedSizeInBytes;
107+
}
108+
81109
@Override
82110
public TSDataType getDataType() {
83111
return TSDataType.TEXT;
@@ -141,7 +169,8 @@ public long getRetainedSizeInBytes() {
141169
@Override
142170
public Column getRegion(int positionOffset, int length) {
143171
checkValidRegion(getPositionCount(), positionOffset, length);
144-
return new BinaryColumn(positionOffset + arrayOffset, length, valueIsNull, values);
172+
return new BinaryColumn(
173+
positionOffset + arrayOffset, length, valueIsNull, values, getRetainedSizeInBytes());
145174
}
146175

147176
@Override

0 commit comments

Comments
 (0)