Skip to content

Commit

Permalink
added error message for ambiguous function call
Browse files Browse the repository at this point in the history
  • Loading branch information
Sullivan-Patrick committed Jun 24, 2021
1 parent ea9572e commit 1cf3256
Showing 1 changed file with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,19 @@ private Optional<T> findMatchingCandidate(
final int len = candidates.size();
if (len == 1) {
return Optional.of(candidates.get(0).value);
} else if (len > 1 && candidates.get(len - 1).compare(candidates.get(len - 2)) > 0) {
return Optional.of(candidates.get(len - 1).value);
} else if (len > 1) {
if (candidates.get(len - 1).compare(candidates.get(len - 2)) > 0) {
return Optional.of(candidates.get(len - 1).value);
}
throw new KsqlException("Function " + udfName
+ " cannot be resolved due to ambiguous method call "
+ getParamsAsString(arguments) + "."
+ System.lineSeparator()
+ "Valid function calls are:"
+ System.lineSeparator()
+ getAcceptedTypesAsString()
+ System.lineSeparator()
+ "For detailed information on a function run: DESCRIBE FUNCTION <Function-Name>;");
}

return Optional.empty();
Expand Down Expand Up @@ -205,10 +216,8 @@ private void getCandidates(
}
}

private KsqlException createNoMatchingFunctionException(final List<SqlArgument> paramTypes) {
LOG.debug("Current UdfIndex:\n{}", describe());

final String requiredTypes = paramTypes.stream()
private String getParamsAsString(final List<SqlArgument> paramTypes){
return paramTypes.stream()
.map(argument -> {
if (argument == null) {
return "null";
Expand All @@ -217,10 +226,20 @@ private KsqlException createNoMatchingFunctionException(final List<SqlArgument>
}
})
.collect(Collectors.joining(", ", "(", ")"));
}

final String acceptedTypes = allFunctions.values().stream()
private String getAcceptedTypesAsString(){
return allFunctions.values().stream()
.map(UdfIndex::formatAvailableSignatures)
.collect(Collectors.joining(System.lineSeparator()));
}

private KsqlException createNoMatchingFunctionException(final List<SqlArgument> paramTypes) {
LOG.debug("Current UdfIndex:\n{}", describe());

final String requiredTypes = getParamsAsString(paramTypes);

final String acceptedTypes = getAcceptedTypesAsString();

return new KsqlException("Function '" + udfName
+ "' does not accept parameters " + requiredTypes + "."
Expand Down

0 comments on commit 1cf3256

Please sign in to comment.