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

BigQuery wrapper: JSON, Numeric not supported #70

Closed
yan-hic opened this issue Mar 10, 2023 · 5 comments
Closed

BigQuery wrapper: JSON, Numeric not supported #70

yan-hic opened this issue Mar 10, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@yan-hic
Copy link

yan-hic commented Mar 10, 2023

Trying to query a table with JSON data type in BigQuery.

Foreign table, with json column type, gets created fine but upon querying, the wrapper returns:

Failed to run sql query: get table metadata failed: Request error (error: error decoding response body: unknown variant `JSON`, expected one of `STRING`, `BYTES`, `INTEGER`, `INT64`, `FLOAT`, `FLOAT64`, `NUMERIC`, `BIGNUMERIC`, `BOOLEAN`, `BOOL`, `TIMESTAMP`, `DATE`, `TIME`, `DATETIME`, `RECORD`, `STRUCT` at line 15 column 22)
@yan-hic yan-hic added the bug Something isn't working label Mar 10, 2023
@yan-hic
Copy link
Author

yan-hic commented Mar 11, 2023

Workaround:

  1. cast to string on BQ side with to_json_string()
  2. create PG view that casts back to json
  3. query that column in graphQL

Interestingly, a view is not necessary if using SQL i.e. found out that, using the foreign table definition as-is (defining column type as json), select column->'sub' from table works.
However

 {
      tableCollection {
        edges {
          node{
            column{
              sub
            } 
	  }
	}
 }

does not work, and returns full column as text value.

EDIT

Documentation was just updated and JSON is always serialized as string in GraphQL: https://supabase.github.io/pg_graphql/api/#json. In SQL or API, one would just cast like json-string::json until the FDW supports it natively.

@burmecia
Copy link
Member

Yes, JSON is not support yet in BigQuery FDW. A workaround is using TO_JSON_STRING to convert JSON to STRING in BigQuery and store that string as source table column. Then use subquery or view on top of PG foreign table and convert that string back to JSON.

@yan-hic
Copy link
Author

yan-hic commented Mar 14, 2023

@burmecia thanks - do you have an ETA and would the wrapper be available in the cloud immediately when released ? I have a few tables with JSON data types in BigQuery and am not authorized to create views (dataset owned by my client).

Ideally, table option would take a subquery as mentioned here. The benefit of it is: subset of columns and computed fields pushed at the source (like casting...). I can create a separate FeatReq for it.

@burmecia
Copy link
Member

We're currently working on improving BigQuery fdw, the JSON support should be ready on the next release. And thanks for the subquery in table option, it is quite useful, we will evaluate and hopefully include it in the future release.

@yan-hic yan-hic changed the title BigQuery wrapper: JSON not supported BigQuery wrapper: JSON, Numeric not supported Apr 2, 2023
@yan-hic
Copy link
Author

yan-hic commented Apr 2, 2023

EDIT: I have edited the title and added Numeric:
Failed to run sql query: field type Numeric not supported

which is a valid type in PG: https://www.postgresql.org/docs/current/datatype-numeric.html and in BigQuery (and is supported by https://github.com/lquerel/gcp-bigquery-client already)

Would be good to add all supported ones or document the limited support.
Thanks.

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