|
19 | 19 |
|
20 | 20 | #include <iostream> |
21 | 21 |
|
| 22 | +#include "iceberg/arrow/arrow_file_io.h" |
22 | 23 | #include "iceberg/avro/avro_register.h" |
23 | | -#include "iceberg/file_reader.h" |
| 24 | +#include "iceberg/catalog/in_memory_catalog.h" |
24 | 25 | #include "iceberg/parquet/parquet_register.h" |
| 26 | +#include "iceberg/table.h" |
| 27 | +#include "iceberg/table_scan.h" |
| 28 | + |
| 29 | +int main(int argc, char** argv) { |
| 30 | + if (argc != 4) { |
| 31 | + std::cerr << "Usage: " << argv[0] |
| 32 | + << " <warehouse_location> <table_name> <table_location>" << std::endl; |
| 33 | + return 0; |
| 34 | + } |
| 35 | + |
| 36 | + const std::string warehouse_location = argv[1]; |
| 37 | + const std::string table_name = argv[2]; |
| 38 | + const std::string table_location = argv[3]; |
| 39 | + const std::unordered_map<std::string, std::string> properties; |
25 | 40 |
|
26 | | -int main() { |
27 | 41 | iceberg::avro::RegisterAll(); |
28 | 42 | iceberg::parquet::RegisterAll(); |
29 | | - auto open_result = iceberg::ReaderFactoryRegistry::Open( |
30 | | - iceberg::FileFormatType::kAvro, {.path = "non-existing-file.avro"}); |
31 | | - if (!open_result.has_value()) { |
32 | | - std::cerr << "Failed to open avro file" << std::endl; |
| 43 | + |
| 44 | + auto catalog = iceberg::InMemoryCatalog::Make("test", iceberg::arrow::MakeLocalFileIO(), |
| 45 | + warehouse_location, properties); |
| 46 | + |
| 47 | + auto register_result = catalog->RegisterTable({.name = table_name}, table_location); |
| 48 | + if (!register_result.has_value()) { |
| 49 | + std::cerr << "Failed to register table: " << register_result.error().message |
| 50 | + << std::endl; |
33 | 51 | return 1; |
34 | 52 | } |
| 53 | + |
| 54 | + auto load_result = catalog->LoadTable({.name = table_name}); |
| 55 | + if (!load_result.has_value()) { |
| 56 | + std::cerr << "Failed to load table: " << load_result.error().message << std::endl; |
| 57 | + return 1; |
| 58 | + } |
| 59 | + |
| 60 | + auto table = std::move(load_result.value()); |
| 61 | + auto scan_result = table->NewScan()->Build(); |
| 62 | + if (!scan_result.has_value()) { |
| 63 | + std::cerr << "Failed to build scan: " << scan_result.error().message << std::endl; |
| 64 | + return 1; |
| 65 | + } |
| 66 | + |
| 67 | + auto scan = std::move(scan_result.value()); |
| 68 | + auto plan_result = scan->PlanFiles(); |
| 69 | + if (!plan_result.has_value()) { |
| 70 | + std::cerr << "Failed to plan files: " << plan_result.error().message << std::endl; |
| 71 | + return 1; |
| 72 | + } |
| 73 | + |
| 74 | + std::cout << "Scan tasks: " << std::endl; |
| 75 | + auto scan_tasks = std::move(plan_result.value()); |
| 76 | + for (const auto& scan_task : scan_tasks) { |
| 77 | + std::cout << " - " << scan_task->data_file()->file_path << std::endl; |
| 78 | + } |
| 79 | + |
35 | 80 | return 0; |
36 | 81 | } |
0 commit comments