Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;项目不采用参数“;在过滤RDD-scala时,ApacheSpark_Scala_Apache Spark_Filter_Parameters_Rdd - Fatal编程技术网

&引用;项目不采用参数“;在过滤RDD-scala时,ApacheSpark

&引用;项目不采用参数“;在过滤RDD-scala时,ApacheSpark,scala,apache-spark,filter,parameters,rdd,Scala,Apache Spark,Filter,Parameters,Rdd,我正在使用ApacheSpark中的csv文件。我创建了RDD,我想为每个月获得单独的RDD,所以我按日期过滤,表示为201601、201602等 case class Item(date: String, id: String, classification: String, description: String, algoIndex: String, stratumIndex: String, itemIndex: String, allGmIndex: String, gmRaIndex

我正在使用ApacheSpark中的csv文件。我创建了RDD,我想为每个月获得单独的RDD,所以我按日期过滤,表示为201601、201602等

case class Item(date: String, id: String, classification: String, description: String, algoIndex: String, stratumIndex: String, itemIndex: String, allGmIndex: String, gmRaIndex: String, coicopWeight: String, itemWeight: String, cpihCoicopWeight: String)

val quarter1 = sc.textFile ("examples/Q1.csv")

val q1 = quarter1 map {i => {
        val x = i.split(",")
        Item(x(0), x(1), x(2), x(3), x(4), x(5), x(6), x(7), x(8), x(9), x(10), x(11))
        }
    }

val Jan = q1.filter {x=> x(0) == "201601"}
val Feb = q1.filter {x=> x(0) == "201602"}
val Mar = q1.filter {x=> x(0) == "201603"}
最后三行导致与以下位相关的错误“Item not take parameters”:

{x=> x(0) == ..}
我怎样才能解决这个问题?我在课堂上做错了什么?
提前非常感谢!:)

使用case类,因此不能使用
apply
语法。使用您定义的名称:

q1.filter { x => x.date == "201601" }


函数文本中的
x
s属于
项的类型。
没有
apply(i:Int)
方法。 相反,
有一组命名的成员变量

请尝试以下方法:

val Jan = q1.filter {x => x.date == "201601"}
它可以缩写为:

val Jan = q1.filter (_.date == "201601")

非常感谢你!:)虽然没有
apply
,但在case类中也可以这样做:
q1.filter{x=>x.productElement(0)=“201601”}
非常感谢!)
val Jan = q1.filter (_.date == "201601")