EpsilonPrime commented on code in PR #14956:
URL: https://github.com/apache/arrow/pull/14956#discussion_r1049140618
##########
cpp/src/arrow/engine/substrait/extension_set.cc:
##########
@@ -790,6 +797,34 @@ ExtensionIdRegistry::SubstraitCallToArrow
DecodeOptionlessUncheckedArithmetic(
};
}
+ExtensionIdRegistry::SubstraitCallToArrow DecodeRoundingMode(
+ const std::string& function_name) {
+ return [function_name](const SubstraitCall& call) ->
Result<compute::Expression> {
+ ARROW_ASSIGN_OR_RAISE(
+ compute::RoundMode round_mode,
+ ParseOptionOrElse(
+ call, "rounding", kRoundModeParser,
+ {compute::RoundMode::DOWN, compute::RoundMode::UP,
+ compute::RoundMode::TOWARDS_ZERO,
compute::RoundMode::TOWARDS_INFINITY,
+ compute::RoundMode::HALF_DOWN, compute::RoundMode::HALF_UP,
+ compute::RoundMode::HALF_TOWARDS_ZERO,
+ compute::RoundMode::HALF_TOWARDS_INFINITY,
compute::RoundMode::HALF_TO_EVEN,
+ compute::RoundMode::HALF_TO_ODD},
+ compute::RoundMode::HALF_TOWARDS_INFINITY));
+ ARROW_ASSIGN_OR_RAISE(std::vector<compute::Expression> value_args,
+ GetValueArgs(call, 0));
+ std::shared_ptr<compute::RoundOptions> options =
+ std::make_shared<compute::RoundOptions>();
+ std::optional<std::vector<std::string> const*> s_arg = call.GetOption("s");
+ if (s_arg.has_value()) {
+ // Substrait will enforce at least one choice is present so this is safe.
+ options->ndigits = std::stol(s_arg.value()->at(0), NULLPTR, 10);
Review Comment:
The std::stol call can raise an exception if the option is non-numeric or if
the value will overflow ndigits (an int64 value). Do we have a standard way of
checking these values that won't risk an exception?
--
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]