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

    https://github.com/apache/spark/pull/18498#discussion_r126298114
  
    --- Diff: R/pkg/R/functions.R ---
    @@ -2163,10 +2164,15 @@ setMethod("date_format", signature(y = "Column", x 
= "character"),
     #' df2 <- sql("SELECT named_struct('name', 'Bob') as people")
     #' df2 <- mutate(df2, people_json = to_json(df2$people))
     #' schema <- structType(structField("name", "string"))
    -#' head(select(df2, from_json(df2$people_json, schema)))}
    +#' head(select(df2, from_json(df2$people_json, schema)))
    +#' head(select(df2, from_json(df2$people_json, "name STRING")))}
     #' @note from_json since 2.2.0
    -setMethod("from_json", signature(x = "Column", schema = "structType"),
    +setMethod("from_json", signature(x = "Column", schema = 
"characterOrstructType"),
               function(x, schema, as.json.array = FALSE, ...) {
    +            if (is.character(schema)) {
    +              schema <- structTypeFromDDL(schema)
    +            }
    --- End diff --
    
    that's also a good point. I'd much rather use the DDL form instead of more 
verbose JSON, more so since R doesn't have built-in support for JSON (though 
jsonlite is very popular).
    
    the main reason I ask is if it is a string in general the method can be 
defined as
    `structType.character` in which an user can call it by simply 
`structType("a STRING, b INT")` which might be more intuitive. do you think 
it's worthwhile to simply do that without supporting JSON format for now (or 
ever)?


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to