You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by smagadi <su...@fico.com> on 2015/08/21 09:59:43 UTC
SPARK sql :Need JSON back isntead of roq
val teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND
age <= 19")
I need teenagers to be a JSON object rather a simple row .How can we get
that done ?
--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/SPARK-sql-Need-JSON-back-isntead-of-roq-tp24381.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
For additional commands, e-mail: user-help@spark.apache.org
Re:SPARK sql :Need JSON back isntead of roq
Posted by Todd <bi...@163.com>.
please try DataFrame.toJSON, it will give you an RDD of JSON string.
At 2015-08-21 15:59:43, "smagadi" <su...@fico.com> wrote:
>val teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13 AND
>age <= 19")
>
>I need teenagers to be a JSON object rather a simple row .How can we get
>that done ?
>
>
>
>--
>View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/SPARK-sql-Need-JSON-back-isntead-of-roq-tp24381.html
>Sent from the Apache Spark User List mailing list archive at Nabble.com.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
>For additional commands, e-mail: user-help@spark.apache.org
>
Re: SPARK sql :Need JSON back isntead of roq
Posted by Roberto Congiu <ro...@gmail.com>.
2015-08-21 3:17 GMT-07:00 smagadi <su...@fico.com>:
> teenagers .toJSON gives the json but it does not preserve the parent ids
>
> meaning if the input was {"name":"Yin",
> "address":{"city":"Columbus","state":"Ohio"},"age":20}
>
> val x= sqlContext.sql("SELECT name, address.city, address.state ,age FROM
> people where age>19 and age <=30 ").toJSON
>
> x.collect().foreach(println)
>
> This returns back , missing address.
> {"name":"Yin","city":"Columbus","state":"Ohio","age":20}
> Is this a bug ?
>
>
You're not including it in the query, so of course it's not there.
Try
sqlContext.sql("Select * from ppl").toJSON.collect().foreach(println)
instead.
I get
{"address":{"city":"Columbus","state":"Ohio"},"name":"Yin"}
R.
Re: SPARK sql :Need JSON back isntead of roq
Posted by smagadi <su...@fico.com>.
teenagers .toJSON gives the json but it does not preserve the parent ids
meaning if the input was {"name":"Yin",
"address":{"city":"Columbus","state":"Ohio"},"age":20}
val x= sqlContext.sql("SELECT name, address.city, address.state ,age FROM
people where age>19 and age <=30 ").toJSON
x.collect().foreach(println)
This returns back , missing address.
{"name":"Yin","city":"Columbus","state":"Ohio","age":20}
Is this a bug ?
--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/SPARK-sql-Need-JSON-back-isntead-of-roq-tp24381p24386.html
Sent from the Apache Spark User List mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@spark.apache.org
For additional commands, e-mail: user-help@spark.apache.org