| 1053 | } |
| 1054 | |
| 1055 | std::vector<std::unique_ptr<ColumnChunkData>> ColumnChunkData::split(bool targetMaxSize) const { |
| 1056 | // FIXME(bmwinger): we either need to split recursively, or detect individual values which bring |
| 1057 | // the size above MAX_SEGMENT_SIZE, since this will still sometimes produce segments larger than |
| 1058 | // MAX_SEGMENT_SIZE |
| 1059 | auto maxSegmentSize = std::max(getMinimumSizeOnDisk(), common::StorageConfig::MAX_SEGMENT_SIZE); |
| 1060 | auto targetSize = |
| 1061 | targetMaxSize ? maxSegmentSize : std::min(getSizeOnDisk() / 2, maxSegmentSize); |
| 1062 | std::vector<std::unique_ptr<ColumnChunkData>> newSegments; |
| 1063 | uint64_t pos = 0; |
| 1064 | const uint64_t chunkSize = 64; |
| 1065 | uint64_t initialCapacity = std::min(chunkSize, numValues); |
| 1066 | while (pos < numValues) { |
| 1067 | std::unique_ptr<ColumnChunkData> newSegment = |
| 1068 | ColumnChunkFactory::createColumnChunkData(getMemoryManager(), getDataType().copy(), |
| 1069 | isCompressionEnabled(), initialCapacity, ResidencyState::IN_MEMORY, hasNullData()); |
| 1070 | |
| 1071 | while (pos < numValues && newSegment->getSizeOnDiskInMemoryStats() <= targetSize) { |
| 1072 | if (newSegment->getNumValues() == newSegment->getCapacity()) { |
| 1073 | newSegment->resize(newSegment->getCapacity() * 2); |
| 1074 | } |
| 1075 | auto numValuesToAppendInChunk = std::min(numValues - pos, chunkSize); |
| 1076 | newSegment->append(this, pos, numValuesToAppendInChunk); |
| 1077 | pos += numValuesToAppendInChunk; |
| 1078 | } |
| 1079 | if (pos < numValues && newSegment->getNumValues() > chunkSize) { |
| 1080 | // Size exceeded target size, so we should drop the last batch added (unless they are |
| 1081 | // the only values) |
| 1082 | pos -= chunkSize; |
| 1083 | newSegment->truncate(newSegment->getNumValues() - chunkSize); |
| 1084 | } |
| 1085 | newSegments.push_back(std::move(newSegment)); |
| 1086 | } |
| 1087 | return newSegments; |
| 1088 | } |
| 1089 | |
| 1090 | void ColumnChunkData::setNullData(std::unique_ptr<NullChunkData> nullData_) { |
| 1091 | nullData = std::move(nullData_); |
no test coverage detected