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

jt2594838 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new b57a0fdd425 Fixed the bug that create attribute does not consider 
nameList size > valueList size (#17593)
b57a0fdd425 is described below

commit b57a0fdd4250abd5db1a891ed4aef940bc3d6054
Author: Caideyipi <[email protected]>
AuthorDate: Thu May 7 09:33:04 2026 +0800

    Fixed the bug that create attribute does not consider nameList size > 
valueList size (#17593)
    
    * fix
    
    * Update DeviceAttributeStore.java
    
    * fix
---
 .../attribute/DeviceAttributeStore.java            |  3 +
 .../attribute/DeviceAttributeStoreTest.java        | 68 ++++++++++++++++++++++
 2 files changed, 71 insertions(+)

diff --git 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java
 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java
index 1f22c306303..81bb311483e 100644
--- 
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java
+++ 
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStore.java
@@ -138,6 +138,9 @@ public class DeviceAttributeStore implements 
IDeviceAttributeStore {
     long memUsage = MAP_SIZE + RamUsageEstimator.NUM_BYTES_OBJECT_REF;
     final Map<String, Binary> attributeMap = new HashMap<>();
     for (int i = 0; i < nameList.size(); i++) {
+      if (valueList.length <= i) {
+        break;
+      }
       if (valueList[i] == null || valueList[i] == Constants.NONE) {
         continue;
       }
diff --git 
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStoreTest.java
 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStoreTest.java
new file mode 100644
index 00000000000..880f5678418
--- /dev/null
+++ 
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/schemaengine/schemaregion/attribute/DeviceAttributeStoreTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.
+ */
+
+package org.apache.iotdb.db.schemaengine.schemaregion.attribute;
+
+import org.apache.tsfile.utils.Binary;
+import org.apache.tsfile.utils.Constants;
+import org.junit.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class DeviceAttributeStoreTest {
+
+  @Test
+  public void testCreateAttributeIgnoresNamesWithoutValues() {
+    final DeviceAttributeStore store = new DeviceAttributeStore(null);
+    final Binary expectedValue = new Binary("v1", StandardCharsets.UTF_8);
+
+    final int pointer =
+        store.createAttribute(
+            Arrays.asList("attr1", "attr2"), new Object[] {expectedValue}, 
"table1");
+
+    final Map<String, Binary> attributes = store.getAttributes(pointer);
+    assertEquals(1, attributes.size());
+    assertEquals(expectedValue, attributes.get("attr1"));
+    assertFalse(attributes.containsKey("attr2"));
+  }
+
+  @Test
+  public void testCreateAttributeSkipsNoneValue() {
+    final DeviceAttributeStore store = new DeviceAttributeStore(null);
+    final Binary expectedValue = new Binary("v2", StandardCharsets.UTF_8);
+
+    final int pointer =
+        store.createAttribute(
+            Arrays.asList("attr1", "attr2"),
+            new Object[] {Constants.NONE, expectedValue},
+            "table1");
+
+    final Map<String, Binary> attributes = store.getAttributes(pointer);
+    assertEquals(1, attributes.size());
+    assertFalse(attributes.containsKey("attr1"));
+    assertTrue(attributes.containsKey("attr2"));
+    assertEquals(expectedValue, attributes.get("attr2"));
+  }
+}

Reply via email to