diff --git a/java/common/src/main/java/org/apache/tsfile/utils/TsPrimitiveType.java b/java/common/src/main/java/org/apache/tsfile/utils/TsPrimitiveType.java index 50a744365..226862ff1 100644 --- a/java/common/src/main/java/org/apache/tsfile/utils/TsPrimitiveType.java +++ b/java/common/src/main/java/org/apache/tsfile/utils/TsPrimitiveType.java @@ -691,6 +691,12 @@ public boolean equals(Object anObject) { return false; } for (int i = 0; i < this.values.length; i++) { + if (values[i] == null && anotherTs.values[i] == null) { + continue; + } + if (values[i] == null || anotherTs.values[i] == null) { + return false; + } if (!values[i].equals(anotherTs.values[i])) { return false; } diff --git a/java/tsfile/src/test/java/org/apache/tsfile/utils/TsPrimitiveTypeTest.java b/java/tsfile/src/test/java/org/apache/tsfile/utils/TsPrimitiveTypeTest.java index f554271b9..d74847b38 100644 --- a/java/tsfile/src/test/java/org/apache/tsfile/utils/TsPrimitiveTypeTest.java +++ b/java/tsfile/src/test/java/org/apache/tsfile/utils/TsPrimitiveTypeTest.java @@ -20,6 +20,7 @@ import org.apache.tsfile.common.conf.TSFileConfig; import org.apache.tsfile.enums.TSDataType; +import org.apache.tsfile.read.TimeValuePair; import org.apache.tsfile.utils.TsPrimitiveType.TsBinary; import org.apache.tsfile.utils.TsPrimitiveType.TsBoolean; import org.apache.tsfile.utils.TsPrimitiveType.TsDouble; @@ -59,4 +60,19 @@ public void testNewAndGet() { Assert.assertEquals(new TsBoolean(true), booleanValue); Assert.assertTrue(booleanValue.getBoolean()); } + + @Test + public void testCompareWithNullValue() { + TimeValuePair timeValuePair1 = + new TimeValuePair( + 1, + new TsPrimitiveType.TsVector( + new TsPrimitiveType[] {new TsBoolean(true), null, null, new TsInt(1)})); + TimeValuePair timeValuePair2 = + new TimeValuePair( + 1, + new TsPrimitiveType.TsVector( + new TsPrimitiveType[] {new TsBoolean(true), null, new TsInt(1), null})); + Assert.assertFalse(timeValuePair1.equals(timeValuePair2)); + } }