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

spannertest: limitation of "UNNEST" clause usage #3296

Closed
sryoya opened this issue Dec 1, 2020 · 4 comments · Fixed by #3431
Closed

spannertest: limitation of "UNNEST" clause usage #3296

sryoya opened this issue Dec 1, 2020 · 4 comments · Fixed by #3431
Assignees
Labels
api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@sryoya
Copy link
Contributor

sryoya commented Dec 1, 2020

Is your feature request related to a problem? Please describe.
It seems AS clause cannot be used to the output from UNNEST.

I tried to run the below SQL in spannertest/intergration_test.go when I was developing #3286 , but received below error.

SELECT AVG(x) as avg FROM UNNEST([0, 2, 4, 4, 5]) as x
spanner: code = "InvalidArgument", desc = "bad query: unexpected trailing query contents \"([0, 2, 4, 4, 5]) AS x\

I have not pursed which code causes this issue, but I guess the parsing logic in spansql may have a point to improve.

@dsymonds
Copy link
Contributor

dsymonds commented Dec 1, 2020

It is because the array literal is unsupported (this is in the README.md). FWIW, it should work with ... UNNEST(@p) for some param.

@sryoya
Copy link
Contributor Author

sryoya commented Dec 1, 2020

Thank you for your explanation. My doubt on AS clause seems to be off the mark.

But, is "UNNEST soon after FROM" also unsupported?

I used UNNEST(@p) as you said, and tried the below SQL.

		{
			`SELECT * FROM UNNEST(@p)`,
			map[string]interface{}{"p": []int64{3, 1}},
			[][]interface{}{
				{int64(3)},
				{int64(1)},
			},
		},

But, it got the following error.

spanner: code = "InvalidArgument", desc = "bad query: unexpected trailing query contents \"(@p)\""

And, if I use UNNEST in WHERE clause like this, it runs successfully.

		{
			`SELECT * FROM Staff WHERE ID IN UNNEST(@p)`,
			map[string]interface{}{"p": []int64{3, 1}},
			[][]interface{}{
				{int64(3)},
				{int64(1)},
			},
		},

Based on the above, "UNNEST" itself works by avoiding hard-coded the array literal as you say, but, it may not work soon after "FROM" .

Let me know if you have anything else.

@sryoya sryoya changed the title spannertest: Support "AS" clause to UNNEST spannertest: limitation of "UNNEST" clause usage Dec 1, 2020
@dsymonds
Copy link
Contributor

dsymonds commented Dec 1, 2020

Ah, right. UNNEST works in expressions, but does not work as a SELECT target.

@sryoya
Copy link
Contributor Author

sryoya commented Dec 1, 2020

I see. Thanks. That seems the very reason my SQL doesn't work.

@skuruppu skuruppu added the api: spanner Issues related to the Spanner API. label Dec 1, 2020
@skuruppu skuruppu added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed triage me I really want to be triaged. labels Dec 1, 2020
gcf-merge-on-green bot pushed a commit that referenced this issue Dec 9, 2020
This does not implement array literals, but now arrays provided as query
parameters may be used as SELECT targets.

Fixes #3296.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: spanner Issues related to the Spanner API. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants