From a1aa70ad2bac6dc23e8bd95258663f2f6c7ffc41 Mon Sep 17 00:00:00 2001 From: FearfulTomcat27 <1471335448@qq.com> Date: Tue, 12 Nov 2024 16:26:27 +0800 Subject: [PATCH 1/5] fix: Throws an exception when comparing to null. --- .../metadata/TableMetadataImpl.java | 34 +++++++++++++++++++ ...AbstractCastFunctionColumnTransformer.java | 32 +++++++++++------ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java index c34c30461e3c..d468631c5f21 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java @@ -61,6 +61,9 @@ import static org.apache.iotdb.commons.conf.IoTDBConstant.PATH_ROOT; import static org.apache.iotdb.commons.conf.IoTDBConstant.PATH_SEPARATOR; +import static org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType.EQUAL; +import static org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType.LESS_THAN; +import static org.apache.iotdb.db.queryengine.plan.relational.function.OperatorType.LESS_THAN_OR_EQUAL; import static org.apache.tsfile.read.common.type.BinaryType.TEXT; import static org.apache.tsfile.read.common.type.BooleanType.BOOLEAN; import static org.apache.tsfile.read.common.type.DateType.DATE; @@ -70,6 +73,7 @@ import static org.apache.tsfile.read.common.type.LongType.INT64; import static org.apache.tsfile.read.common.type.StringType.STRING; import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP; +import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN; public class TableMetadataImpl implements Metadata { @@ -107,6 +111,14 @@ public Optional getTableSchema(SessionInfo session, QualifiedObject public Type getOperatorReturnType(OperatorType operatorType, List argumentTypes) throws OperatorNotFoundException { + if (isCompareWithNull(argumentTypes)) { + if (operatorType.equals(EQUAL) + || operatorType.equals(LESS_THAN) + || operatorType.equals(LESS_THAN_OR_EQUAL)) { + return BOOLEAN; + } + return argumentTypes.get(0); + } switch (operatorType) { case ADD: if (!isTwoTypeCalculable(argumentTypes) @@ -780,6 +792,10 @@ public static boolean isTimestampType(Type type) { return TIMESTAMP.equals(type); } + public static boolean isUnknownType(Type type) { + return UNKNOWN.equals(type); + } + public static boolean isIntegerNumber(Type type) { return INT32.equals(type) || INT64.equals(type); } @@ -798,6 +814,15 @@ public static boolean isTwoTypeComparable(List argumentTypes) { return (isNumericType(left) && isNumericType(right)) || (isCharType(left) && isCharType(right)); } + public static boolean isCompareWithNull(List argumentTypes) { + if (argumentTypes.size() != 2) { + return false; + } + Type left = argumentTypes.get(0); + Type right = argumentTypes.get(1); + return isNumericType(left) || isCharType(left) && isUnknownType(right); + } + public static boolean isArithmeticType(Type type) { return INT32.equals(type) || INT64.equals(type) @@ -815,4 +840,13 @@ public static boolean isTwoTypeCalculable(List argumentTypes) { Type right = argumentTypes.get(1); return isArithmeticType(left) && isArithmeticType(right); } + + public static boolean isCalculateWithNull(List argumentTypes) { + if (argumentTypes.size() != 2) { + return false; + } + Type left = argumentTypes.get(0); + Type right = argumentTypes.get(1); + return isArithmeticType(left) && isUnknownType(right); + } } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractCastFunctionColumnTransformer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractCastFunctionColumnTransformer.java index 19e29bd8c25a..a0c93e4bf7e0 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractCastFunctionColumnTransformer.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/unary/scalar/AbstractCastFunctionColumnTransformer.java @@ -48,27 +48,39 @@ protected AbstractCastFunctionColumnTransformer( @Override protected void doTransform(Column column, ColumnBuilder columnBuilder) { - TypeEnum sourceType = childColumnTransformer.getType().getTypeEnum(); Type childType = childColumnTransformer.getType(); - for (int i = 0, n = column.getPositionCount(); i < n; i++) { - if (!column.isNull(i)) { - transform(column, columnBuilder, sourceType, childType, i); - } else { + if (childType == null) { + for (int i = 0; i < column.getPositionCount(); i++) { columnBuilder.appendNull(); } + } else { + TypeEnum sourceType = childType.getTypeEnum(); + for (int i = 0, n = column.getPositionCount(); i < n; i++) { + if (!column.isNull(i)) { + transform(column, columnBuilder, sourceType, childType, i); + } else { + columnBuilder.appendNull(); + } + } } } @Override protected void doTransform(Column column, ColumnBuilder columnBuilder, boolean[] selection) { - TypeEnum sourceType = childColumnTransformer.getType().getTypeEnum(); Type childType = childColumnTransformer.getType(); - for (int i = 0, n = column.getPositionCount(); i < n; i++) { - if (selection[i] && !column.isNull(i)) { - transform(column, columnBuilder, sourceType, childType, i); - } else { + if (childType == null) { + for (int i = 0; i < column.getPositionCount(); i++) { columnBuilder.appendNull(); } + } else { + TypeEnum sourceType = childType.getTypeEnum(); + for (int i = 0, n = column.getPositionCount(); i < n; i++) { + if (selection[i] && !column.isNull(i)) { + transform(column, columnBuilder, sourceType, childType, i); + } else { + columnBuilder.appendNull(); + } + } } } From 8f9b0908b84c0f87f26ee80b1d243973e2ba1519 Mon Sep 17 00:00:00 2001 From: FearfulTomcat27 <1471335448@qq.com> Date: Wed, 13 Nov 2024 15:40:37 +0800 Subject: [PATCH 2/5] test: Add an IT that compares with null using the operator --- .../relational/it/query/old/IoTDBFilterTableIT.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBFilterTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBFilterTableIT.java index e2536adcba0b..cfd6e0f831d4 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBFilterTableIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBFilterTableIT.java @@ -237,4 +237,14 @@ public void testFilterWithUDTF() { fail(throwable.getMessage()); } } + + @Test + public void testCompareWithNull() { + tableResultSetEqualTest( + "select s1 from sg1 where s1 != null", new String[] {"s1"}, new String[] {}, DATABASE_NAME); + tableResultSetEqualTest( + "select s1 from sg1 where s1 <> null", new String[] {"s1"}, new String[] {}, DATABASE_NAME); + tableResultSetEqualTest( + "select s1 from sg1 where s1 = null", new String[] {"s1"}, new String[] {}, DATABASE_NAME); + } } From d800ce5b404c97330abdb3fc6fe99e6b43ad8cc7 Mon Sep 17 00:00:00 2001 From: FearfulTomcat27 <1471335448@qq.com> Date: Wed, 13 Nov 2024 15:57:38 +0800 Subject: [PATCH 3/5] test: Add IT with null calculations --- .../it/query/old/IoTDBFilterTableIT.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBFilterTableIT.java b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBFilterTableIT.java index cfd6e0f831d4..e509a05d051f 100644 --- a/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBFilterTableIT.java +++ b/integration-test/src/test/java/org/apache/iotdb/relational/it/query/old/IoTDBFilterTableIT.java @@ -247,4 +247,18 @@ public void testCompareWithNull() { tableResultSetEqualTest( "select s1 from sg1 where s1 = null", new String[] {"s1"}, new String[] {}, DATABASE_NAME); } + + @Test + public void testCalculateWithNull() { + tableResultSetEqualTest( + "select s1 + null from sg1", + new String[] {"_col0"}, + new String[] {"null,", "null,"}, + DATABASE_NAME); + tableResultSetEqualTest( + "select s2 - null from sg1", + new String[] {"_col0"}, + new String[] {"null,", "null,"}, + DATABASE_NAME); + } } From a7349d8b8ef9db7d2e231b00cf9573b2fc60341f Mon Sep 17 00:00:00 2001 From: FearfulTomcat27 <1471335448@qq.com> Date: Wed, 13 Nov 2024 15:59:43 +0800 Subject: [PATCH 4/5] refactor: Optimize return type judgment structure --- .../plan/relational/metadata/TableMetadataImpl.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java index d468631c5f21..e64ccf804296 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java @@ -112,13 +112,11 @@ public Type getOperatorReturnType(OperatorType operatorType, List Date: Tue, 19 Nov 2024 20:50:44 +0800 Subject: [PATCH 5/5] fix: Modify the returnType of the NullColumnTransformer and add a return type for comparison with null. --- .../function/arithmetic/AdditionResolver.java | 14 ++++++++++ .../function/arithmetic/DivisionResolver.java | 18 +++++++++++++ .../function/arithmetic/ModulusResolver.java | 18 +++++++++++++ .../arithmetic/MultiplicationResolver.java | 18 +++++++++++++ .../arithmetic/SubtractionResolver.java | 14 ++++++++++ .../metadata/TableMetadataImpl.java | 26 ++++++------------- .../column/leaf/NullColumnTransformer.java | 4 ++- 7 files changed, 93 insertions(+), 19 deletions(-) diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/AdditionResolver.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/AdditionResolver.java index b3d1836e687f..16607dc01ecc 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/AdditionResolver.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/AdditionResolver.java @@ -28,6 +28,7 @@ import static org.apache.tsfile.read.common.type.IntType.INT32; import static org.apache.tsfile.read.common.type.LongType.INT64; import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP; +import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN; public class AdditionResolver { @@ -40,6 +41,7 @@ public class AdditionResolver { addCondition(INT32, DOUBLE, DOUBLE); addCondition(INT32, DATE, DATE); addCondition(INT32, TIMESTAMP, TIMESTAMP); + addCondition(INT32, UNKNOWN, INT32); addCondition(INT64, INT32, INT64); addCondition(INT64, INT64, INT64); @@ -47,22 +49,34 @@ public class AdditionResolver { addCondition(INT64, DOUBLE, DOUBLE); addCondition(INT64, DATE, DATE); addCondition(INT64, TIMESTAMP, TIMESTAMP); + addCondition(INT64, UNKNOWN, INT64); addCondition(FLOAT, INT32, FLOAT); addCondition(FLOAT, INT64, FLOAT); addCondition(FLOAT, FLOAT, FLOAT); addCondition(FLOAT, DOUBLE, DOUBLE); + addCondition(FLOAT, UNKNOWN, FLOAT); addCondition(DOUBLE, INT32, DOUBLE); addCondition(DOUBLE, INT64, DOUBLE); addCondition(DOUBLE, FLOAT, DOUBLE); addCondition(DOUBLE, DOUBLE, DOUBLE); + addCondition(DOUBLE, UNKNOWN, DOUBLE); addCondition(DATE, INT32, DATE); addCondition(DATE, INT64, DATE); + addCondition(DATE, UNKNOWN, DATE); addCondition(TIMESTAMP, INT32, TIMESTAMP); addCondition(TIMESTAMP, INT64, TIMESTAMP); + addCondition(TIMESTAMP, UNKNOWN, TIMESTAMP); + + addCondition(UNKNOWN, INT32, INT32); + addCondition(UNKNOWN, INT64, INT64); + addCondition(UNKNOWN, FLOAT, FLOAT); + addCondition(UNKNOWN, DOUBLE, DOUBLE); + addCondition(UNKNOWN, DATE, DATE); + addCondition(UNKNOWN, TIMESTAMP, TIMESTAMP); } private static void addCondition(Type condition1, Type condition2, Type result) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/DivisionResolver.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/DivisionResolver.java index 0d6bf4664ec9..d70f99edefba 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/DivisionResolver.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/DivisionResolver.java @@ -22,10 +22,13 @@ import java.util.Map; import java.util.Optional; +import static org.apache.tsfile.read.common.type.DateType.DATE; import static org.apache.tsfile.read.common.type.DoubleType.DOUBLE; import static org.apache.tsfile.read.common.type.FloatType.FLOAT; import static org.apache.tsfile.read.common.type.IntType.INT32; import static org.apache.tsfile.read.common.type.LongType.INT64; +import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP; +import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN; public class DivisionResolver { @@ -36,21 +39,36 @@ public class DivisionResolver { addCondition(INT32, INT64, INT64); addCondition(INT32, FLOAT, FLOAT); addCondition(INT32, DOUBLE, DOUBLE); + addCondition(INT32, UNKNOWN, INT32); addCondition(INT64, INT32, INT64); addCondition(INT64, INT64, INT64); addCondition(INT64, FLOAT, FLOAT); addCondition(INT64, DOUBLE, DOUBLE); + addCondition(INT64, UNKNOWN, INT64); addCondition(FLOAT, INT32, FLOAT); addCondition(FLOAT, INT64, FLOAT); addCondition(FLOAT, FLOAT, FLOAT); addCondition(FLOAT, DOUBLE, DOUBLE); + addCondition(FLOAT, UNKNOWN, FLOAT); addCondition(DOUBLE, INT32, DOUBLE); addCondition(DOUBLE, INT64, DOUBLE); addCondition(DOUBLE, FLOAT, DOUBLE); addCondition(DOUBLE, DOUBLE, DOUBLE); + addCondition(DOUBLE, UNKNOWN, DOUBLE); + + addCondition(DATE, UNKNOWN, DATE); + + addCondition(TIMESTAMP, UNKNOWN, TIMESTAMP); + + addCondition(UNKNOWN, INT32, INT32); + addCondition(UNKNOWN, INT64, INT64); + addCondition(UNKNOWN, FLOAT, FLOAT); + addCondition(UNKNOWN, DOUBLE, DOUBLE); + addCondition(UNKNOWN, DATE, DATE); + addCondition(UNKNOWN, TIMESTAMP, TIMESTAMP); } private static void addCondition(Type condition1, Type condition2, Type result) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/ModulusResolver.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/ModulusResolver.java index c0e777655206..e4fc3d73ec96 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/ModulusResolver.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/ModulusResolver.java @@ -22,10 +22,13 @@ import java.util.Map; import java.util.Optional; +import static org.apache.tsfile.read.common.type.DateType.DATE; import static org.apache.tsfile.read.common.type.DoubleType.DOUBLE; import static org.apache.tsfile.read.common.type.FloatType.FLOAT; import static org.apache.tsfile.read.common.type.IntType.INT32; import static org.apache.tsfile.read.common.type.LongType.INT64; +import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP; +import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN; public class ModulusResolver { @@ -36,21 +39,36 @@ public class ModulusResolver { addCondition(INT32, INT64, INT64); addCondition(INT32, FLOAT, FLOAT); addCondition(INT32, DOUBLE, DOUBLE); + addCondition(INT32, UNKNOWN, INT32); addCondition(INT64, INT32, INT64); addCondition(INT64, INT64, INT64); addCondition(INT64, FLOAT, FLOAT); addCondition(INT64, DOUBLE, DOUBLE); + addCondition(INT64, UNKNOWN, INT64); addCondition(FLOAT, INT32, FLOAT); addCondition(FLOAT, INT64, FLOAT); addCondition(FLOAT, FLOAT, FLOAT); addCondition(FLOAT, DOUBLE, DOUBLE); + addCondition(FLOAT, UNKNOWN, FLOAT); addCondition(DOUBLE, INT32, DOUBLE); addCondition(DOUBLE, INT64, DOUBLE); addCondition(DOUBLE, FLOAT, DOUBLE); addCondition(DOUBLE, DOUBLE, DOUBLE); + addCondition(DOUBLE, UNKNOWN, DOUBLE); + + addCondition(DATE, UNKNOWN, DATE); + + addCondition(TIMESTAMP, UNKNOWN, TIMESTAMP); + + addCondition(UNKNOWN, INT32, INT32); + addCondition(UNKNOWN, INT64, INT64); + addCondition(UNKNOWN, FLOAT, FLOAT); + addCondition(UNKNOWN, DOUBLE, DOUBLE); + addCondition(UNKNOWN, DATE, DATE); + addCondition(UNKNOWN, TIMESTAMP, TIMESTAMP); } private static void addCondition(Type condition1, Type condition2, Type result) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/MultiplicationResolver.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/MultiplicationResolver.java index 769e0172f8ef..1f6b8710879e 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/MultiplicationResolver.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/MultiplicationResolver.java @@ -22,10 +22,13 @@ import java.util.Map; import java.util.Optional; +import static org.apache.tsfile.read.common.type.DateType.DATE; import static org.apache.tsfile.read.common.type.DoubleType.DOUBLE; import static org.apache.tsfile.read.common.type.FloatType.FLOAT; import static org.apache.tsfile.read.common.type.IntType.INT32; import static org.apache.tsfile.read.common.type.LongType.INT64; +import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP; +import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN; public class MultiplicationResolver { @@ -36,21 +39,36 @@ public class MultiplicationResolver { addCondition(INT32, INT64, INT64); addCondition(INT32, FLOAT, FLOAT); addCondition(INT32, DOUBLE, DOUBLE); + addCondition(INT32, UNKNOWN, INT32); addCondition(INT64, INT32, INT64); addCondition(INT64, INT64, INT64); addCondition(INT64, FLOAT, FLOAT); addCondition(INT64, DOUBLE, DOUBLE); + addCondition(INT64, UNKNOWN, INT64); addCondition(FLOAT, INT32, FLOAT); addCondition(FLOAT, INT64, FLOAT); addCondition(FLOAT, FLOAT, FLOAT); addCondition(FLOAT, DOUBLE, DOUBLE); + addCondition(FLOAT, UNKNOWN, FLOAT); addCondition(DOUBLE, INT32, DOUBLE); addCondition(DOUBLE, INT64, DOUBLE); addCondition(DOUBLE, FLOAT, DOUBLE); addCondition(DOUBLE, DOUBLE, DOUBLE); + addCondition(DOUBLE, UNKNOWN, DOUBLE); + + addCondition(DATE, UNKNOWN, DATE); + + addCondition(TIMESTAMP, UNKNOWN, TIMESTAMP); + + addCondition(UNKNOWN, INT32, INT32); + addCondition(UNKNOWN, INT64, INT64); + addCondition(UNKNOWN, FLOAT, FLOAT); + addCondition(UNKNOWN, DOUBLE, DOUBLE); + addCondition(UNKNOWN, DATE, DATE); + addCondition(UNKNOWN, TIMESTAMP, TIMESTAMP); } private static void addCondition(Type condition1, Type condition2, Type result) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/SubtractionResolver.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/SubtractionResolver.java index 5b7f4a79022f..ba3f5200e13e 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/SubtractionResolver.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/function/arithmetic/SubtractionResolver.java @@ -28,6 +28,7 @@ import static org.apache.tsfile.read.common.type.IntType.INT32; import static org.apache.tsfile.read.common.type.LongType.INT64; import static org.apache.tsfile.read.common.type.TimestampType.TIMESTAMP; +import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN; public class SubtractionResolver { @@ -38,27 +39,40 @@ public class SubtractionResolver { addCondition(INT32, INT64, INT64); addCondition(INT32, FLOAT, FLOAT); addCondition(INT32, DOUBLE, DOUBLE); + addCondition(INT32, UNKNOWN, INT32); addCondition(INT64, INT32, INT64); addCondition(INT64, INT64, INT64); addCondition(INT64, FLOAT, FLOAT); addCondition(INT64, DOUBLE, DOUBLE); + addCondition(INT64, UNKNOWN, INT64); addCondition(FLOAT, INT32, FLOAT); addCondition(FLOAT, INT64, FLOAT); addCondition(FLOAT, FLOAT, FLOAT); addCondition(FLOAT, DOUBLE, DOUBLE); + addCondition(FLOAT, UNKNOWN, FLOAT); addCondition(DOUBLE, INT32, DOUBLE); addCondition(DOUBLE, INT64, DOUBLE); addCondition(DOUBLE, FLOAT, DOUBLE); addCondition(DOUBLE, DOUBLE, DOUBLE); + addCondition(DOUBLE, UNKNOWN, DOUBLE); addCondition(DATE, INT32, DATE); addCondition(DATE, INT64, DATE); + addCondition(DATE, UNKNOWN, DATE); addCondition(TIMESTAMP, INT32, TIMESTAMP); addCondition(TIMESTAMP, INT64, TIMESTAMP); + addCondition(TIMESTAMP, UNKNOWN, TIMESTAMP); + + addCondition(UNKNOWN, INT32, INT32); + addCondition(UNKNOWN, INT64, INT64); + addCondition(UNKNOWN, FLOAT, FLOAT); + addCondition(UNKNOWN, DOUBLE, DOUBLE); + addCondition(UNKNOWN, DATE, DATE); + addCondition(UNKNOWN, TIMESTAMP, TIMESTAMP); } private static void addCondition(Type condition1, Type condition2, Type result) { diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java index e64ccf804296..97f22c006bb5 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/plan/relational/metadata/TableMetadataImpl.java @@ -110,13 +110,6 @@ public Optional getTableSchema(SessionInfo session, QualifiedObject @Override public Type getOperatorReturnType(OperatorType operatorType, List argumentTypes) throws OperatorNotFoundException { - - if (isCompareWithNull(argumentTypes)) { - return BOOLEAN; - } else if (isCalculateWithNull(argumentTypes)) { - return argumentTypes.get(0); - } - switch (operatorType) { case ADD: if (!isTwoTypeCalculable(argumentTypes) @@ -807,18 +800,11 @@ public static boolean isTwoTypeComparable(List argumentTypes) { if (left.equals(right)) { return true; } - // Boolean type and Binary Type can not be compared with other types - return (isNumericType(left) && isNumericType(right)) || (isCharType(left) && isCharType(right)); - } - - public static boolean isCompareWithNull(List argumentTypes) { - if (argumentTypes.size() != 2) { - return false; - } - Type left = argumentTypes.get(0); - Type right = argumentTypes.get(1); - return isNumericType(left) || isCharType(left) && isUnknownType(right); + return (isNumericType(left) && isNumericType(right)) + || (isCharType(left) && isCharType(right)) + || (isUnknownType(left) && (isNumericType(right) || isCharType(right))) + || ((isNumericType(left) || isCharType(left)) && isUnknownType(right)); } public static boolean isArithmeticType(Type type) { @@ -836,6 +822,10 @@ public static boolean isTwoTypeCalculable(List argumentTypes) { } Type left = argumentTypes.get(0); Type right = argumentTypes.get(1); + if ((isUnknownType(left) && isArithmeticType(right)) + || (isUnknownType(right) && isArithmeticType(left))) { + return true; + } return isArithmeticType(left) && isArithmeticType(right); } diff --git a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/leaf/NullColumnTransformer.java b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/leaf/NullColumnTransformer.java index 21d4dfc166ea..d6cc68ab3ca5 100644 --- a/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/leaf/NullColumnTransformer.java +++ b/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/queryengine/transformation/dag/column/leaf/NullColumnTransformer.java @@ -21,10 +21,12 @@ import org.apache.tsfile.read.common.block.column.NullColumn; +import static org.apache.tsfile.read.common.type.UnknownType.UNKNOWN; + public class NullColumnTransformer extends LeafColumnTransformer { public NullColumnTransformer() { - super(null); + super(UNKNOWN); } @Override