lordgamez commented on a change in pull request #866:
URL: https://github.com/apache/nifi-minifi-cpp/pull/866#discussion_r468409914
##########
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()) {
+ if (flowAttributes[it->first] != commonAttributes[it->first])
+ commonAttributes.erase(it++);
+ else
+ ++it;
+ } else {
+ commonAttributes.erase(it++);
+ }
+ }
+}
+
+void KeepAllUniqueAttributesMerger::processFlowFile(const
std::shared_ptr<core::FlowFile> &flow, std::map<std::string, std::string>&
commonAttributes) {
+ auto flowAttributes = flow->getAttributes();
+ for (const auto& attr : flowAttributes) {
+ if (commonAttributes.find(attr.first) != commonAttributes.end()) {
+ if (commonAttributes[attr.first] != attr.second) {
+ commonAttributes.erase(attr.first);
+ removed_attributes_.push_back(attr.first);
+ }
+ } else if (std::find(removed_attributes_.cbegin(),
removed_attributes_.cend(), attr.first) == removed_attributes_.cend()) {
Review comment:
Iterating through 3 flowfiles in order A, B and C, if all 3 have the
same attribute but B has a different value for it, then we remove the attribute
from the common attributes map. But reaching C we would readd the attribute to
the common attributes map because it is not present, as it was removed
previously due to the conflicting value. So in this case I check if it was
previously removed or not and only add the new attribute if it was not
previously seen.
----------------------------------------------------------------
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:
[email protected]