Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyze queries with DECLARE #139

Open
emersonlesage opened this issue May 1, 2023 · 3 comments
Open

Analyze queries with DECLARE #139

emersonlesage opened this issue May 1, 2023 · 3 comments

Comments

@emersonlesage
Copy link

Does the analyzer support queries that contain DECLARE statements? Im getting "unexpected token: DECLARE" errors when running it.

@matthewcbrown
Copy link
Collaborator

It's often helpful to provide some context when requesting help.
For instance, what query are you running?
What API are you calling?

But, to answer your question as best I can. Yes, the analyzer supports queries that contain DECLARE statements.

@emersonlesage
Copy link
Author

Thanks for the reply, and sorry I should have included more details.

I am following the AnalyzeBigQuery.java file here: https://github.com/GoogleCloudPlatform/professional-services/blob/main/tools/zetasql-helper/zetasql-toolkit-examples/src/main/java/com/google/zetasql/toolkit/examples/AnalyzeBigQuery.java

and trying to make it work with a modified query that contains a DECLARE statement:

DECLARE my_title STRING DEFAULT 'Unrestricted submarine warfare';
SELECT title, language FROM bigquery-public-data.samples.wikipedia WHERE title = my_title;

Everything builds fine and the original files example files run without issues, but once I include the DECLARE keyword I get the following error:

Exception in thread "main" com.google.zetasql.SqlException: Syntax error: Unexpected keyword DECLARE [at 1:1]
at com.google.zetasql.Analyzer.analyzeNextStatement(Analyzer.java:220)
at com.google.zetasql.toolkit.ZetaSQLToolkitAnalyzer$1.next(ZetaSQLToolkitAnalyzer.java:144)
at com.google.zetasql.toolkit.ZetaSQLToolkitAnalyzer$1.next(ZetaSQLToolkitAnalyzer.java:1)
at java.base/java.util.Iterator.forEachRemaining(Iterator.java:133)
at com.google.zetasql.toolkit.examples.AnalyzeBigQuery.main(AnalyzeBigQuery.java:72)
Caused by: com.google.zetasql.io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Syntax error: Unexpected keyword DECLARE [at 1:1]
at com.google.zetasql.io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:262)
at com.google.zetasql.io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:243)
at com.google.zetasql.io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:156)
at com.google.zetasql.ZetaSqlLocalServiceGrpc$ZetaSqlLocalServiceBlockingStub.analyze(ZetaSqlLocalServiceGrpc.java:1506)
at com.google.zetasql.Analyzer.analyzeNextStatement(Analyzer.java:218)
... 4 more

Furthermore I am running this within the Google Cloud Shell. I suspect that I need to add the declared variable to the bigquery catalog but am unsure how to do so, any help would be much appreciated!

@masterlittle
Copy link

DECLARE statements are considered a part of script in Bigquery. That's not supported in Zetasql currently.

Though I also tried finding how to add a constant in a simple catalog but could not find how to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants