Giter Site home page Giter Site logo

Unknown type JSON about bigrquery HOT 6 CLOSED

Kvit avatar Kvit commented on June 11, 2024
Unknown type JSON

from bigrquery.

Comments (6)

hadley avatar hadley commented on June 11, 2024 1

In R, would expect to get a parsed object or just a string containing JSON?

from bigrquery.

Kvit avatar Kvit commented on June 11, 2024 1

the object would be ideal but the sting will do too, perhaps it can be an option parse_json = c("string", "object") ?

from bigrquery.

hadley avatar hadley commented on June 11, 2024 1

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.

Kvit avatar Kvit commented on June 11, 2024

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.

hadley avatar hadley commented on June 11, 2024

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.

hadley avatar hadley commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.