Comments (6)
In R, would expect to get a parsed object or just a string containing JSON?
from bigrquery.
the object would be ideal but the sting will do too, perhaps it can be an option parse_json = c("string", "object")
?
from bigrquery.
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.
from bigrquery.
I can get around the issue by converting JSON to plain string in the new table using the conversion function TO_JSON_STRING(json)
, then dropping the column, then converting string to JSON again, but it is a lot of steps.
from bigrquery.
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 '[email protected]'.
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
from bigrquery.
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 '[email protected]'.
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
from bigrquery.
Related Issues (20)
- Use standard argument checkers
- Speed up tests HOT 1
- Update for dbplyr 2.4.0 quoting semantics
- Remove unprefixed deprecated functions
- Switch `expect_error()` to `expect_snapshot()`
- Use sessions HOT 2
- Switch to defer
- Add gzip to user agent? HOT 1
- update scheduled query HOT 8
- Seconds decimal dropped in new parsing HOT 4
- tbl() breaking when used with dbConnect - again? HOT 2
- Release bigrquery 1.5.0
- compute() function in dplyr is broken HOT 2
- Release bigrquery 1.5.1
- compute() permission denied even for temporary tables. HOT 2
- `dbplyr::table_path_components()` fails to parse components as table name is enclosed with backticks HOT 5
- Write a tbl_dbi as a table in bigquery HOT 8
- Improve bq_perform_upload to upload as PARQUET file HOT 1
- bigrquery::bq_auth() Doesn't work, Warning message: Unable to refresh token: invalid_grant Account has been deleted HOT 2
- tbl(con, sql("string query")) errors if the query contains 3 or more periods HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bigrquery.