From 4b85c2738e649d445b27c77e09ab3305e1dbc311 Mon Sep 17 00:00:00 2001 From: xy720 <22125576+xy720@users.noreply.github.com> Date: Thu, 4 May 2023 23:45:22 +0800 Subject: [PATCH] [bug](function)fix potential npe in getFunction() when fe restart (#18989) fix potential npe in getFunction() when fe restart --- .../org/apache/doris/catalog/FunctionSet.java | 3 +-- .../org/apache/doris/catalog/FunctionSetTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java index be8d944423..b633e4ec7c 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/FunctionSet.java @@ -1290,8 +1290,7 @@ public class FunctionSet { if (f.hasTemplateArg()) { f = specializeTemplateFunction(f, desc, f.hasVariadicTemplateArg()); } - f = resolveInferenceFunction(f, desc); - if (f != null) { + if (f != null && (f = resolveInferenceFunction(f, desc)) != null) { inferredFunctions.add(f); } } diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionSetTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionSetTest.java index ccdfd46574..737a3f9b40 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionSetTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/FunctionSetTest.java @@ -18,7 +18,9 @@ package org.apache.doris.catalog; import org.apache.doris.analysis.FunctionName; +import org.apache.doris.catalog.Function.CompareMode; +import com.google.common.collect.Lists; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -52,4 +54,17 @@ public class FunctionSetTest { Assert.assertTrue(newArgTypes[0].matchesType(ScalarType.VARCHAR)); } + @Test + public void testAddInferenceFunction() { + TemplateType type1 = new TemplateType("T"); + TemplateType type2 = new TemplateType("T"); + functionSet.addBuiltinBothScalaAndVectorized(ScalarFunction.createBuiltin( + "test_a", Type.ANY_TYPE, Lists.newArrayList(type1, type2), false, + "", "", "", true)); + Type[] argTypes = {ArrayType.create(), ScalarType.INT}; + Function desc = new Function(new FunctionName("test_a"), Arrays.asList(argTypes), ScalarType.INVALID, false); + Function result = functionSet.getFunction(desc, CompareMode.IS_IDENTICAL); + Assert.assertNull(result); + } + }