2016-08-24 68 views
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 
                        ^

任何人都知道我在做什么错?

非常感谢!

回答

0
// this produces a collection of tuples of type (Long, String, String, String, String, String) 
val products = transactionsRDD.map(Transactions => (Transactions.ID,Transactions.Chain,Transactions.Dept,Transactions.Category,Transactions.Company,Transactions.Brand)).distinct 

// since products is a collection of sextuples, the pattern match should match the tuple length 
val productMap = products.map { case (ID, chain, dept, cat, comp, brand) => (ID -> chain) }.collect.toList.toMap 
相关问题