bakaid commented on a change in pull request #732: MINIFICPP-1013
URL: https://github.com/apache/nifi-minifi-cpp/pull/732#discussion_r379325208
 
 

 ##########
 File path: extensions/sql/data/MaxCollector.h
 ##########
 @@ -0,0 +1,155 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <string>
+#include <unordered_map>
+#include <tuple>
+
+#include "SQLRowSubscriber.h"
+
+namespace org {
+namespace apache {
+namespace nifi {
+namespace minifi {
+namespace sql {
+
+class MaxCollector: public SQLRowSubscriber {
+  void beginProcessRow() override {}
+
+  void endProcessRow() override {
+    if (columnsVerified_) {
+      return;
+    }
+
+    if (countColumns_ != mapState_.size())
+      throw minifi::Exception(PROCESSOR_EXCEPTION, "MaxCollector: Column(s) '" 
+ maxValueColumnNames_ + "' are not found in the columns of '" + selectQuery_ + 
"' result.");
+
+    columnsVerified_ = true;
+  }
+
+  void processColumnName(const std::string& name) override {
+    if (columnsVerified_) {
+      return;
+    }
+
+    if (mapState_.count(name)) {
+      countColumns_++;
+    }
+  }
+
+  void processColumn(const std::string& name, const std::string& value)  
override {
+    updateMaxValue(name, '\'' + value + '\'');
+  }
+
+  void processColumn(const std::string& name, double value) override {
+    updateMaxValue(name, value);
+  }
+
+  void processColumn(const std::string& name, int value) override {
+    updateMaxValue(name, value);
+  }
+
+  void processColumn(const std::string& name, long long value) override {
+    updateMaxValue(name, value);
+  }
+
+  void processColumn(const std::string& name, unsigned long long value) 
override {
+    updateMaxValue(name, value);
+  }
+
+  void processColumn(const std::string& name, const char* value) override {}
+
+  template <typename T>
+  struct MaxValue {
+    void updateMaxValue(const std::string& name, const T& value) {
+      const auto it = mapColumnNameValue_.find(name);
+      if (it == mapColumnNameValue_.end()) {
+        mapColumnNameValue_.insert({ name, value });
+      } else {
+        if (value > it->second) {
+          it->second = value;
+        }
+      }
+    }
+
+    std::unordered_map<std::string, T> mapColumnNameValue_;
+  };
+
+  template <typename Tuple, int Index>
+  struct UpdateMapState {
+    UpdateMapState(const Tuple& tpl, std::unordered_map<std::string, 
std::string>& mapState) {
+      for (auto& el : mapState) {
+        const auto& maxVal = std::get<Index>(tpl);
+
+        const auto it = maxVal.mapColumnNameValue_.find(el.first);
+        if (it != maxVal.mapColumnNameValue_.end()) {
+          std::stringstream ss;
+          ss << it->second;
+          el.second = ss.str();
+        }
+      }
+
+      UpdateMapState<Tuple, Index - 1>(tpl, mapState);
 
 Review comment:
   Build fails on macOS with:
   ```
   
/Users/danielbakai/nifi-minifi-cpp/extensions/sql/./data/MaxCollector.h:109:40: 
error: cannot pass object
         of non-trivial type 'const
         
org::apache::nifi::minifi::sql::MaxCollector::MaxValues<std::__1::basic_string<char>,
 double, int,
         long long, unsigned long long>' through variadic constructor; call 
will abort at runtime
         [-Wnon-pod-varargs]
         UpdateMapState<Tuple, Index - 1>(tpl, mapState);
                                          ^
   ```
   
   And on Linux with clang with:
   ```
   In file included from 
/home/bakaid/nifi-minifi-cpp/extensions/sql/processors/QueryDatabaseTable.cpp:47:
   /home/bakaid/nifi-minifi-cpp/extensions/sql/./data/MaxCollector.h:109:40: 
error: cannot pass object of non-trivial type 'const
         
org::apache::nifi::minifi::sql::MaxCollector::MaxValues<std::__cxx11::basic_string<char>,
 double, int, long long, unsigned long long>' through variadic constructor; 
call will
         abort at runtime [-Wnon-pod-varargs]
         UpdateMapState<Tuple, Index - 1>(tpl, mapState);
                                          ^
   /home/bakaid/nifi-minifi-cpp/extensions/sql/./data/MaxCollector.h:109:7: 
note: in instantiation of member function
         
'org::apache::nifi::minifi::sql::MaxCollector::UpdateMapState<org::apache::nifi::minifi::sql::MaxCollector::MaxValues<std::__cxx11::basic_string<char>,
 double, int, long long,
         unsigned long long>, 0>::UpdateMapState' requested here
         UpdateMapState<Tuple, Index - 1>(tpl, mapState);
         ^
   /home/bakaid/nifi-minifi-cpp/extensions/sql/./data/MaxCollector.h:109:7: 
note: in instantiation of member function
         
'org::apache::nifi::minifi::sql::MaxCollector::UpdateMapState<org::apache::nifi::minifi::sql::MaxCollector::MaxValues<std::__cxx11::basic_string<char>,
 double, int, long long,
         unsigned long long>, 1>::UpdateMapState' requested here
   /home/bakaid/nifi-minifi-cpp/extensions/sql/./data/MaxCollector.h:109:7: 
note: in instantiation of member function
         
'org::apache::nifi::minifi::sql::MaxCollector::UpdateMapState<org::apache::nifi::minifi::sql::MaxCollector::MaxValues<std::__cxx11::basic_string<char>,
 double, int, long long,
         unsigned long long>, 2>::UpdateMapState' requested here
   /home/bakaid/nifi-minifi-cpp/extensions/sql/./data/MaxCollector.h:109:7: 
note: in instantiation of member function
         
'org::apache::nifi::minifi::sql::MaxCollector::UpdateMapState<org::apache::nifi::minifi::sql::MaxCollector::MaxValues<std::__cxx11::basic_string<char>,
 double, int, long long,
         unsigned long long>, 3>::UpdateMapState' requested here
   /home/bakaid/nifi-minifi-cpp/extensions/sql/./data/MaxCollector.h:137:5: 
note: in instantiation of member function
         
'org::apache::nifi::minifi::sql::MaxCollector::UpdateMapState<org::apache::nifi::minifi::sql::MaxCollector::MaxValues<std::__cxx11::basic_string<char>,
 double, int, long long,
         unsigned long long>, 4>::UpdateMapState' requested here
       UpdateMapState<decltype(maxValues_), decltype(maxValues_)::size - 
1>(maxValues_, mapState_);
       ^
   /home/bakaid/nifi-minifi-cpp/extensions/sql/./data/MaxCollector.h:109:45: 
error: cannot pass object of non-trivial type 'std::unordered_map<std::string, 
std::string>' (aka
         'unordered_map<basic_string<char>, basic_string<char> >') through 
variadic constructor; call will abort at runtime [-Wnon-pod-varargs]
         UpdateMapState<Tuple, Index - 1>(tpl, mapState);
                                               ^
   2 errors generated.
   extensions/sql/CMakeFiles/minifi-sql.dir/build.make:206: recipe for target 
'extensions/sql/CMakeFiles/minifi-sql.dir/processors/QueryDatabaseTable.cpp.o' 
failed
   make[2]: *** 
[extensions/sql/CMakeFiles/minifi-sql.dir/processors/QueryDatabaseTable.cpp.o] 
Error 1
   CMakeFiles/Makefile2:3863: recipe for target 
'extensions/sql/CMakeFiles/minifi-sql.dir/all' failed
   ```
   
   The changes introduced are not portable.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to