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


The following commit(s) were added to refs/heads/master by this push:
     new 37331a0  [hotfix][table-common] Enrich the output type of 
InputTypeValidators#getExpectedSignature.
37331a0 is described below

commit 37331a01b257693f0b2c746219b9277535044ef4
Author: Dawid Wysakowicz <[email protected]>
AuthorDate: Thu Jun 27 09:57:00 2019 +0200

    [hotfix][table-common] Enrich the output type of 
InputTypeValidators#getExpectedSignature.
---
 .../table/types/inference/InputTypeValidator.java  |   7 +-
 .../flink/table/types/inference/Signature.java     | 104 +++++++++++++++++++++
 .../table/types/inference/TypeInferenceUtil.java   |  26 +++++-
 .../inference/validators/PassingTypeValidator.java |   6 +-
 4 files changed, 131 insertions(+), 12 deletions(-)

diff --git 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeValidator.java
 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeValidator.java
index 09fbaf2..b3bf89f 100644
--- 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeValidator.java
+++ 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/InputTypeValidator.java
@@ -51,10 +51,7 @@ public interface InputTypeValidator {
        /**
         * Returns a summary of the function's expected signatures.
         *
-        * <p>e.g. "SUBSTR(string VARCHAR, start INTEGER, length INTEGER)", 
"SUBSTR(string VARCHAR, start INTEGER)"
-        *
-        * @param name the function's name usually referencing the function in 
a catalog; the name is
-        *             meant for debugging purposes only.
+        * @param definition the function definition that defines the function 
currently being called.
         */
-       List<String> getExpectedSignatures(String name, FunctionDefinition 
definition);
+       List<Signature> getExpectedSignatures(FunctionDefinition definition);
 }
diff --git 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/Signature.java
 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/Signature.java
new file mode 100644
index 0000000..cf53f74
--- /dev/null
+++ 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/Signature.java
@@ -0,0 +1,104 @@
+/*
+ * 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.flink.table.types.inference;
+
+import org.apache.flink.annotation.PublicEvolving;
+import org.apache.flink.table.functions.FunctionDefinition;
+import org.apache.flink.util.Preconditions;
+
+import javax.annotation.Nullable;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * Describes the signature of a function. It is meant for representing 
information for debugging
+ * purposes.
+ *
+ * <p>A signature is returned from {@link 
InputTypeValidator#getExpectedSignatures(FunctionDefinition)}.
+ */
+@PublicEvolving
+public final class Signature {
+
+       private final List<Argument> arguments;
+
+       private Signature(List<Argument> arguments) {
+               this.arguments = Preconditions.checkNotNull(arguments, 
"Argument must not be null.");
+       }
+
+       /**
+        * Creates an immutable instance of {@link Signature}.
+        */
+       public static Signature of(Argument... arguments) {
+               return new Signature(Arrays.asList(arguments));
+       }
+
+       /**
+        * Creates an immutable instance of {@link Signature}.
+        */
+       public static Signature of(List<Argument> arguments) {
+               return new Signature(arguments);
+       }
+
+       public List<Argument> getArguments() {
+               return arguments;
+       }
+
+       /**
+        * Representation of a single argument in a signature.
+        *
+        * <p>The type is represented as {@link String} in order to also 
express type families or varargs.
+        */
+       public static final class Argument {
+
+               private final @Nullable String name;
+
+               private final String type;
+
+               private Argument(@Nullable String name, String type) {
+                       this.name = name;
+                       this.type = Preconditions.checkNotNull(type);
+               }
+
+               /**
+                * Returns an instance of {@link Argument}.
+                */
+               public static Argument of(String name, String type) {
+                       return new Argument(
+                               Preconditions.checkNotNull(name, "Name must not 
be null."),
+                               type);
+               }
+
+               /**
+                * Returns an instance of {@link Argument}.
+                */
+               public static Argument of(String type) {
+                       return new Argument(null, type);
+               }
+
+               public Optional<String> getName() {
+                       return Optional.ofNullable(name);
+               }
+
+               public String getType() {
+                       return type;
+               }
+       }
+}
diff --git 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/TypeInferenceUtil.java
 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/TypeInferenceUtil.java
index e6cca85..045ec0e 100644
--- 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/TypeInferenceUtil.java
+++ 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/TypeInferenceUtil.java
@@ -133,14 +133,30 @@ public final class TypeInferenceUtil {
        private static ValidationException getInvalidInputException(
                        InputTypeValidator validator,
                        CallContext callContext) {
+
+               final String expectedSignatures = 
validator.getExpectedSignatures(callContext.getFunctionDefinition())
+                       .stream()
+                       .map(s -> formatSignature(callContext.getName(), s))
+                       .collect(Collectors.joining("\n"));
                return new ValidationException(
                        String.format(
                                "Invalid input arguments. Expected signatures 
are:\n%s",
-                               String.join(
-                                       "\n",
-                                       validator.getExpectedSignatures(
-                                               callContext.getName(),
-                                               
callContext.getFunctionDefinition()))));
+                               expectedSignatures));
+       }
+
+       private static String formatSignature(String name, Signature s) {
+               final String arguments = s.getArguments()
+                       .stream()
+                       .map(TypeInferenceUtil::formatArgument)
+                       .collect(Collectors.joining(", "));
+               return String.format("%s(%s)", name, arguments);
+       }
+
+       private static String formatArgument(Signature.Argument arg) {
+               final StringBuilder stringBuilder = new StringBuilder();
+               arg.getName().ifPresent(n -> stringBuilder.append(n).append(" 
=> "));
+               stringBuilder.append(arg.getType());
+               return stringBuilder.toString();
        }
 
        private static void validateArgumentCount(ArgumentCount argumentCount, 
int actualCount) {
diff --git 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/validators/PassingTypeValidator.java
 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/validators/PassingTypeValidator.java
index e8ba511..0cd8cd4 100644
--- 
a/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/validators/PassingTypeValidator.java
+++ 
b/flink-table/flink-table-common/src/main/java/org/apache/flink/table/types/inference/validators/PassingTypeValidator.java
@@ -23,6 +23,8 @@ import org.apache.flink.table.functions.FunctionDefinition;
 import org.apache.flink.table.types.inference.ArgumentCount;
 import org.apache.flink.table.types.inference.CallContext;
 import org.apache.flink.table.types.inference.InputTypeValidator;
+import org.apache.flink.table.types.inference.Signature;
+import org.apache.flink.table.types.inference.Signature.Argument;
 
 import java.util.Collections;
 import java.util.List;
@@ -47,8 +49,8 @@ public class PassingTypeValidator implements 
InputTypeValidator {
        }
 
        @Override
-       public List<String> getExpectedSignatures(String name, 
FunctionDefinition definition) {
-               return Collections.singletonList(name + "(*)");
+       public List<Signature> getExpectedSignatures(FunctionDefinition 
definition) {
+               return 
Collections.singletonList(Signature.of(Argument.of("*")));
        }
 
        private static class PassingArgumentCount implements ArgumentCount {

Reply via email to