You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by tridib <tr...@live.com> on 2014/11/04 21:19:03 UTC

spark sql create nested schema

I am trying to create a schema which will look like:

root
 |-- ParentInfo: struct (nullable = true)
 |    |-- ID: string (nullable = true)
 |    |-- State: string (nullable = true)
 |    |-- Zip: string (nullable = true)
 |-- ChildInfo: struct (nullable = true)
 |    |-- ID: string (nullable = true)
 |    |-- State: string (nullable = true)
 |    |-- Hobby: string (nullable = true)
 |    |-- Zip: string (nullable = true)

How do I create a StructField of StructType? I think that's what the "root"
is.

Thanks & Regards 
Tridib



--
View this message in context: http://apache-spark-user-list.1001560.n3.nabble.com/spark-sql-create-nested-schema-tp18090.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 create nested schema

Posted by Yin Huai <hu...@gmail.com>.
Hello Tridib,

For you case, you can use StructType(StructField("ParentInfo", parentInfo,
true) :: StructField("ChildInfo", childInfo, true) :: Nil) to create the
StructType representing the schema (parentInfo and childInfo are two
existing StructTypes). You can take a look at our docs (
http://spark.apache.org/docs/1.1.0/sql-programming-guide.html#programmatically-specifying-the-schema
 and
http://spark.apache.org/docs/1.1.0/api/scala/index.html#org.apache.spark.sql.package
).

Thanks,

Yin

On Tue, Nov 4, 2014 at 3:19 PM, tridib <tr...@live.com> wrote:

> I am trying to create a schema which will look like:
>
> root
>  |-- ParentInfo: struct (nullable = true)
>  |    |-- ID: string (nullable = true)
>  |    |-- State: string (nullable = true)
>  |    |-- Zip: string (nullable = true)
>  |-- ChildInfo: struct (nullable = true)
>  |    |-- ID: string (nullable = true)
>  |    |-- State: string (nullable = true)
>  |    |-- Hobby: string (nullable = true)
>  |    |-- Zip: string (nullable = true)
>
> How do I create a StructField of StructType? I think that's what the "root"
> is.
>
> Thanks & Regards
> Tridib
>
>
>
> --
> View this message in context:
> http://apache-spark-user-list.1001560.n3.nabble.com/spark-sql-create-nested-schema-tp18090.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
>
>