GoogleCloudPlatform / zetasql-toolkit

The ZetaSQL Toolkit is a library that helps users use ZetaSQL Java API to perform SQL analysis for multiple query engines, including BigQuery and Cloud Spanner.
Apache License 2.0
39 stars 10 forks source link

Function Not Found error for UDF functions when used in variable declaration. #92

Open TunahanOcal opened 2 months ago

TunahanOcal commented 2 months ago

Hi, If there is a user defined function and it is used in variable declaration, it cannot be found even if it is added to catalog. I am using the same function in other queries not having variable declaration I do not get any error. I have debugged the code it is throwing error in analyzeExpression method. I also checked the catalog from debugger it contains my in customFunctions

public static ResolvedNodes.ResolvedExpr analyzeExpression(String expression, AnalyzerOptions options, SimpleCatalog catalog) {
        LocalService.AnalyzeRequest.Builder request = AnalyzeRequest.newBuilder().setSqlExpression(expression);
        FileDescriptorSetsBuilder fileDescriptorSetsBuilder = AnalyzerHelper.serializeSimpleCatalog(catalog, options, request);

        LocalService.AnalyzeResponse response;
        try {
            response = Client.getStub().analyze(request.build());
        } catch (StatusRuntimeException var7) {
            StatusRuntimeException e = var7;
            throw new SqlException(e);
        }

        return AnalyzerHelper.deserializeResolvedExpression(catalog, fileDescriptorSetsBuilder, response);
    }

Thanks in advance.

dion-ricky commented 2 months ago

Hi, can you provide any example? I am unable to recreate the issue, I used this query and it works without raising any exception:

CREATE `project.dataset.func_name`()
RETURNS INT64
AS (
  10
);
DECLARE foo INT64 DEFAULT `project.dataset.func_name`();
TunahanOcal commented 1 week ago

Hi, I have found that, it happens when the UDF is not quoted. Can we add StatementRewriter.quoteNamePaths function for the variable declarations.