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

JSON_EXTRACT_SCALAR nor JSON_QUERY does not work as expected #286

Open
cdromas opened this issue Mar 14, 2024 · 1 comment
Open

JSON_EXTRACT_SCALAR nor JSON_QUERY does not work as expected #286

cdromas opened this issue Mar 14, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@cdromas
Copy link

cdromas commented Mar 14, 2024

What happened?

Considering having a table named test in a dataset named data_history with a JSON field named data.

SELECT JSON_QUERY(data, '$.data.test') FROM data_history.test WHERE TIMESTAMP_TRUNC(date, DAY) = TIMESTAMP("2024-03-14") LIMIT 1

Return the entire JSON value

What did you expect to happen?

SELECT JSON_QUERY(data, '$.data.test') FROM data_history.test WHERE TIMESTAMP_TRUNC(date, DAY) = TIMESTAMP("2024-03-14") LIMIT 1

The result should be the extracted field test

How can we reproduce it (as minimally and precisely as possible)?

{data:"{"test":"hello"}"}

Anything else we need to know?

No response

@cdromas cdromas added the bug Something isn't working label Mar 14, 2024
@szaffarano
Copy link

To reproduce the issue you can also use the bq client with the sample data as shown in the README

❯ bq --api http://0.0.0.0:9050 query --project_id=test 'SELECT structarr[OFFSET(0)].value.age FROM dataset1.table_a'

+-----------------------------------------+
|                   age                   |
+-----------------------------------------+
| {"age": 10, "nested": {"key": "value"}} |
| {"age": 15, "nested": {"key": "value"}} |
+-----------------------------------------+

❮ bq --api http://0.0.0.0:9050 query --project_id=test 'SELECT structarr[OFFSET(0)].value.nested FROM dataset1.table_a'

+-----------------------------------------+
|                 nested                  |
+-----------------------------------------+
| {"age": 10, "nested": {"key": "value"}} |
| {"age": 15, "nested": {"key": "value"}} |
+-----------------------------------------+

❯ bq --api http://0.0.0.0:9050 query --project_id=test 'SELECT structarr[OFFSET(0)].value.nested.key FROM dataset1.table_a'

+------+
| key  |
+------+
| NULL |
| NULL |
+------+

nested is an extra JSON key I added into server/testdata/data.yaml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants