This is an automated email from the ASF dual-hosted git repository. morrysnow pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 2b401785cee [fix](Nereids) build array and map literal expression failed (#27060) 2b401785cee is described below commit 2b401785ceedd3c4c23cddf104720e2035ceb1ad Author: morrySnow <101034200+morrys...@users.noreply.github.com> AuthorDate: Thu Nov 16 14:08:24 2023 +0800 [fix](Nereids) build array and map literal expression failed (#27060) 1. empty array and map literal 2. multi-layer nested array and map literal --- .../doris/nereids/parser/LogicalPlanBuilder.java | 8 +++++-- .../expressions/functions/ComputeSignature.java | 11 +++++---- .../expressions/functions/IdenticalSignature.java | 6 +++++ .../functions/NullOrIdenticalSignature.java | 8 ++++++- .../suites/nereids_syntax_p0/test_literal.groovy | 27 ++++++++++++++++++++++ 5 files changed, 52 insertions(+), 8 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index 13a4b7503e0..bbec310e3df 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -1905,11 +1905,15 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { * TODO remove this function after we refactor type coercion. */ private List<Literal> typeCoercionItems(List<Literal> items) { - DataType dataType = new Array(items.toArray(new Literal[0])).expectedInputTypes().get(0); + Array array = new Array(items.toArray(new Literal[0])); + if (array.expectedInputTypes().isEmpty()) { + return ImmutableList.of(); + } + DataType dataType = array.expectedInputTypes().get(0); return items.stream() .map(item -> item.checkedCastTo(dataType)) .map(Literal.class::cast) - .collect(Collectors.toList()); + .collect(ImmutableList.toImmutableList()); } @Override diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignature.java index 7655a5be473..ea6997e8482 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/ComputeSignature.java @@ -120,13 +120,14 @@ public interface ComputeSignature extends FunctionTrait, ImplicitCastInputTypes /** use processor to process computeSignature */ static boolean processComplexType(DataType signatureType, DataType realType, BiFunction<DataType, DataType, Boolean> processor) { - if (signatureType instanceof ArrayType && realType instanceof ArrayType) { - return processor.apply(((ArrayType) signatureType).getItemType(), - ((ArrayType) realType).getItemType()); + return processComplexType(((ArrayType) signatureType).getItemType(), + ((ArrayType) realType).getItemType(), processor); } else if (signatureType instanceof MapType && realType instanceof MapType) { - return processor.apply(((MapType) signatureType).getKeyType(), ((MapType) realType).getKeyType()) - && processor.apply(((MapType) signatureType).getValueType(), ((MapType) realType).getValueType()); + return processComplexType(((MapType) signatureType).getKeyType(), + ((MapType) realType).getKeyType(), processor) + && processComplexType(((MapType) signatureType).getValueType(), + ((MapType) realType).getValueType(), processor); } else if (signatureType instanceof StructType && realType instanceof StructType) { // TODO: do not support struct type now // throw new AnalysisException("do not support struct type now"); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/IdenticalSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/IdenticalSignature.java index f8497248c31..410074124e0 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/IdenticalSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/IdenticalSignature.java @@ -33,6 +33,12 @@ import java.util.List; public interface IdenticalSignature extends ComputeSignature { /** isIdentical */ static boolean isIdentical(DataType signatureType, DataType realType) { + return ComputeSignature.processComplexType( + signatureType, realType, IdenticalSignature::isPrimitiveIdentical); + } + + /** isIdentical */ + static boolean isPrimitiveIdentical(DataType signatureType, DataType realType) { try { // TODO: copy matchesType to DataType // TODO: resolve AnyDataType invoke toCatalogDataType diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/NullOrIdenticalSignature.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/NullOrIdenticalSignature.java index 948ce448b50..37530bc8b1c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/NullOrIdenticalSignature.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/expressions/functions/NullOrIdenticalSignature.java @@ -31,8 +31,14 @@ import java.util.List; * when matching a particular instantiation. That is, their fixed arguments. */ public interface NullOrIdenticalSignature extends ComputeSignature { - /** isNullOrIdentical */ + static boolean isNullOrIdentical(DataType signatureType, DataType realType) { + return ComputeSignature.processComplexType( + signatureType, realType, NullOrIdenticalSignature::isPrimitiveNullOrIdentical); + } + + /** isNullOrIdentical */ + static boolean isPrimitiveNullOrIdentical(DataType signatureType, DataType realType) { try { // TODO: copy matchesType to DataType // TODO: resolve AnyDataType invoke toCatalogDataType diff --git a/regression-test/suites/nereids_syntax_p0/test_literal.groovy b/regression-test/suites/nereids_syntax_p0/test_literal.groovy new file mode 100644 index 00000000000..d3ed7d44098 --- /dev/null +++ b/regression-test/suites/nereids_syntax_p0/test_literal.groovy @@ -0,0 +1,27 @@ +// 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. + +suite("test_literal") { + sql 'set enable_nereids_planner=true' + sql 'set enable_fallback_to_original_planner=false' + + + // test map and array empty literal + sql """ + select {}, [], [[[null]], [[1, 2, 3]]], {1:[null], 3:[3]}; + """ +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org