westonpace commented on code in PR #14956:
URL: https://github.com/apache/arrow/pull/14956#discussion_r1053552922


##########
cpp/src/arrow/engine/substrait/extension_set.cc:
##########
@@ -24,6 +24,7 @@
 #include <sstream>
 #include <unordered_set>
 
+#include "arrow/compute/api.h"

Review Comment:
   We try to avoid including `/api.h` files internally as they tend to be quite 
large and increase compilation times.  Instead we prefer many smaller includes. 
 The `api.h` files are for external use and also to help up distinguish public 
API from private API.



##########
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:
   Probably a moot point since it seems `s` will remain a value argument (and 
not an option) but the general philosophy is that, if a call might raise an 
exception like that, we need to check externally to ensure it does not.  Arrow 
code should not raise exceptions.
   
   We have a suite of string to value parsing functions though.  Should you 
encounter this in the future the functions in `src/arrow/util/value_parsing.h` 
should come in handy.  In particular I think this could be a call to 
`arrow::internal::ParseValue<Int64Type>`



##########
cpp/src/arrow/engine/substrait/extension_set.cc:
##########
@@ -670,10 +671,10 @@ struct ExtensionIdRegistryImpl : ExtensionIdRegistry {
 template <typename Enum>
 class EnumParser {
  public:
-  explicit EnumParser(const std::vector<std::string>& options) {
+  explicit EnumParser(const std::vector<std::string>& options, int offset) {

Review Comment:
   This is a good cleanup.  However, the need for `kUnspecified` came from a 
time when Substrait handled enums differently.  Another potential change, that 
might be simpler, would be to remove `kUnspecified` from the other enums. 



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