-
Notifications
You must be signed in to change notification settings - Fork 182
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
Unknown type JSON #544
Comments
I can get around the issue by converting JSON to plain string in the new table using the conversion function |
In R, would expect to get a parsed object or just a string containing JSON? |
the object would be ideal but the sting will do too, perhaps it can be an option |
Could you help me get your SQL to work? This is what I see: library(bigrquery)
options(gargle_oauth_email = TRUE)
con <- DBI::dbConnect(bq_test_dataset())
#> ℹ The bigrquery package is using a cached token for 'hadley@posit.co'.
DBI::dbExecute(con, "CREATE TABLE bigquery (
id INT,
data JSON
);")
#> [1] 0
DBI::dbExecute(con, r"(INSERT INTO bigquery (id, data)
VALUES (1, '{"name": "John", "age": 30, "city": "New York"}');)")
#> Error in `bq_job_wait()` at bigrquery/R/dbi-result.R:21:3:
#> ! Job 'gargle-169921.job_56LyAlmx4LgUkfwQ_97LO2Q2LaAd.US' failed
#> ✖ Value has type STRING which cannot be inserted into column data, which has type JSON at [2:12] [invalidQuery] Created on 2023-11-09 with reprex v2.0.2.9000 |
Don't worry, found an example in the google docs: library(bigrquery)
options(gargle_oauth_email = TRUE)
ds <- bq_test_dataset()
#> ℹ The bigrquery package is using a cached token for 'hadley@posit.co'.
con <- DBI::dbConnect(ds)
DBI::dbExecute(con, "CREATE TABLE table1(
id INT64,
cart JSON
)")
#> [1] 0
DBI::dbExecute(con, r"(
INSERT INTO table1 VALUES
(1, JSON '{"name": "Alice", "age": 30}'),
(2, JSON_ARRAY(10, ['foo', 'bar'], [20, 30])),
(3, JSON_OBJECT('foo', 10, 'bar', ['a', 'b']));
)")
#> [1] 3
DBI::dbReadTable(con, "table1")
#> Error in eval(expr, envir, enclos): Unknown type JSON Created on 2023-11-09 with reprex v2.0.2.9000 |
Hmmm, I think I'm going to move to a strategy where for unknown field types I just return the string that BigQuery sends me. Then it'll be up to you to parse it. |
Getting error "Unknown type JSON" from function bq_table_download() while trying to download table that includes field of type JSON .
to reproduce, in Google Cloud SQL Workspace
bq_table_download()
The text was updated successfully, but these errors were encountered: