【问题标题】:How to map a RDD of type org.apache.spark.rdd.RDD[Array[String]]?如何映射 org.apache.spark.rdd.RDD[Array[String]] 类型的 RDD?
【发布时间】:2015-09-15 22:57:36
【问题描述】:

我是 Spark 和 Scala 的新手。 我有一个 org.apache.spark.rdd.RDD[Array[String]] 类型的 RDD。

这是来自myRdd.take(3) 的列表。

Array(Array(1, 2524474, CBSGPRS, 1, 2015-09-09 10:42:03, 0, 47880, 302001131103734, NAT, "", 502161081073570, "", BLANK, UNK, "", "", "", MV_PVC, BLANK, 1, "", 0, 475078439, 41131;0;0, "", 102651;0;0, 3|3), Array(2, 2524516, CBSGPRS, 1, 2015-09-09 23:42:14, 0, 1260, 302001131104272, NAT, "", 502161081074085, "", BLANK, UNK, "", "", "", MV_PVC, BLANK, 1, "", 0, 2044745984, 3652;0;0, "", 8636;0;0, 3|3), Array(3, 2524545, CBSGPRS, 1, 2015-09-09 14:56:55, 0, 32886, 302001131101629, NAT, "", 502161081071599, "", BLANK, UNK, "", "", "", MV_PVC, BLANK, 1, "", 0, 1956194307, 14164657;0;0, "", 18231194;0;0, 3|3))

我正在尝试将其映射如下..

var gprsMap = frows.collect().map{ tuple =>
// bind variables to the tuple
var (recKey, origRecKey, recTypeId, durSpanId, timestamp, prevConvDur, convDur,
    msisdn, callType, aPtyCellId, aPtyImsi, aPtyMsrn, bPtyNbr, bPtyNbrTypeId,
    bPtyCellId, bPtyImsi, bPtyMsrn, inTrgId, outTrgId, callStatusId, suppSvcId, provChgAmt,
    genFld1, genFld2, genFld3, genFld4, genFld5) = tuple

var dtm = timestamp.split(" ");
var idx = timestamp indexOf ' '
var dt = timestamp slice(0, idx)
var tm = timestamp slice(idx + 1, timestamp.length)

// return the results tuple
((dtm(0), msisdn, callType, recTypeId, provChgAmt), (convDur))
}

我不断收到错误:

错误:对象 Tuple27 不是包 scala 的成员。

我不确定错误是什么。有人可以帮忙吗?

【问题讨论】:

    标签: scala mapreduce apache-spark


    【解决方案1】:

    问题是 Scala 只支持最多 22 个字段的元组。此外,您的 frows: RDD[Array[String]] 包含 Array[String] 作为元素。因此,map 函数中的tuple 变量也是Array[String] 类型。因此,不能将变量tuple 取消应用到元组中。

    但是您可以做的是直接通过索引访问数组的元素。

    val recKey = tuple(0)
    val timestamp = tuple(4)
    ...
    

    【讨论】:

      猜你喜欢
      • 2020-08-17
      • 1970-01-01
      • 2017-01-29
      • 2015-12-11
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-26
      相关资源
      最近更新 更多