milesgranger commented on code in PR #14326:
URL: https://github.com/apache/arrow/pull/14326#discussion_r997391097


##########
cpp/src/arrow/dataset/scanner_test.cc:
##########
@@ -1074,6 +1074,24 @@ TEST_P(TestScanner, ProjectedScanNested) {
   AssertScanBatchesUnorderedEqualRepetitionsOf(MakeScanner(batch_in), 
batch_out);
 }
 
+TEST_P(TestScanner, ProjectedScanNestedFromNames) {
+  SetSchema({
+      field("struct", struct_({field("i32", int32()), field("f64", 
float64())})),
+      field("nested", struct_({field("left", int32()),
+                               field("right", struct_({field("i32", int32()),
+                                                       field("f64", 
float64())}))})),
+  });
+  ASSERT_OK_AND_ASSIGN(auto descr,
+                       ProjectionDescr::FromNames({"struct.i32", 
"nested.right.f64"},
+                                                  *options_->dataset_schema))
+  SetProjection(options_.get(), std::move(descr));
+  auto batch_in = ConstantArrayGenerator::Zeroes(GetParam().items_per_batch, 
schema_);
+  auto batch_out = ConstantArrayGenerator::Zeroes(
+      GetParam().items_per_batch,
+      schema({field("struct.i32", int32()), field("nested.right.f64", 
float64())}));

Review Comment:
   Ya...we do the field name renaming on python, and then in C++ it's left with 
whatever the dotted path was. Do you think we should move the field renaming 
into C++ instead?



##########
cpp/src/arrow/dataset/scanner.cc:
##########
@@ -751,7 +751,19 @@ Result<ProjectionDescr> 
ProjectionDescr::FromNames(std::vector<std::string> name
                                                    const Schema& 
dataset_schema) {
   std::vector<compute::Expression> exprs(names.size());
   for (size_t i = 0; i < exprs.size(); ++i) {
-    exprs[i] = compute::field_ref(names[i]);
+    // If name isn't in schema, try finding it by dotted path.
+    if (dataset_schema.GetFieldByName(names[i]) == nullptr) {
+      auto name = names[i];
+      if (name.rfind(".", 0) != 0) {
+        name = "." + name;
+      }
+      ARROW_ASSIGN_OR_RAISE(auto field_ref, FieldRef::FromDotPath(name));
+      // safe as we know there is at least 1 dot.
+      names[i] = name.substr(name.rfind(".") + 1);
+      exprs[i] = compute::field_ref(field_ref);

Review Comment:
   That's true, except `compute::field_ref` returns an `Expression` from a 
`FieldRef`'; which is the vector type of `exprs`.



-- 
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]

Reply via email to