js8544 commented on code in PR #261:
URL: https://github.com/apache/arrow-cookbook/pull/261#discussion_r981124021


##########
cpp/code/basic_arrow.cc:
##########
@@ -70,48 +76,48 @@ TEST(BasicArrow, ReturnNotOk) { ASSERT_OK(ReturnNotOk()); }
 /// Only supports floating point and integral types. Does not support decimals.
 class TableSummation {
   double partial = 0.0;
- public:
 
+ public:
   arrow::Result<double> Compute(std::shared_ptr<arrow::RecordBatch> batch) {
-    for (std::shared_ptr<arrow::Array> array : batch->columns()) {
+    for (const auto& array : batch->columns()) {
       ARROW_RETURN_NOT_OK(arrow::VisitArrayInline(*array, this));
     }
     return partial;
   }
 
   // Default implementation
-  arrow::Status Visit(const arrow::Array& array) {
-    return arrow::Status::NotImplemented("Can not compute sum for array of 
type ",
-                                         array.type()->ToString());
-  }
-
   template <typename ArrayType, typename T = typename ArrayType::TypeClass>
-  arrow::enable_if_number<T, arrow::Status> Visit(const ArrayType& array) {
-    for (arrow::util::optional<typename T::c_type> value : array) {
-      if (value.has_value()) {
-        partial += static_cast<double>(value.value());
+  arrow::Status Visit(const ArrayType& array) {
+    if constexpr (arrow::is_number_type<T>::value) {
+      for (auto value : array) {
+        if (value.has_value()) {
+          partial += static_cast<double>(value.value());
+        }
       }
+      return arrow::Status::OK();
+    } else {
+      return arrow::Status::NotImplemented("Can not compute sum for array of 
type ",
+                                           array.type()->ToString());
     }
-    return arrow::Status::OK();
   }
 };  // TableSummation
 
 arrow::Status VisitorSummationExample() {
   StartRecipe("VisitorSummationExample");
-  std::shared_ptr<arrow::Schema> schema = arrow::schema({

Review Comment:
   I see. I've reverted most `auto`s in f069a5be4d6544e26edd6735823e7d0442c87564



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