diff --git a/fe/fe-common/src/main/java/org/apache/doris/catalog/StructType.java b/fe/fe-common/src/main/java/org/apache/doris/catalog/StructType.java index be5cb287b4..2061f08a8c 100644 --- a/fe/fe-common/src/main/java/org/apache/doris/catalog/StructType.java +++ b/fe/fe-common/src/main/java/org/apache/doris/catalog/StructType.java @@ -32,6 +32,7 @@ import com.google.gson.annotations.SerializedName; import java.util.ArrayList; import java.util.HashMap; +import java.util.Objects; /** * Describes a STRUCT type. STRUCT types have a list of named struct fields. @@ -152,12 +153,14 @@ public class StructType extends Type { return true; } - if (t.isStructType()) { + if (!t.isStructType()) { return false; } - if (fields.size() != ((StructType) t).getFields().size()) { - return false; + StructType other = (StructType) t; + if (fields.size() != other.getFields().size()) { + // Temp to make NullPredict from fe send to be + return other.getFields().size() == 1 && Objects.equals(other.getFields().get(0).name, "null_pred"); } for (int i = 0; i < fields.size(); i++) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java index 572c778262..55b732a79c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/IsNullPredicate.java @@ -24,6 +24,8 @@ import org.apache.doris.catalog.Function; import org.apache.doris.catalog.Function.NullableMode; import org.apache.doris.catalog.FunctionSet; import org.apache.doris.catalog.ScalarFunction; +import org.apache.doris.catalog.StructField; +import org.apache.doris.catalog.StructType; import org.apache.doris.catalog.Type; import org.apache.doris.common.AnalysisException; import org.apache.doris.thrift.TExprNode; @@ -63,11 +65,21 @@ public class IsNullPredicate extends Predicate { isNotNullSymbol, Lists.newArrayList(t), Type.BOOLEAN, NullableMode.ALWAYS_NOT_NULLABLE)); // for array type + for (Type complexType : Lists.newArrayList(Type.ARRAY, Type.MAP)) { + functionSet.addBuiltinBothScalaAndVectorized(ScalarFunction.createBuiltinOperator(IS_NULL, isNullSymbol, + Lists.newArrayList(complexType), Type.BOOLEAN, NullableMode.ALWAYS_NOT_NULLABLE)); + + functionSet.addBuiltinBothScalaAndVectorized(ScalarFunction.createBuiltinOperator(IS_NOT_NULL, + isNotNullSymbol, Lists.newArrayList(complexType), Type.BOOLEAN, + NullableMode.ALWAYS_NOT_NULLABLE)); + } + + Type nullStruct = new StructType(Lists.newArrayList(new StructField("null_pred", Type.NULL))); functionSet.addBuiltinBothScalaAndVectorized(ScalarFunction.createBuiltinOperator(IS_NULL, isNullSymbol, - Lists.newArrayList(Type.ARRAY), Type.BOOLEAN, NullableMode.ALWAYS_NOT_NULLABLE)); + Lists.newArrayList(nullStruct), Type.BOOLEAN, NullableMode.ALWAYS_NOT_NULLABLE)); functionSet.addBuiltinBothScalaAndVectorized(ScalarFunction.createBuiltinOperator(IS_NOT_NULL, - isNotNullSymbol, Lists.newArrayList(Type.ARRAY), Type.BOOLEAN, NullableMode.ALWAYS_NOT_NULLABLE)); + isNotNullSymbol, Lists.newArrayList(nullStruct), Type.BOOLEAN, NullableMode.ALWAYS_NOT_NULLABLE)); } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/IsNullPredicateWithComplexTypeTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/IsNullPredicateWithComplexTypeTest.java new file mode 100644 index 0000000000..c40de1e643 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/IsNullPredicateWithComplexTypeTest.java @@ -0,0 +1,60 @@ +// 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.doris.analysis; + +import org.apache.doris.common.Config; +import org.apache.doris.utframe.TestWithFeService; + +import org.junit.jupiter.api.Test; + +public class IsNullPredicateWithComplexTypeTest extends TestWithFeService { + + @Override + protected void runBeforeAll() throws Exception { + Config.enable_map_type = true; + Config.enable_struct_type = true; + // create database + createDatabase("test"); + + createTable("CREATE TABLE test.complex (\n" + + " `dt` int(11) COMMENT \"\",\n" + + " `id` int(11) COMMENT \"\",\n" + + " `m` Map COMMENT \"\",\n" + + " `a` Array COMMENT \"\",\n" + + " `s` Struct COMMENT \"\",\n" + + " `value` varchar(8) COMMENT \"\"\n" + + ") ENGINE=OLAP\n" + + "DUPLICATE KEY(`dt`)\n" + + "PARTITION BY RANGE(`dt`)\n" + + "(PARTITION p1 VALUES LESS THAN (\"10\"))\n" + + "DISTRIBUTED BY HASH(`id`) BUCKETS 10\n" + + "PROPERTIES (\n" + + " \"replication_num\" = \"1\"\n" + + ");"); + } + + @Test + public void testIsNull() throws Exception { + String testStructIsNUll = "select * from test.complex where s is null"; + String testMapIsNUll = "select * from test.complex where m is null"; + String testArrayIsNUll = "select * from test.complex where a is null"; + assertSQLPlanOrErrorMsgContains(testStructIsNUll, ""); + assertSQLPlanOrErrorMsgContains(testMapIsNUll, ""); + assertSQLPlanOrErrorMsgContains(testArrayIsNUll, ""); + } +}