This is an automated email from the ASF dual-hosted git repository. twalthr pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit 1ee13f261a04b3a5bdb223381348bb7789e60687 Author: Rui Li <li...@apache.org> AuthorDate: Sat Dec 19 17:45:56 2020 +0800 [FLINK-20680][table-common] Fix invalid validation of var-arg function with no parameters --- .../org/apache/flink/table/module/hive/HiveModuleTest.java | 14 ++++++++++++++ .../flink/table/types/extraction/ExtractionUtils.java | 8 +++++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java index 7a99054..76fb190 100644 --- a/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java +++ b/flink-connectors/flink-connector-hive/src/test/java/org/apache/flink/table/module/hive/HiveModuleTest.java @@ -223,4 +223,18 @@ public class HiveModuleTest { tableEnv.sqlQuery("select mod(-1,2),pmod(-1,2)").execute().collect()); assertEquals("[-1,1]", results.toString()); } + + @Test + public void testCallUDFWithNoParam() { + TableEnvironment tableEnv = HiveTestUtils.createTableEnvWithBlinkPlannerBatchMode(); + + tableEnv.unloadModule("core"); + tableEnv.loadModule("hive", new HiveModule()); + tableEnv.loadModule("core", CoreModule.INSTANCE); + + List<Row> results = + CollectionUtil.iteratorToList( + tableEnv.sqlQuery("select `array`(),`map`()").execute().collect()); + assertEquals("[[],{}]", results.toString()); + } } diff --git a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java index 14dde1b..4c502d2 100644 --- a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java +++ b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/extraction/ExtractionUtils.java @@ -92,7 +92,8 @@ public final class ExtractionUtils { final int paramCount = executable.getParameterCount(); final int classCount = classes.length; // check for enough classes for each parameter - if (classCount < paramCount || (executable.isVarArgs() && classCount < paramCount - 1)) { + if ((!executable.isVarArgs() && classCount != paramCount) + || (executable.isVarArgs() && classCount < paramCount - 1)) { return false; } int currentClass = 0; @@ -109,8 +110,9 @@ public final class ExtractionUtils { classes[currentClass], paramComponent, true)) { currentClass++; } - } else if (parameterMatches(classes[currentClass], param) - || parameterMatches(classes[currentClass], paramComponent)) { + } else if (currentClass < classCount + && (parameterMatches(classes[currentClass], param) + || parameterMatches(classes[currentClass], paramComponent))) { currentClass++; } }