You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by amghost <zh...@gmail.com> on 2015/03/22 08:40:14 UTC

Should Spark SQL support retrieve column value from Row by column name?

I would like to retrieve column value from Spark SQL query result. But
currently it seems that Spark SQL only support retrieving by index


val results = sqlContext.sql("SELECT name FROM people")
results.map(t => "Name: " + *t(0)*).collect().foreach(println)

I think it will be much more convenient if I could do something like this:

results.map(t => "Name: " + *t("name")*).collect().foreach(println)

How do you like?



--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/Should-Spark-SQL-support-retrieve-column-value-from-Row-by-column-name-tp22174.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: Should Spark SQL support retrieve column value from Row by column name?

Posted by Yanbo Liang <yb...@gmail.com>.
If you use the latest version Spark 1.3, you can use the DataFrame API like

val results = sqlContext.sql("SELECT name FROM people")
results.select("name").show()

2015-03-22 15:40 GMT+08:00 amghost <zh...@gmail.com>:

> I would like to retrieve column value from Spark SQL query result. But
> currently it seems that Spark SQL only support retrieving by index
>
>
> val results = sqlContext.sql("SELECT name FROM people")
> results.map(t => "Name: " + *t(0)*).collect().foreach(println)
>
> I think it will be much more convenient if I could do something like this:
>
> results.map(t => "Name: " + *t("name")*).collect().foreach(println)
>
> How do you like?
>
>
>
> --
> View this message in context:
> http://apache-spark-user-list.1001560.n3.nabble.com/Should-Spark-SQL-support-retrieve-column-value-from-Row-by-column-name-tp22174.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: Should Spark SQL support retrieve column value from Row by column name?

Posted by Michael Armbrust <mi...@databricks.com>.
Please open a JIRA, we added the info to Row that will allow this to
happen, but we need to provide the methods you are asking for.  I'll add
that this does work today in python (i.e. row.columnName).

On Sun, Mar 22, 2015 at 12:40 AM, amghost <zh...@gmail.com> wrote:

> I would like to retrieve column value from Spark SQL query result. But
> currently it seems that Spark SQL only support retrieving by index
>
>
> val results = sqlContext.sql("SELECT name FROM people")
> results.map(t => "Name: " + *t(0)*).collect().foreach(println)
>
> I think it will be much more convenient if I could do something like this:
>
> results.map(t => "Name: " + *t("name")*).collect().foreach(println)
>
> How do you like?
>
>
>
> --
> View this message in context:
> http://apache-spark-user-list.1001560.n3.nabble.com/Should-Spark-SQL-support-retrieve-column-value-from-Row-by-column-name-tp22174.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
>
>