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

null pointer exception sql queries includes unnest expression #51

Closed TunahanOcal closed 6 months ago

TunahanOcal commented 6 months ago

Hello, First of all, thank you for the new version of the toolkit. After changing the version to 5.0, I encountered an error when the SQL code has unnest expression. After debugging the code I see that the ASTPathExpression in ASTTablePathExpression which contains unnest expression is null.

You can see where the null pointer error occurs below.

List<ASTNodes.ASTPathExpression> pathExpressions = (List)getResourcePathExpressionFromParseTree(parsedStatement).stream().sorted(Comparator.comparing((expression) -> {
            return expression.getParseLocationRange().start();
        })).collect(Collectors.toList());

You can see the error below:

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: java.lang.NullPointerException: Cannot invoke "com.google.zetasql.parser.ASTNodes$ASTPathExpression.getParseLocationRange()" because "expression" is null] with root cause
java.lang.NullPointerException: Cannot invoke "com.google.zetasql.parser.ASTNodes$ASTPathExpression.getParseLocationRange()" because "expression" is null
    at com.google.zetasql.toolkit.StatementRewriter.lambda$quoteNamePaths$0(StatementRewriter.java:123)
    at java.base/java.util.Comparator.lambda$comparing$77a9974f$1(Comparator.java:473)
    at java.base/java.util.TimSort.countRunAndMakeAscending(TimSort.java:360)
    at java.base/java.util.TimSort.sort(TimSort.java:220)
    at java.base/java.util.Arrays.sort(Arrays.java:1308)
    at java.base/java.util.stream.SortedOps$SizedRefSortingSink.end(SortedOps.java:353)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
    at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
    at com.google.zetasql.toolkit.StatementRewriter.quoteNamePaths(StatementRewriter.java:124)
    at com.google.zetasql.toolkit.ZetaSQLToolkitAnalyzer$StatementAnalyzer.next(ZetaSQLToolkitAnalyzer.java:210)
    at com.google.zetasql.toolkit.ZetaSQLToolkitAnalyzer$StatementAnalyzer.next(ZetaSQLToolkitAnalyzer.java:148)
ppaglilla commented 6 months ago

Thank you for reporting! Fixed in version 0.5.1.

There's not announcement in the repository yet, but it was released to maven already.