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

[Question] does not supported Positional Parameters? #25

Closed
halnique opened this issue Aug 26, 2022 · 5 comments
Closed

[Question] does not supported Positional Parameters? #25

halnique opened this issue Aug 26, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@halnique
Copy link

Thanks for the goccy/bigquery-emulator, it is a very useful feature.

Can I use BigQuery Positional Parameters?
https://cloud.google.com/bigquery/docs/samples/bigquery-query-params-positional

In my environment, an error has occurred. (Using docker image)

$ bq --api http://0.0.0.0:9050 query --use_legacy_sql=false --parameter=:integer:1 --project_id=test "select * from dataset1.table_a where id = ?"
You have encountered a bug in the BigQuery CLI. Please file a bug report in our public issue tracker:
https://issuetracker.google.com/issues/new?component=187149&template=0
Please include a brief description of the steps that led to this issue, as well as any rows that can be made public from the following information:

========================================
== Platform ==
  CPython:2.7.16:Darwin-19.6.0-x86_64-i386-64bit
== bq version ==
  2.0.75

...

========================================

Unexpected exception in query operation: You have encountered a bug in the BigQuery CLI. Please file a bug report in our public issue tracker:
https://issuetracker.google.com/issues/new?component=187149&template=0
Please include a brief description of the steps that led to this issue, as well as any rows that can be made public from the following information:

bigquery-emulator logged the following.

2022-08-26T03:24:31.949Z	INFO	server/middleware.go:41	GET /discovery/v1/apis/bigquery/v2/rest	{"query": ""}
2022-08-26T03:24:31.977Z	INFO	server/middleware.go:41	POST /projects/test/jobs	{"query": "alt=json"}
2022-08-26T03:24:31.982Z	INFO	contentdata/repository.go:145		{"query": "select * from dataset1.table_a where id = ?", "values": ["1"]}
2022-08-26T03:24:31.990Z	INFO	server/middleware.go:41	GET /projects/test/queries/bqjob_r4eb0707bb65b00af_00000182d82e0938_1	{"query": "timeoutMs=0&startIndex=0&alt=json&maxResults=100"}
2022-08-26T03:24:32.097Z	ERROR	server/handler.go:41	internal error	{"error": "INVALID_ARGUMENT: Positional parameters are not supported [at 1:43]"}

In actual Google BigQuery, it works as follows.

$ bq query --use_legacy_sql=false --parameter=:integer:1 --project_id=my-project 'select * from dataset1.table_a where id = ?'
[
  {
    "id": "1", 
    "name": "alice"
  }
]

Is there any option to make Positional Parameters available?

@halnique
Copy link
Author

I have confirmed that Named Parameters is working.

$ bq --api http://0.0.0.0:9050 query --use_legacy_sql=false --parameter=id:integer:1 --project_id=test "select * from dataset1.table_a where id = @id"
[
  {
    "id": "1", 
    "name": "alice"
  }
]

bigquery-emulator logged the following.

2022-08-26T03:43:43.254Z	INFO	server/middleware.go:41	GET /discovery/v1/apis/bigquery/v2/rest	{"query": ""}
2022-08-26T03:43:43.282Z	INFO	server/middleware.go:41	POST /projects/test/jobs	{"query": "alt=json"}
2022-08-26T03:43:43.286Z	INFO	contentdata/repository.go:145		{"query": "select * from dataset1.table_a where id = @id", "values": ["1"]}
2022-08-26T03:43:43.286Z	DEBUG	contentdata/repository.go:208	query result	{"rows": [[1,"alice"]]}
2022-08-26T03:43:43.294Z	INFO	server/middleware.go:41	GET /projects/test/queries/bqjob_r3513523cffe35404_00000182d83f9a8e_1	{"query": "timeoutMs=0&startIndex=0&alt=json&maxResults=100"}

@goccy
Copy link
Owner

goccy commented Aug 26, 2022

There is a type called ParameterMode in go-zetasql ( https://github.com/goccy/go-zetasql/blob/c0cdb2761078bdee9a269bcb29da4686d7ad4869/enum.go#L6-L19 ) that bigquery emulator uses.
As far as I know, this value can only be applied one at a time, so it may be difficult to enable positional parameter or named parameter at the same time 🤔

@goccy
Copy link
Owner

goccy commented Aug 26, 2022

I found a way to solve this problem ! I'll fix this problem as soon as possible !

@halnique
Copy link
Author

Amazing! I will look forward to it.

@goccy goccy added the enhancement New feature or request label Aug 26, 2022
@goccy
Copy link
Owner

goccy commented Aug 27, 2022

This issue has been fixed in v0.1.7. If you have any problems, please reopen this.

@goccy goccy closed this as completed Aug 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants