Skip to content

Commit

Permalink
Various minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sullivan-Patrick committed Jun 24, 2021
1 parent fca14aa commit be17dd6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
* arguments.</li>
* <li>If two methods exist that match given the above rules, return the
* method with fewer generic arguments.</li>
* <li>If two methods exist that match given the above rules, an exception
* is thrown due to a vague function call</li>
* <li>If two methods exist that match given the above rules, the function
* call is ambiguous and an exception is thrown.</li>
* </ul>
*/
public class UdfIndex<T extends FunctionSignature> {
Expand Down Expand Up @@ -145,28 +145,28 @@ void addFunction(final T function) {
}

T getFunction(final List<SqlArgument> arguments) {
final List<Node> candidates = new ArrayList<>();

// first try to get the candidates without any implicit casting
Optional<T> candidate = findMatchingCandidate(candidates, arguments, false);
Optional<T> candidate = findMatchingCandidate(arguments, false);
if (candidate.isPresent()) {
return candidate.get();
} else if (!supportsImplicitCasts) {
throw createNoMatchingFunctionException(arguments);
}
candidates.clear();

//if non were found (candidate isn't present) try again with implicit casting
candidate = findMatchingCandidate(candidates, arguments, true);
// if none were found (candidate isn't present) try again with implicit casting
candidate = findMatchingCandidate(arguments, true);
if (candidate.isPresent()) {
return candidate.get();
}
throw createNoMatchingFunctionException(arguments);
}

private Optional<T> findMatchingCandidate(final List<Node> candidates,
private Optional<T> findMatchingCandidate(
final List<SqlArgument> arguments, final boolean allowCasts) {

final List<Node> candidates = new ArrayList<>();

getCandidates(arguments, 0, root, candidates, new HashMap<>(), allowCasts);
candidates.sort(Node::compare);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -937,15 +937,15 @@ public void shouldThrowIfNoExactMatchAndImplicitCastDisabled() {
}

@Test
public void shouldThrowWhenGivenVagueImplicitCast() {
public void shouldThrowOnAmbiguousImplicitCastWithoutGenerics() {
// Given:
givenFunctions(
function(FIRST_FUNC, false, LONG, LONG),
function(SECOND_FUNC, false, DOUBLE, DOUBLE)
);

// When:
final Exception e = assertThrows(Exception.class,
final KsqlException e = assertThrows(KsqlException.class,
() -> udfIndex
.getFunction(ImmutableList.of(SqlArgument.of(INTEGER), SqlArgument.of(BIGINT))));

Expand All @@ -971,15 +971,15 @@ public void shouldFindFewerGenerics() {
}

@Test
public void shouldThrowOnComparablyEqualFunctionsWithSameGenericCount() {
public void shouldThrowOnAmbiguousImplicitCastWithGenerics() {
// Given:
givenFunctions(
function(FIRST_FUNC, false, LONG, GenericType.of("A"), GenericType.of("B")),
function(SECOND_FUNC, false, DOUBLE, GenericType.of("A"), GenericType.of("B"))
);

// When:
final Exception e = assertThrows(Exception.class,
final KsqlException e = assertThrows(KsqlException.class,
() -> udfIndex
.getFunction(ImmutableList
.of(SqlArgument.of(INTEGER), SqlArgument.of(INTEGER), SqlArgument.of(INTEGER))));
Expand Down

0 comments on commit be17dd6

Please sign in to comment.