public static Function get(String keyspace, String name, List<? extends AssignementTestable> providedArgs, ColumnSpecification receiver) throws InvalidRequestException
{
List<Function.Factory> factories = declared.get(name.toLowerCase());
if (factories.isEmpty())
throw new InvalidRequestException(String.format("Unknown CQL3 function %s called", name));
// Fast path if there is not choice
if (factories.size() == 1)
{
Function fun = factories.get(0).create(receiver.ksName, receiver.cfName);
validateTypes(keyspace, fun, providedArgs, receiver);
return fun;
}
Function candidate = null;
for (Function.Factory factory : factories)
{
Function toTest = factory.create(receiver.ksName, receiver.cfName);
if (!isValidType(keyspace, toTest, providedArgs, receiver))
continue;
if (candidate == null)
candidate = toTest;
else
throw new InvalidRequestException(String.format("Ambiguous call to function %s (can match both type signature %s and %s): use type casts to disambiguate", name, signature(candidate), signature(toTest)));
}
if (candidate == null)
throw new InvalidRequestException(String.format("Invalid call to function %s, none of its type signature matches (known type signatures: %s)", name, signatures(factories, receiver)));
return candidate;
}