0
我正在使用Spark Mllib在零售行業做鏈接分析項目。我的模式是:(Spark - Scala)錯誤:構造函數無法實例化爲預期類型;
ID - 長鏈 - 詮釋部門 - INT類別 - 詮釋公司 - 龍品牌 - 長日期 - 日期ProductSize - 詮釋ProductMeasure - Chararray PurchaseQuantity - 詮釋PurchaseAmount - 雙
和代碼,我「米使用是:
spark-shell
import org.apache.spark._
import org.apache.spark.rdd.RDD
import org.apache.spark.util.IntParam
import org.apache.spark.graphx._
import org.apache.spark.graphx.util.GraphGenerators
case class Transactions(ID:Long,Chain:String,Dept:String,Category:String,Company:String,Brand:String,Date:String,ProductSize:String,ProductMeasure:String,PurchaseQuantity:String,PurchaseAmount:String)
def parseTransactions(str:String): Transactions = {
val line = str.split(",")
Transactions(line(0).toLong,line(1),line(2),line(3),line(4),line(5),line(6),line(7),line(8),line(9),line(10))
}
val textRDD = sc.textFile("/user/cloudera/transactions.csv")
val transactionsRDD = textRDD.map(parseTransactions).cache()
val products = transactionsRDD.map(Transactions => (Transactions.ID,Transactions.Chain,Transactions.Dept,Transactions.Category,Transactions.Company,Transactions.Brand)).distinct
products.take(1)
val productMap = products.map { case ((ID), name) => (ID -> name) }.collect.toList.toMap
,我發現了folloiwng錯誤:
<console>:46: error: constructor cannot be instantiated to expected type;
found : (T1, T2)
required: (Long, String, String, String, String, String)
val productMap = products.map { case ((ID), name) => (ID -> name) }.collect.toList.toMap
^
<console>:46: error: not found: value ID
val productMap = products.map { case ((ID), name) => (ID -> name) }.collect.toList.toMap
^
<console>:46: error: value toList is not a member of Array[Nothing]
val productMap = products.map { case ((ID), name) => (ID -> name) }.collect.toList.toMap
^
任何人都知道我在做什麼錯?
非常感謝!