| 156 | } // namespace |
| 157 | |
| 158 | ArrayVectorPtr VectorMaker::arrayOfRowVector( |
| 159 | const RowTypePtr& rowType, |
| 160 | const std::vector<std::vector<variant>>& data) { |
| 161 | vector_size_t size = data.size(); |
| 162 | BufferPtr offsets = AlignedBuffer::allocate<vector_size_t>(size, pool_); |
| 163 | BufferPtr sizes = AlignedBuffer::allocate<vector_size_t>(size, pool_); |
| 164 | |
| 165 | auto rawOffsets = offsets->asMutable<vector_size_t>(); |
| 166 | auto rawSizes = sizes->asMutable<vector_size_t>(); |
| 167 | |
| 168 | // Count number of elements. |
| 169 | vector_size_t numElements = 0; |
| 170 | for (const auto& array : data) { |
| 171 | numElements += array.size(); |
| 172 | } |
| 173 | |
| 174 | // Create the underlying vector. |
| 175 | auto rowVector = std::dynamic_pointer_cast<RowVector>( |
| 176 | BaseVector::create(rowType, numElements, pool_)); |
| 177 | for (auto& field : rowVector->children()) { |
| 178 | field->resize(numElements); |
| 179 | } |
| 180 | |
| 181 | vector_size_t currentIdx = 0; |
| 182 | for (const auto& arrayValue : data) { |
| 183 | *rawSizes++ = arrayValue.size(); |
| 184 | *rawOffsets++ = currentIdx; |
| 185 | |
| 186 | for (auto arrayElement : arrayValue) { |
| 187 | if (arrayElement.isNull()) { |
| 188 | rowVector->setNull(currentIdx, true); |
| 189 | } else { |
| 190 | for (auto i = 0; i < rowType->size(); i++) { |
| 191 | const auto& value = arrayElement.row()[i]; |
| 192 | if (value.isNull()) { |
| 193 | rowVector->childAt(i)->setNull(currentIdx, true); |
| 194 | } else { |
| 195 | BOLT_DYNAMIC_SCALAR_TYPE_DISPATCH( |
| 196 | setNotNullValue, |
| 197 | rowType->childAt(i)->kind(), |
| 198 | rowVector->childAt(i), |
| 199 | currentIdx, |
| 200 | value); |
| 201 | } |
| 202 | } |
| 203 | } |
| 204 | currentIdx++; |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | return std::make_shared<ArrayVector>( |
| 209 | pool_, |
| 210 | ARRAY(rowType), |
| 211 | nullptr, |
| 212 | size, |
| 213 | offsets, |
| 214 | sizes, |
| 215 | std::move(rowVector), |