2017-10-04 3 views

答えて

2

スパークSQLのこの隠された機能は、いわゆるスキーマDSL(つまりを使用してスキーマを定義することがあります多くの丸括弧などはありません)。

scala> spark.version 
res0: String = 2.2.0 

import org.apache.spark.sql.types._ 
val name = new StructType().add($"name".string) 
scala> println(name.simpleString) 
struct<name:string> 

val address = new StructType().add($"address".string) 
scala> println(address.simpleString) 
struct<address:string> 

val schema = new StructType().add("abc", name).add("pqr", address) 
scala> println(schema.simpleString) 
struct<abc:struct<name:string>,pqr:struct<address:string>> 

scala> schema.simpleString == "struct<abc:struct<name:string>,pqr:struct<address:string>>" 
res4: Boolean = true 

scala> schema.printTreeString 
root 
|-- abc: struct (nullable = true) 
| |-- name: string (nullable = true) 
|-- pqr: struct (nullable = true) 
| |-- address: string (nullable = true) 
+0

:) thanks –

2

あなたはどうなるのでstructFieldは、タイプと名前の組み合わせです:

StructType(Seq(StructField("structName", StructType(Seq(StructField("name", StringType), StructField("address", StringType)))) 
関連する問題