in zetasql-toolkit-bigquery/src/main/java/com/google/zetasql/toolkit/catalog/bigquery/FunctionResultTypeResolver.java [65:92]
private static FunctionArgumentType inferFunctionReturnType(
FunctionSignature signature,
String body,
LanguageOptions languageOptions,
SimpleCatalog catalog) {
AnalyzerOptions analyzerOptions = new AnalyzerOptions();
analyzerOptions.setLanguageOptions(languageOptions);
for (FunctionArgumentType argument : signature.getFunctionArgumentList()) {
if (!argument.isConcrete()) {
throw new CouldNotInferFunctionReturnType(
signature, "Cannot infer the return type of a function with templated arguments");
}
analyzerOptions.addExpressionColumn(
argument.getOptions().getArgumentName(), argument.getType());
}
try {
ResolvedExpr analyzedExpression = Analyzer.analyzeExpression(body, analyzerOptions, catalog);
return new FunctionArgumentType(
analyzedExpression.getType(), FunctionArgumentTypeOptions.builder().build(), 1);
} catch (SqlException sqlException) {
throw new CouldNotInferFunctionReturnType(
signature, "Failed to infer function return type", sqlException);
}
}