This is an automated email from the ASF dual-hosted git repository.

justinchen pushed a commit to branch opc-13
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit 97728bbc96138aff8fc610c21368e1a5c76c9ddd
Author: Caideyipi <[email protected]>
AuthorDate: Wed Mar 18 10:55:54 2026 +0800

    fix
---
 .../pipe/sink/protocol/opcua/OpcUaNameSpace.java   | 50 +++++++++++++---------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
index f9fbb2d2ad4..a8edc941bb4 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/sink/protocol/opcua/OpcUaNameSpace.java
@@ -156,6 +156,26 @@ public class OpcUaNameSpace extends 
ManagedNamespaceWithLifecycle {
       final TSDataType type = measurementSchema.getType();
       final NodeId nodeId = newNodeId(currentFolder + name);
       final UaVariableNode measurementNode;
+
+      int lastNonnullIndex = -1;
+      for (int j = tablet.rowSize - 1; j >= 0; --j) {
+        if (!tablet.bitMaps[i].isMarked(j)) {
+          lastNonnullIndex = j;
+          break;
+        }
+      }
+
+      if (lastNonnullIndex == -1) {
+        continue;
+      }
+
+      final long utcTimestamp = 
timestampToUtc(tablet.timestamps[lastNonnullIndex]);
+      final DataValue value =
+          new DataValue(
+              new Variant(getTabletObjectValue4Opc(tablet.values[i], 
lastNonnullIndex, type)),
+              StatusCode.GOOD,
+              new DateTime(utcTimestamp),
+              new DateTime());
       if (!getNodeManager().containsNode(nodeId)) {
         measurementNode =
             new UaVariableNode.UaVariableNodeBuilder(getNodeContext())
@@ -166,6 +186,7 @@ public class OpcUaNameSpace extends 
ManagedNamespaceWithLifecycle {
                 .setDisplayName(LocalizedText.english(name))
                 .setDataType(convertToOpcDataType(type))
                 .setTypeDefinition(Identifiers.BaseDataVariableType)
+                .setValue(value)
                 .build();
         getNodeManager().addNode(measurementNode);
         folderNode.addOrganizes(measurementNode);
@@ -181,26 +202,15 @@ public class OpcUaNameSpace extends 
ManagedNamespaceWithLifecycle {
                                 String.format("The Node %s does not exist.", 
nodeId)));
       }
 
-      int lastNonnullIndex = -1;
-      for (int j = tablet.rowSize - 1; j >= 0; --j) {
-        if (!tablet.bitMaps[i].isMarked(j)) {
-          lastNonnullIndex = j;
-          break;
-        }
-      }
-
-      if (lastNonnullIndex != -1) {
-        final long utcTimestamp = 
timestampToUtc(tablet.timestamps[lastNonnullIndex]);
-        if (Objects.isNull(measurementNode.getValue())
-            || 
Objects.requireNonNull(measurementNode.getValue().getSourceTime()).getUtcTime()
-                < utcTimestamp) {
-          measurementNode.setValue(
-              new DataValue(
-                  new Variant(getTabletObjectValue4Opc(tablet.values[i], 
lastNonnullIndex, type)),
-                  StatusCode.GOOD,
-                  new DateTime(utcTimestamp),
-                  new DateTime()));
-        }
+      if (Objects.isNull(measurementNode.getValue())
+          || Objects.isNull(measurementNode.getValue().getSourceTime())
+          || measurementNode.getValue().getSourceTime().getUtcTime() < 
utcTimestamp) {
+        measurementNode.setValue(
+            new DataValue(
+                new Variant(getTabletObjectValue4Opc(tablet.values[i], 
lastNonnullIndex, type)),
+                StatusCode.GOOD,
+                new DateTime(utcTimestamp),
+                new DateTime()));
       }
     }
   }

Reply via email to