lordgamez commented on code in PR #2265:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2265#discussion_r4119496593


##########
extensions/opc/src/FetchOPCHistory.cpp:
##########
@@ -0,0 +1,400 @@
+/**
+ * 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.
+ */
+
+#include "FetchOPCHistory.h"
+
+#include <optional>
+#include <string>
+#include <vector>
+
+#include "core/ProcessSession.h"
+#include "core/Resource.h"
+#include "minifi-cpp/core/ProcessContext.h"
+#include "utils/ProcessorConfigUtils.h"
+#include "utils/StringUtils.h"
+
+namespace org::apache::nifi::minifi::processors {
+
+namespace {
+
+constexpr const char* LAST_FETCHED_TIMESTAMP_KEY = "last_fetched_timestamp";
+constexpr const char* LAST_FETCHED_FINGERPRINT_KEY = 
"last_fetched_fingerprint";
+
+std::string updateTypeToString(UA_HistoryUpdateType type) {
+  switch (type) {
+    case UA_HISTORYUPDATETYPE_INSERT:
+      return "Insert";
+    case UA_HISTORYUPDATETYPE_REPLACE:
+      return "Replace";
+    case UA_HISTORYUPDATETYPE_UPDATE:
+      return "Update";
+    case UA_HISTORYUPDATETYPE_DELETE:
+      return "Delete";
+    default:
+      return "Unknown";
+  }
+}
+
+std::string uaStringToString(const UA_String& str) {
+  return {reinterpret_cast<const char*>(str.data), str.length};
+}
+
+struct HistoryEntry {
+  std::string value;
+  int64_t source_timestamp = 0;
+  const UA_ModificationInfo* modification_info = nullptr;
+
+  [[nodiscard]] int64_t modificationTime() const {
+    return modification_info ? modification_info->modificationTime : 
UA_DateTime_fromUnixTime(0);
+  }
+};
+
+struct HistoryBatch {
+  std::vector<HistoryEntry> entries;
+  bool has_modification_info = false;
+};
+
+std::string entryFingerprint(const HistoryEntry& entry, bool 
has_modification_info) {
+  // The fingerprint deduplicates entries sharing the boundary source 
timestamp across triggers. For raw value history a
+  // duplicated (value, source timestamp) pair represents no change in the 
history, so losing one to deduplication is harmless.
+  // For audit (modification) history the modification time and update type 
distinguish otherwise-identical entries, so they
+  // are included to make the fingerprint more unique and reduce the chance of 
dropping a distinct modification.
+  std::string raw = ":" + entry.value;
+  if (has_modification_info) {
+    const auto update_type = entry.modification_info ? 
updateTypeToString(entry.modification_info->updateType) : "";
+    raw = std::to_string(entry.modificationTime()) + ":" + update_type + raw;
+  }

Review Comment:
   Having the username as part of the fingerprint seems to be an overkill for 
me. Having the modification time, update time and value should be enough.



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