You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "thisisnic (via GitHub)" <gi...@apache.org> on 2023/02/08 10:30:28 UTC

[GitHub] [arrow] thisisnic commented on a diff in pull request #34050: GH-31910: [C++] Add support for Substrait cast expression

thisisnic commented on code in PR #34050:
URL: https://github.com/apache/arrow/pull/34050#discussion_r1099942179


##########
cpp/src/arrow/engine/substrait/expression_internal.cc:
##########
@@ -320,6 +320,30 @@ Result<compute::Expression> FromProto(const substrait::Expression& expr,
       return function_converter(substrait_call);
     }
 
+    case substrait::Expression::kCast: {
+      const auto& cast_exp = expr.cast();
+      ARROW_ASSIGN_OR_RAISE(auto input,
+                            FromProto(cast_exp.input(), ext_set, conversion_options));
+
+      // need to convert from the Substrait type spec to the relevant Arrow thing
+      // do we need a switch/case or can we just get code similar to the below FromProto?
+      // the type should come from cast_expr.type()
+      
+      // this will be a Result<std::pair<std::shared_ptr<DataType>
+      ARROW_ASSIGN_OR_RAISE(auto type,
+                            FromProto(cast_exp.type(), ext_set, conversion_options));
+
+      if(cast_exp.failure_behavior() == substrait::Expression_Cast_FailureBehavior::Expression_Cast_FailureBehavior_FAILURE_BEHAVIOR_THROW_EXCEPTION){
+        return compute::call("cast", std::move(input), compute::CastOptions::Safe(type));
+      } else if(cast_exp.failure_behavior() == substrait::Expression_Cast_FailureBehavior::Expression_Cast_FailureBehavior_FAILURE_BEHAVIOR_RETURN_NULL){
+
+      // e.g. if unspecified  
+      } else {
+        return compute::call("cast", std::move(input), compute::CastOptions::Unsafe(type));

Review Comment:
   Thanks for highlighting this, I can see that these are different things, so I'll update 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-unsubscribe@arrow.apache.org

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