| 372 | namespace { |
| 373 | |
| 374 | Status WriteBatch( |
| 375 | std::shared_ptr<RecordBatch> batch, compute::Expression guarantee, |
| 376 | FileSystemDatasetWriteOptions write_options, |
| 377 | std::function<Status(std::shared_ptr<RecordBatch>, const PartitionPathFormat&)> |
| 378 | write) { |
| 379 | ARROW_ASSIGN_OR_RAISE(auto groups, write_options.partitioning->Partition(batch)); |
| 380 | batch.reset(); // drop to hopefully conserve memory |
| 381 | |
| 382 | if (write_options.max_partitions <= 0) { |
| 383 | return Status::Invalid("max_partitions must be positive (was ", |
| 384 | write_options.max_partitions, ")"); |
| 385 | } |
| 386 | |
| 387 | if (groups.batches.size() > static_cast<size_t>(write_options.max_partitions)) { |
| 388 | return Status::Invalid("Fragment would be written into ", groups.batches.size(), |
| 389 | " partitions. This exceeds the maximum of ", |
| 390 | write_options.max_partitions); |
| 391 | } |
| 392 | |
| 393 | for (std::size_t index = 0; index < groups.batches.size(); index++) { |
| 394 | auto partition_expression = and_(groups.expressions[index], guarantee); |
| 395 | auto next_batch = groups.batches[index]; |
| 396 | PartitionPathFormat destination; |
| 397 | ARROW_ASSIGN_OR_RAISE(destination, |
| 398 | write_options.partitioning->Format(partition_expression)); |
| 399 | RETURN_NOT_OK(write(next_batch, destination)); |
| 400 | } |
| 401 | return Status::OK(); |
| 402 | } |
| 403 | |
| 404 | class DatasetWritingSinkNodeConsumer : public acero::SinkNodeConsumer { |
| 405 | public: |