You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "Hyukjin Kwon (JIRA)" <ji...@apache.org> on 2017/02/14 15:35:41 UTC

[jira] [Updated] (SPARK-19595) from_json produces only a single row when input is a json array

     [ https://issues.apache.org/jira/browse/SPARK-19595?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Hyukjin Kwon updated SPARK-19595:
---------------------------------
    Description: 
Currently, {{from_json}} reads a single row when it is a json array. For example,

{code}
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types._
val schema = StructType(StructField("a", IntegerType) :: Nil)
Seq(("""[{"a": 1}, {"a": 2}]""")).toDF("struct").select(from_json(col("struct"), schema)).show()
+--------------------+
|jsontostruct(struct)|
+--------------------+
|                 [1]|
+--------------------+
{code}

Maybe we should not support this in that function or it should work like a generator expression.


  was:
Currently, {{from_json}} reads a single row when it is a json array. For example,

```scala
import org.apache.spark.sql.functions._
import org.apache.spark.sql.types._
val schema = StructType(StructField("a", IntegerType) :: Nil)
Seq(("""[{"a": 1}, {"a": 2}]""")).toDF("struct").select(from_json(col("struct"), schema)).show()
+--------------------+
|jsontostruct(struct)|
+--------------------+
|                 [1]|
+--------------------+
```

Maybe we should not support this in that function or it should work like a generator expression.



> from_json produces only a single row when input is a json array
> ---------------------------------------------------------------
>
>                 Key: SPARK-19595
>                 URL: https://issues.apache.org/jira/browse/SPARK-19595
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.2.0
>            Reporter: Hyukjin Kwon
>            Priority: Minor
>
> Currently, {{from_json}} reads a single row when it is a json array. For example,
> {code}
> import org.apache.spark.sql.functions._
> import org.apache.spark.sql.types._
> val schema = StructType(StructField("a", IntegerType) :: Nil)
> Seq(("""[{"a": 1}, {"a": 2}]""")).toDF("struct").select(from_json(col("struct"), schema)).show()
> +--------------------+
> |jsontostruct(struct)|
> +--------------------+
> |                 [1]|
> +--------------------+
> {code}
> Maybe we should not support this in that function or it should work like a generator expression.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org