explicit Row and schema definition APIsを使用した例です。
(mildy)厄介な部分がスキーマオブジェクトを設定しています。 StructFieldおよびStructTypeを参照してください。
これはScala 2.10.xでうまく動作します。
scala> import org.apache.spark.sql.{DataFrame,Row}
import org.apache.spark.sql.{DataFrame, Row}
scala> import org.apache.spark.sql.types._
import org.apache.spark.sql.types._
scala> val alphabet = ('a' to 'z').map(_ + "") // for column labels
alphabet: scala.collection.immutable.IndexedSeq[String] = Vector(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z)
scala> val row1 = Row(1 to 26 : _*)
row1: org.apache.spark.sql.Row = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]
scala> val row2 = Row(26 to 1 by -1 : _*)
row2: org.apache.spark.sql.Row = [26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]
scala> val schema = StructType(alphabet.map(label => StructField(label, IntegerType, false)))
schema: org.apache.spark.sql.types.StructType = StructType(StructField(a,IntegerType,false), StructField(b,IntegerType,false), StructField(c,IntegerType,false), StructField(d,IntegerType,false), StructField(e,IntegerType,false), StructField(f,IntegerType,false), StructField(g,IntegerType,false), StructField(h,IntegerType,false), StructField(i,IntegerType,false), StructField(j,IntegerType,false), StructField(k,IntegerType,false), StructField(l,IntegerType,false), StructField(m,IntegerType,false), StructField(n,IntegerType,false), StructField(o,IntegerType,false), StructField(p,IntegerType,false), StructField(q,IntegerType,false), StructField(r,IntegerType,false), StructField(s,IntegerType,false), StructField(t,IntegerType,false), StructField(u,IntegerType,false), StructField(v,IntegerTyp...
scala> val rdd = hiveContext.sparkContext.parallelize(Seq(row1, row2))
rdd: org.apache.spark.rdd.RDD[org.apache.spark.sql.Row] = ParallelCollectionRDD[5] at parallelize at <console>:23
scala> val df = hiveContext.createDataFrame(rdd, schema)
df: org.apache.spark.sql.DataFrame = [a: int, b: int, c: int, d: int, e: int, f: int, g: int, h: int, i: int, j: int, k: int, l: int, m: int, n: int, o: int, p: int, q: int, r: int, s: int, t: int, u: int, v: int, w: int, x: int, y: int, z: int]
scala> df.show()
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| a| b| c| d| e| f| g| h| i| j| k| l| m| n| o| p| q| r| s| t| u| v| w| x| y| z|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
| 1| 2| 3| 4| 5| 6| 7| 8| 9| 10| 11| 12| 13| 14| 15| 16| 17| 18| 19| 20| 21| 22| 23| 24| 25| 26|
| 26| 25| 24| 23| 22| 21| 20| 19| 18| 17| 16| 15| 14| 13| 12| 11| 10| 9| 8| 7| 6| 5| 4| 3| 2| 1|
+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
答えをありがとう。しかし、あなたのアプローチの問題は、Scala 2.11では22フィールド以上のケースクラスを定義できますが、Apache Sparkが使用するバージョンであるバージョン2.10では定義できないということです。したがって、スパークシェルでは、そのケースクラスを定義しようとしている: "エラー:実装の制限:ケースクラスは22以上のパラメータを持つことはできません。 –
22個以上の要素を持つケースクラスはscala 2.10ではサポートされていません。OPがそのバージョンのscalaを使用していると思います – eliasah
SparkライブラリはScala 2.11で利用可能でサポートされていますので、 2.10そうではありません! –