vibhatha commented on code in PR #14132:
URL: https://github.com/apache/arrow/pull/14132#discussion_r971665499
##########
cpp/src/arrow/engine/substrait/serde_test.cc:
##########
@@ -3078,5 +3089,94 @@ TEST(Substrait, AggregateRelEmit) {
buf, {}, conversion_options);
}
+TEST(Substrait, ReadRelWithGlobFiles) {
+ compute::ExecContext exec_context;
+ arrow::dataset::internal::Initialize();
+
+ auto dummy_schema =
+ schema({field("A", int32()), field("B", int32()), field("C", int32())});
+
+ // creating a dummy dataset using a dummy table
+ auto table_1 = TableFromJSON(dummy_schema, {R"([
+ [1, 1, 10],
+ [3, 4, 20]
+ ])"});
+ auto table_2 = TableFromJSON(dummy_schema, {R"([
+ [11, 11, 110],
+ [13, 14, 120]
+ ])"});
+ auto table_3 = TableFromJSON(dummy_schema, {R"([
+ [21, 21, 210],
+ [23, 24, 220]
+ ])"});
+ auto expected_table = TableFromJSON(dummy_schema, {R"([
+ [1, 1, 10],
+ [3, 4, 20],
+ [11, 11, 110],
+ [13, 14, 120],
+ [21, 21, 210],
+ [23, 24, 220]
+ ])"});
+
+ std::vector<std::shared_ptr<Table>> input_tables = {table_1, table_2,
table_3};
+ auto format = std::make_shared<arrow::dataset::IpcFileFormat>();
+ auto filesystem = std::make_shared<fs::LocalFileSystem>();
+ const std::vector<std::string> file_names = {"serde_test_1.arrow",
"serde_test_2.arrow",
+ "serde_test_3.arrow"};
+
+ const std::string path_prefix = "substrait-globfiles-";
+ std::string glob_like_path;
+ int idx = 0;
+
+ // creating a vector to avoid out-of-scoping Temporary directory
+ // if out-of-scoped the written folder get wiped out
+ std::vector<std::unique_ptr<arrow::internal::TemporaryDir>> tempdirs;
+ for (size_t i = 0; i < file_names.size(); i++) {
+ ASSERT_OK_AND_ASSIGN(auto tempdir,
arrow::internal::TemporaryDir::Make(path_prefix));
+ tempdirs.push_back(std::move(tempdir));
+ }
+ for (const auto& file_name : file_names) {
+ ASSERT_OK_AND_ASSIGN(auto file_path,
tempdirs[idx]->path().Join(file_name));
+ std::string file_path_str = file_path.ToString();
+ WriteIpcData(file_path_str, filesystem, input_tables[idx++]);
+ std::string base_path = file_path_str.substr(0,
file_path_str.find(path_prefix));
+ glob_like_path = "file://" + base_path + path_prefix +
"*/serde_test_*.arrow";
+ }
+
+ ASSERT_OK_AND_ASSIGN(auto buf, internal::SubstraitFromJSON("Plan", R"({
+ "relations": [{
+ "rel": {
+ "read": {
+ "base_schema": {
+ "names": ["A", "B", "C"],
+ "struct": {
+ "types": [{
+ "i32": {}
+ }, {
+ "i32": {}
+ }, {
+ "i32": {}
+ }]
+ }
+ },
+ "local_files": {
+ "items": [
+ {
+ "uri_path_glob": ")" + glob_like_path +
+ R"(",
Review Comment:
I formatted the code, but this is what it produces.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]