| 459 | |
| 460 | template <typename Range> |
| 461 | Status TupleRangeFromTable(const Table& table, const compute::CastOptions& cast_options, |
| 462 | compute::ExecContext* ctx, Range* rows) { |
| 463 | using row_type = typename std::decay<decltype(*std::begin(*rows))>::type; |
| 464 | constexpr std::size_t n_columns = std::tuple_size<row_type>::value; |
| 465 | |
| 466 | if (table.schema()->num_fields() != n_columns) { |
| 467 | return Status::Invalid( |
| 468 | "Number of columns in the table does not match the width of the target: ", |
| 469 | table.schema()->num_fields(), " != ", n_columns); |
| 470 | } |
| 471 | |
| 472 | if (std::size(*rows) != static_cast<size_t>(table.num_rows())) { |
| 473 | return Status::Invalid( |
| 474 | "Number of rows in the table does not match the size of the target: ", |
| 475 | table.num_rows(), " != ", std::size(*rows)); |
| 476 | } |
| 477 | |
| 478 | // Check that all columns have the correct type, otherwise cast them. |
| 479 | std::shared_ptr<Table> table_owner; |
| 480 | std::reference_wrapper<const ::arrow::Table> current_table(table); |
| 481 | |
| 482 | ARROW_RETURN_NOT_OK(internal::EnsureColumnTypes<row_type>::Cast( |
| 483 | table, &table_owner, cast_options, ctx, ¤t_table)); |
| 484 | |
| 485 | internal::TupleSetter<Range, row_type>::Fill(current_table.get(), rows); |
| 486 | |
| 487 | return Status::OK(); |
| 488 | } |
| 489 | |
| 490 | } // namespace stl |
| 491 | } // namespace arrow |