TODO : handle complex vectors (list/map/..)
| 186 | |
| 187 | // TODO : handle complex vectors (list/map/..) |
| 188 | Status Projector::AllocArrayData(const DataTypePtr& type, int64_t num_records, |
| 189 | arrow::MemoryPool* pool, |
| 190 | ArrayDataPtr* array_data) const { |
| 191 | arrow::Status astatus; |
| 192 | std::vector<std::shared_ptr<arrow::Buffer>> buffers; |
| 193 | |
| 194 | // The output vector always has a null bitmap. |
| 195 | int64_t size = arrow::bit_util::BytesForBits(num_records); |
| 196 | ARROW_ASSIGN_OR_RAISE(auto bitmap_buffer, arrow::AllocateBuffer(size, pool)); |
| 197 | buffers.push_back(std::move(bitmap_buffer)); |
| 198 | |
| 199 | // String/Binary vectors have an offsets array. |
| 200 | auto type_id = type->id(); |
| 201 | if (arrow::is_binary_like(type_id)) { |
| 202 | auto offsets_len = arrow::bit_util::BytesForBits((num_records + 1) * 32); |
| 203 | |
| 204 | ARROW_ASSIGN_OR_RAISE(auto offsets_buffer, arrow::AllocateBuffer(offsets_len, pool)); |
| 205 | buffers.push_back(std::move(offsets_buffer)); |
| 206 | } |
| 207 | |
| 208 | // The output vector always has a data array. |
| 209 | int64_t data_len; |
| 210 | if (arrow::is_primitive(type_id) || type_id == arrow::Type::DECIMAL) { |
| 211 | const auto& fw_type = static_cast<const arrow::FixedWidthType&>(*type); |
| 212 | data_len = arrow::bit_util::BytesForBits(num_records * fw_type.bit_width()); |
| 213 | } else if (arrow::is_binary_like(type_id)) { |
| 214 | // we don't know the expected size for varlen output vectors. |
| 215 | data_len = 0; |
| 216 | } else { |
| 217 | return Status::Invalid("Unsupported output data type " + type->ToString()); |
| 218 | } |
| 219 | ARROW_ASSIGN_OR_RAISE(auto data_buffer, arrow::AllocateResizableBuffer(data_len, pool)); |
| 220 | |
| 221 | // This is not strictly required but valgrind gets confused and detects this |
| 222 | // as uninitialized memory access. See arrow::util::SetBitTo(). |
| 223 | if (type->id() == arrow::Type::BOOL) { |
| 224 | memset(data_buffer->mutable_data(), 0, data_len); |
| 225 | } |
| 226 | buffers.push_back(std::move(data_buffer)); |
| 227 | |
| 228 | *array_data = arrow::ArrayData::Make(type, num_records, std::move(buffers)); |
| 229 | return Status::OK(); |
| 230 | } |
| 231 | |
| 232 | Status Projector::ValidateEvaluateArgsCommon(const arrow::RecordBatch& batch) const { |
| 233 | ARROW_RETURN_IF(!batch.schema()->Equals(*schema_), |
nothing calls this directly
no test coverage detected