它周圍是相當繁瑣的方式,但它確實工作中,嘗試此示例代碼,讓你開始,你可以看到有超過22列被訪問:
object SimpleApp {
class Record(val x1: String, val x2: String, val x3: String, ... val x24:String) extends Product with Serializable {
def canEqual(that: Any) = that.isInstanceOf[Record]
def productArity = 24
def productElement(n: Int) = n match {
case 0 => x1
case 1 => x2
case 2 => x3
...
case 23 => x24
}
}
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Product Test")
val sc = new SparkContext(conf)
val sqlContext = new SQLContext(sc);
val record = new Record("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x")
import sqlContext._
sc.parallelize(record :: Nil).registerAsTable("records")
sql("SELECT x1 FROM records").collect()
}
}
switch to scala 2.11? – Odomontois
我想這可能是很簡單,但它不是 – Silverrose
@Odomontois AFAIK斯卡拉2.11不支持基數> 22,即元組沒有Tuple23的情況。 – moem