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


##########
cpp/src/arrow/engine/substrait/relation_internal.cc:
##########
@@ -771,6 +808,42 @@ Result<std::unique_ptr<substrait::FilterRel>> 
FilterRelationConverter(
   return std::move(filter_rel);
 }
 
+Result<std::unique_ptr<substrait::ProjectRel>> ProjectRelationConverter(
+    const std::shared_ptr<Schema>& schema, const compute::Declaration& 
declaration,
+    ExtensionSet* ext_set, const ConversionOptions& conversion_options) {
+  auto project_rel = std::make_unique<substrait::ProjectRel>();
+  const auto& project_node_options =
+      checked_cast<const compute::ProjectNodeOptions&>(*declaration.options);
+  const auto& expressions = project_node_options.expressions;
+  if (declaration.inputs.size() == 0) {
+    return Status::Invalid("Project node doesn't have an input.");
+  }
+
+  // handling input
+  auto declr_input = declaration.inputs[0];
+  ARROW_ASSIGN_OR_RAISE(
+      auto input_rel,
+      ToProto(std::get<compute::Declaration>(declr_input), ext_set, 
conversion_options));
+
+  for (const auto& expr : expressions) {
+    compute::Expression bound_expression;
+    if (!expr.IsBound()) {
+      ARROW_ASSIGN_OR_RAISE(bound_expression, expr.Bind(*schema));
+    }
+    ARROW_ASSIGN_OR_RAISE(auto subs_expr,
+                          ToProto(bound_expression, ext_set, 
conversion_options));
+    project_rel->mutable_expressions()->AddAllocated(subs_expr.release());
+  }
+  project_rel->set_allocated_input(input_rel.release());
+
+  // set an emit to only output the result of the expressions passed in
+  std::vector<int> emit_fields(expressions.size());
+  std::iota(emit_fields.begin(), emit_fields.end(), schema->num_fields() - 1);

Review Comment:
   Thank you for catching 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: github-unsubscr...@arrow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to