|
2 | 2 | #include <dlfcn.h> |
3 | 3 | #include <iostream> |
4 | 4 | #include <memory> |
| 5 | +#include <stdexcept> |
5 | 6 | #include <string> |
| 7 | +#include <vector> |
6 | 8 |
|
7 | 9 | #include <cudf/column/column.hpp> |
8 | 10 | #include <cudf/column/column_view.hpp> |
@@ -152,27 +154,33 @@ int run_check(const char *library_path) { |
152 | 154 | } |
153 | 155 | } |
154 | 156 |
|
155 | | - // Convert to cuDF column view using from_arrow_device_column |
156 | | - std::cout << "\nConverting to cuDF column view...\n"; |
| 157 | + std::cout << "\nConverting to cuDF table view...\n"; |
157 | 158 | try { |
158 | 159 | auto table = cudf::from_arrow_device(&schema, &device_array); |
159 | 160 |
|
160 | 161 | std::cout << "Conversion successful!\n\n"; |
161 | 162 |
|
162 | | - // convert to host array, call the verifier inside of the shared library. |
| 163 | + // Round-trip to host Arrow and validate in the producer library. |
163 | 164 | auto host_array = cudf::to_arrow_host(*table); |
164 | | - auto host_metadata = std::vector<cudf::column_metadata>{ |
165 | | - cudf::column_metadata{"prims"}, |
166 | | - cudf::column_metadata{"decimals"}, |
167 | | - cudf::column_metadata{"strings"}, |
168 | | - cudf::column_metadata{"dates"}, |
169 | | - }; |
| 165 | + auto host_metadata = std::vector<cudf::column_metadata>{}; |
| 166 | + auto const num_columns = table->num_columns(); |
| 167 | + if (schema.n_children != num_columns || schema.children == nullptr) { |
| 168 | + throw std::runtime_error("exported schema does not match imported table"); |
| 169 | + } |
| 170 | + host_metadata.reserve(num_columns); |
| 171 | + for (auto i = 0; i < num_columns; ++i) { |
| 172 | + auto const child_schema = schema.children[i]; |
| 173 | + if (child_schema == nullptr || child_schema->name == nullptr) { |
| 174 | + throw std::runtime_error("exported schema child is missing a name"); |
| 175 | + } |
| 176 | + host_metadata.push_back(cudf::column_metadata{child_schema->name}); |
| 177 | + } |
170 | 178 | auto host_schema = cudf::to_arrow_schema(*table, host_metadata); |
171 | 179 | if (validate_array(host_schema.get(), &host_array->array) != 0) { |
172 | | - std::cerr << "\nValidation failed!\n"; |
| 180 | + throw std::runtime_error("validation failed"); |
173 | 181 | } |
174 | 182 | } catch (const std::exception &e) { |
175 | | - std::cerr << "Error: Failed to convert Arrow array to cuDF column: " << e.what() << "\n"; |
| 183 | + std::cerr << "Error: Failed to validate Arrow device export with cuDF: " << e.what() << "\n"; |
176 | 184 |
|
177 | 185 | // Release the Arrow array |
178 | 186 | if (device_array.array.release) { |
|
0 commit comments