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 d19d0352db2 Fixed the bug that the attribute insertion will not update
null when cache miss (#17568)
d19d0352db2 is described below
commit d19d0352db2b8b285a5a898e201ffdbcc9f53c63
Author: Caideyipi <[email protected]>
AuthorDate: Thu Apr 30 11:39:30 2026 +0800
Fixed the bug that the attribute insertion will not update null when cache
miss (#17568)
---
.../fetcher/TableDeviceSchemaValidator.java | 31 ++++++------
.../fetcher/TableDeviceSchemaValidatorTest.java | 55 ++++++++++++++++++++++
2 files changed, 71 insertions(+), 15 deletions(-)
diff --git
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaValidator.java
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaValidator.java
index a83752e4d95..216a81d5399 100644
---
a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaValidator.java
+++
b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaValidator.java
@@ -129,12 +129,8 @@ public class TableDeviceSchemaValidator {
if (attributeMap == null) {
result.missingDeviceIndexList.add(i);
} else {
- for (int j = 0, attributeSize = attributeKeyList.size(); j <
attributeSize; j++) {
- if (!Objects.equals(
- attributeMap.get(attributeKeyList.get(j)),
attributeValueList.get(i)[j])) {
- result.attributeUpdateDeviceIndexList.add(i);
- break;
- }
+ if (isAttributeUpdateRequired(attributeKeyList,
attributeValueList.get(i), attributeMap)) {
+ result.attributeUpdateDeviceIndexList.add(i);
}
}
}
@@ -184,18 +180,23 @@ public class TableDeviceSchemaValidator {
final ValidateResult result,
final int index,
final Map<String, Binary> attributeMap) {
- final Object[] deviceAttributeValueList = attributeValueList.get(index);
- for (int j = 0, size = attributeKeyList.size(); j < size; j++) {
- if (deviceAttributeValueList[j] != null) {
- final String key = attributeKeyList.get(j);
- final Binary value = attributeMap.get(key);
+ if (isAttributeUpdateRequired(attributeKeyList,
attributeValueList.get(index), attributeMap)) {
+ result.attributeUpdateDeviceIndexList.add(index);
+ }
+ }
- if (!deviceAttributeValueList[j].equals(value)) {
- result.attributeUpdateDeviceIndexList.add(index);
- break;
- }
+ static boolean isAttributeUpdateRequired(
+ final List<String> attributeKeyList,
+ final Object[] deviceAttributeValueList,
+ final Map<String, Binary> attributeMap) {
+ for (int j = 0, size = attributeKeyList.size(); j < size; j++) {
+ final Object inputValue =
+ deviceAttributeValueList.length > j ? deviceAttributeValueList[j] :
null;
+ if (!Objects.equals(attributeMap.get(attributeKeyList.get(j)),
inputValue)) {
+ return true;
}
}
+ return false;
}
private void autoCreateOrUpdateDeviceSchema(
diff --git
a/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaValidatorTest.java
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaValidatorTest.java
new file mode 100644
index 00000000000..6242ab8960b
--- /dev/null
+++
b/iotdb-core/datanode/src/test/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/fetcher/TableDeviceSchemaValidatorTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.queryengine.plan.relational.metadata.fetcher;
+
+import org.apache.tsfile.utils.Binary;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class TableDeviceSchemaValidatorTest {
+
+ @Test
+ public void testNullAttributeNeedsUpdate() {
+ final Map<String, Binary> attributeMap = new HashMap<>();
+ attributeMap.put("attr", new Binary("x", StandardCharsets.UTF_8));
+
+ Assert.assertTrue(
+ TableDeviceSchemaValidator.isAttributeUpdateRequired(
+ Collections.singletonList("attr"), new Object[] {null},
attributeMap));
+ }
+
+ @Test
+ public void testMissingTailAttributeValueEqualsNull() {
+ final Map<String, Binary> attributeMap = new HashMap<>();
+ attributeMap.put("attr1", new Binary("x", StandardCharsets.UTF_8));
+
+ Assert.assertFalse(
+ TableDeviceSchemaValidator.isAttributeUpdateRequired(
+ Arrays.asList("attr1", "attr2"),
+ new Object[] {new Binary("x", StandardCharsets.UTF_8)},
+ attributeMap));
+ }
+}