You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/08/11 07:10:31 UTC

[GitHub] [nifi-minifi-cpp] adamdebreceni commented on a change in pull request #866: MINIFICPP-1321 Support attribute strategies in MergeContent processor

adamdebreceni commented on a change in pull request #866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/866#discussion_r468371398



##########
File path: extensions/libarchive/MergeContent.cpp
##########
@@ -342,6 +362,56 @@ std::shared_ptr<core::FlowFile> ZipMerge::merge(core::ProcessContext *context, c
   return flowFile;
 }
 
+void AttributeMerger::mergeAttributes() {
+  std::map<std::string, std::string> commonAttributes = getCommonAttributes();
+
+  for (const auto& pair : commonAttributes) {
+    session_->putAttribute(mergeFlow_, pair.first, pair.second);
+  }
+}
+
+std::map<std::string, std::string> AttributeMerger::getCommonAttributes() {
+  std::map<std::string, std::string> commonAttributes;
+  bool isFirst = true;
+  for (const auto& flow : flows_) {
+    if (isFirst) {
+      commonAttributes = flow->getAttributes();
+      isFirst = false;
+    } else {
+      processFlowFile(flow, commonAttributes);
+    }
+  }
+  return commonAttributes;
+}
+
+void KeepOnlyCommonAttributesMerger::processFlowFile(const std::shared_ptr<core::FlowFile> &flow, std::map<std::string, std::string>& commonAttributes) {
+  auto flowAttributes = flow->getAttributes();
+  for (auto it = commonAttributes.cbegin(); it != commonAttributes.cend();) {
+    if (flowAttributes.find(it->first) != flowAttributes.end()) {

Review comment:
       with `FlowFile::getAttribute` we could both check for existence and extract the value in one motion (here for `flowAttributes` and in the other `processFlowFile` for `commonAttributes`)




----------------------------------------------------------------
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:
users@infra.apache.org