in tools/automatic_query_fixer/src/main/java/com/google/cloud/bigquery/utils/queryfixer/fixer/NoMatchingSignatureFixer.java [96:137]
private List<String> convert(
List<NoMatchingSignatureError.ArgumentType> arguments,
NoMatchingSignatureError.Signature signature) {
List<String> argumentTemplates = new ArrayList<>();
// A wildcard to match ANY type.
String any = null;
boolean atRequired = true;
int argsIndex = 0;
for (int i = 0; i < arguments.size(); i++) {
NoMatchingSignatureError.ArgumentType argument = arguments.get(i);
String sourceType = argument.getDataType();
NoMatchingSignatureError.ArgumentType expectedArgument =
getArgumentType(signature, atRequired, argsIndex);
if (expectedArgument == null) {
return null;
}
String expectedType = expectedArgument.getDataType();
// ANY equals the data type that matches the first ANY.
if (expectedType.equals(TypeCast.ANY)) {
expectedType = any == null ? any = sourceType : any;
}
String argumentHolder;
// place holder is 1-based index.
if (expectedType.equals(sourceType)) {
argumentHolder = String.format("{%s}", i + 1);
} else {
argumentHolder = TypeCast.getCastTemplate(expectedType, sourceType, i + 1);
}
argumentTemplates.add(argumentHolder);
argsIndex++;
// After matching all the required argument, it will start to match optional arguments.
if (atRequired && argsIndex == signature.getRequired().size()) {
atRequired = false;
argsIndex = 0;
}
}
return argumentTemplates;
}