Github user felixcheung commented on a diff in the pull request:

    https://github.com/apache/spark/pull/17178#discussion_r104971290
  
    --- Diff: R/pkg/inst/tests/testthat/test_sparkSQL.R ---
    @@ -1342,28 +1342,52 @@ test_that("column functions", {
       df <- read.json(mapTypeJsonPath)
       j <- collect(select(df, alias(to_json(df$info), "json")))
       expect_equal(j[order(j$json), ][1], "{\"age\":16,\"height\":176.5}")
    -  df <- as.DataFrame(j)
    -  schema <- structType(structField("age", "integer"),
    -                       structField("height", "double"))
    -  s <- collect(select(df, alias(from_json(df$json, schema), "structcol")))
    -  expect_equal(ncol(s), 1)
    -  expect_equal(nrow(s), 3)
    -  expect_is(s[[1]][[1]], "struct")
    -  expect_true(any(apply(s, 1, function(x) { x[[1]]$age == 16 } )))
    -
    -  # passing option
    -  df <- as.DataFrame(list(list("col" = "{\"date\":\"21/10/2014\"}")))
    -  schema2 <- structType(structField("date", "date"))
    -  expect_error(tryCatch(collect(select(df, from_json(df$col, schema2))),
    -                        error = function(e) { stop(e) }),
    -               paste0(".*(java.lang.NumberFormatException: For input 
string:).*"))
    -  s <- collect(select(df, from_json(df$col, schema2, dateFormat = 
"dd/MM/yyyy")))
    -  expect_is(s[[1]][[1]]$date, "Date")
    -  expect_equal(as.character(s[[1]][[1]]$date), "2014-10-21")
    -
    -  # check for unparseable
    -  df <- as.DataFrame(list(list("a" = "")))
    -  expect_equal(collect(select(df, from_json(df$a, schema)))[[1]][[1]], NA)
    +
    +  schemas <- list(structType(structField("age", "integer"), 
structField("height", "double")),
    +                  "struct<age:integer,height:double>")
    --- End diff --
    
    If it is a format that is documented and globally defined in Spark, it 
shouldn't be a problem to use that. If a variant of `from_json` is already 
taking a schema string, we should be able call it directly from R without 
having to make it public, although it might make sense to do so, if, say, 
`read.format("json")` supports it too.
    
    I'm not super worry about having a way to produce JSON schema string for 
the R user - we would just accept such JSON schema string and assume the user 
can create it.
    
    But yea, overall this feels very heavy-weighed to support multiple JSON 
objects in a column value. How about just take a bool flag like we started 
with? :)



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to