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
35 stars 8 forks source link

Getting Invalid SQL type: date error queries with declare statements #32

Closed TunahanOcal closed 2 months ago

TunahanOcal commented 6 months ago

Hello,

I am getting type errors, if the query has declare statements. You can see the example declare statements and the exception below.

declare _delta_date_min date;
declare _delta_date_max date;
Exception in thread "main" com.google.zetasql.toolkit.catalog.typeparser.ZetaSQLTypeParseError: Invalid SQL type: date
    at com.google.zetasql.toolkit.catalog.typeparser.ZetaSQLTypeParser.parse(ZetaSQLTypeParser.java:77)
    at com.google.zetasql.toolkit.ZetaSQLToolkitAnalyzer$StatementAnalyzer.parseASTType(ZetaSQLToolkitAnalyzer.java:253)
    at java.base/java.util.Optional.map(Optional.java:265)
    at com.google.zetasql.toolkit.ZetaSQLToolkitAnalyzer$StatementAnalyzer.applyVariableDeclaration(ZetaSQLToolkitAnalyzer.java:285)
    at com.google.zetasql.toolkit.ZetaSQLToolkitAnalyzer$StatementAnalyzer.next(ZetaSQLToolkitAnalyzer.java:195)
    at com.google.zetasql.toolkit.ZetaSQLToolkitAnalyzer$StatementAnalyzer.next(ZetaSQLToolkitAnalyzer.java:148)

Thanks in advance.

TunahanOcal commented 6 months ago

I just noticed that if the variable types are written in lowercase, errors will occur; whereas, if the types are written in uppercase, there will be no exception.

marcinp55 commented 6 months ago

I'm getting the same exception and changing the types to uppercase really does solve the problem. Given that SQL is case-insensitive that's quite unexpected.

ppaglilla commented 2 months ago

Fixed in 6e51423e387e890b587f9bb03c36bc826340a6fd, will be included in the next release. This release has been a long time coming, but should release shortly.

ppaglilla commented 2 months ago

Version 0.5.0 has been released with the fix for this issue and is already available through maven