Callable object for parsing/converting individual JSON blocks. The class itself can be called concurrently but reads from the `DecodeContext` aren't synchronized
| 300 | // Callable object for parsing/converting individual JSON blocks. The class itself can be |
| 301 | // called concurrently but reads from the `DecodeContext` aren't synchronized |
| 302 | class DecodingOperator { |
| 303 | public: |
| 304 | explicit DecodingOperator(std::shared_ptr<const DecodeContext> context) |
| 305 | : context_(std::move(context)) {} |
| 306 | |
| 307 | Result<DecodedBlock> operator()(const ChunkedBlock& block) const { |
| 308 | int64_t num_bytes; |
| 309 | ARROW_ASSIGN_OR_RAISE(auto unconverted, ParseBlock(block, context_->parse_options(), |
| 310 | context_->pool(), &num_bytes)); |
| 311 | |
| 312 | std::shared_ptr<ChunkedArrayBuilder> builder; |
| 313 | RETURN_NOT_OK(MakeChunkedArrayBuilder(TaskGroup::MakeSerial(), context_->pool(), |
| 314 | context_->promotion_graph(), |
| 315 | context_->conversion_type(), &builder)); |
| 316 | builder->Insert(0, field("", unconverted->type()), unconverted); |
| 317 | |
| 318 | std::shared_ptr<ChunkedArray> chunked; |
| 319 | RETURN_NOT_OK(builder->Finish(&chunked)); |
| 320 | ARROW_ASSIGN_OR_RAISE( |
| 321 | auto batch, RecordBatch::FromStructArray(chunked->chunk(0), context_->pool())); |
| 322 | |
| 323 | return DecodedBlock{std::move(batch), num_bytes}; |
| 324 | } |
| 325 | |
| 326 | private: |
| 327 | std::shared_ptr<const DecodeContext> context_; |
| 328 | }; |
| 329 | |
| 330 | // Reads from a source iterator, completes the subsequent decode task on the calling |
| 331 | // thread. This is only really used for compatibility with the async pipeline when CPU |