vibhatha commented on code in PR #13914:
URL: https://github.com/apache/arrow/pull/13914#discussion_r959747818


##########
cpp/src/arrow/engine/substrait/relation_internal.cc:
##########
@@ -248,19 +286,56 @@ Result<DeclarationInfo> FromProto(const substrait::Rel& 
rel, const ExtensionSet&
       for (int i = 0; i < input.num_columns; i++) {
         expressions.emplace_back(compute::field_ref(FieldRef(i)));
       }
+      std::vector<std::shared_ptr<Field>> 
new_fields(project.expressions().size());
+      int i = 0;
+      auto project_schema = input.output_schema;
       for (const auto& expr : project.expressions()) {
-        expressions.emplace_back();
-        ARROW_ASSIGN_OR_RAISE(expressions.back(),
+        ARROW_ASSIGN_OR_RAISE(compute::Expression des_expr,
                               FromProto(expr, ext_set, conversion_options));
+        auto bound_expr = des_expr.Bind(*input.output_schema);
+        if (auto* expr_call = bound_expr->call()) {
+          new_fields[i] = field(expr_call->function_name,
+                                
expr_call->kernel->signature->out_type().type());
+        } else if (auto* field_ref = des_expr.field_ref()) {
+          ARROW_ASSIGN_OR_RAISE(FieldPath field_path,
+                                field_ref->FindOne(*input.output_schema));
+          ARROW_ASSIGN_OR_RAISE(new_fields[i], 
field_path.Get(*input.output_schema));
+        } else if (auto* literal = des_expr.literal()) {
+          new_fields[i] =
+              field("field_" + std::to_string(input.num_columns + i), 
literal->type());
+        }
+        i++;
+        expressions.emplace_back(des_expr);
+      }
+      while (!new_fields.empty()) {
+        auto field = new_fields.back();
+        ARROW_ASSIGN_OR_RAISE(
+            project_schema,
+            project_schema->AddField(
+                input.num_columns + static_cast<int>(new_fields.size()) - 1,
+                std::move(field)));
+        new_fields.pop_back();

Review Comment:
   Thanks for noting this one. Redundant and I missed this. 



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