あなたはexplode
を意味しません。 Explodeは新しい行を作成します。 StructType
列を単一のselect
ステートメントで複数の列に分割できます。
このよう
:
case class Act(a: Int, b: Seq[String])
case class Boo(a1: Int, b1: String)
case class C(a: Act, b: Boo)
val df = Seq(C(Act(1, Seq("test")), Boo(2, "this is"))).toDF
df.show
+--------------------+-----------+
| a| b|
+--------------------+-----------+
|[1,WrappedArray(t...|[2,this is]|
+--------------------+-----------+
df.printSchema
root
|-- a: struct (nullable = true)
| |-- a: integer (nullable = false)
| |-- b: array (nullable = true)
| | |-- element: string (containsNull = true)
|-- b: struct (nullable = true)
| |-- a1: integer (nullable = false)
| |-- b1: string (nullable = true)
df.select($"a", $"a.a", $"a.b", $"b", $"b.a1", $"b.b1").show
+--------------------+---+------+-----------+---+-------+
| a| a| b| b| a1| b1|
+--------------------+---+------+-----------+---+-------+
|[1,WrappedArray(t...| 1|[test]|[2,this is]| 2|this is|
+--------------------+---+------+-----------+---+-------+
ないあなたが何を意味するかを確認しますが、爆発は何に取り組むべきです。ドキュメントの例では、文字列をケースクラスの配列に分割して展開します。 –
caseクラスAct(a:int、b:string、c:seq [string])、ケースクラスBoo(a1:int、b1:String)、ケースクラスC(a:Act、b:Boo)ですから、C要素aを1つの複合列法の代わりに3つの列(a:int、b:文字列、c:seq [string])に分解したい場合は、どうすればよいでしょうか? – Anand
あなたは爆発を意味しません。 Explodeは新しい行を作成します。 select文を使用すると、StructType列を複数の組み合わせに分割できます。 'select($" a.a "、$" a.b "、...)' –