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

Add support for analyzing variable declarations and assignments #11

Closed ppaglilla closed 1 year ago

ppaglilla commented 1 year ago

Adds support for analyzing variable declarations and assignments. While the ZetaSQL Analyzer does not support any kind of script statement, we now can handle jobs that include variable declarations and assignments.

ZetaSQLToolkitAnalyzer.analyzeStatements() now returns an Iterator<AnalyzedStatement>; where each AnalyzedStatement has the parsed statement and, optionally, the resolved statement. The resolved statement is only available for statement that can be analyzed.

When encountering a variable declaration, we create a Constant in the Catalog. We also validate the default value expression, if provided.

When encountering an assignment; we validate it and check if the expression is valid, if the variable being assigned to exists and if the expression coerces to the variable type.