|
19 | 19 |
|
20 | 20 | package org.apache.iotdb.db.pipe.event.common.tsfile.container.scan; |
21 | 21 |
|
| 22 | +import org.apache.tsfile.common.constant.TsFileConstant; |
22 | 23 | import org.apache.tsfile.compress.IUnCompressor; |
23 | 24 | import org.apache.tsfile.encoding.decoder.Decoder; |
24 | 25 | import org.apache.tsfile.enums.TSDataType; |
@@ -159,22 +160,44 @@ static List<Long> toSuffixMaxList(final List<Long> pageEstimatedMemoryUsageInByt |
159 | 160 | static long estimatePageMemoryUsageInBytesWithBatchData( |
160 | 161 | final PageHeader timePageHeader, |
161 | 162 | final Chunk timeChunk, |
162 | | - final List<TSDataType> valueDataTypeList) { |
| 163 | + final List<TSDataType> valueDataTypeList) |
| 164 | + throws IOException { |
163 | 165 | return estimatePageMemoryUsageInBytesWithBatchData( |
164 | 166 | timePageHeader.getUncompressedSize(), |
165 | 167 | getPageRowCount(timePageHeader, timeChunk), |
166 | 168 | valueDataTypeList); |
167 | 169 | } |
168 | 170 |
|
169 | | - static int getPageRowCount(final PageHeader pageHeader, final Chunk chunk) { |
| 171 | + static int getPageRowCount(final PageHeader pageHeader, final Chunk chunk) throws IOException { |
170 | 172 | if (isSinglePageChunk(chunk.getHeader())) { |
171 | | - return Objects.isNull(chunk.getChunkStatistic()) |
172 | | - ? 0 |
173 | | - : saturateToInt(chunk.getChunkStatistic().getCount()); |
| 173 | + if (Objects.nonNull(chunk.getChunkStatistic())) { |
| 174 | + return saturateToInt(chunk.getChunkStatistic().getCount()); |
| 175 | + } |
| 176 | + return isTimeChunk(chunk.getHeader()) ? countSinglePageTimeValues(chunk) : 0; |
174 | 177 | } |
175 | 178 | return saturateToInt(pageHeader.getNumOfValues()); |
176 | 179 | } |
177 | 180 |
|
| 181 | + private static int countSinglePageTimeValues(final Chunk chunk) throws IOException { |
| 182 | + final ByteBuffer chunkDataBuffer = chunk.getData().duplicate(); |
| 183 | + final PageHeader pageHeader = deserializePageHeader(chunkDataBuffer, chunk.getHeader()); |
| 184 | + final ByteBuffer pageData = deserializePageData(pageHeader, chunkDataBuffer, chunk.getHeader()); |
| 185 | + final Decoder decoder = |
| 186 | + Decoder.getDecoderByType(chunk.getHeader().getEncodingType(), TSDataType.INT64); |
| 187 | + |
| 188 | + int rowCount = 0; |
| 189 | + while (decoder.hasNext(pageData)) { |
| 190 | + decoder.readLong(pageData); |
| 191 | + ++rowCount; |
| 192 | + } |
| 193 | + return rowCount; |
| 194 | + } |
| 195 | + |
| 196 | + private static boolean isTimeChunk(final ChunkHeader chunkHeader) { |
| 197 | + return (chunkHeader.getChunkType() & TsFileConstant.TIME_COLUMN_MASK) |
| 198 | + == TsFileConstant.TIME_COLUMN_MASK; |
| 199 | + } |
| 200 | + |
178 | 201 | private static int saturateToInt(final long value) { |
179 | 202 | return (int) Math.min(Integer.MAX_VALUE, value); |
180 | 203 | } |
|
0 commit comments