Вы находитесь на странице: 1из 2

val n: Int = 2

val g: Int = 2
val gSize: Int = n/g
val matrix1 = sc.textFile("matrix3")
val matrix2 = sc.textFile("matrix4")
def linesToRowColumn(l: String): ((Int, Int), Double) = {
val ll = l.split(" ")
return((ll(0).toInt - 1, ll(1).toInt - 1), ll(2).toDouble)
}
def AssignGroups(l:((Int, Int),Double), left:Boolean): List[((Int, Int), ((Int,
Int), Double))] = {
val k = l._1
val v = l._2
val i = if(left)
k._1/gSize
else
k._2/gSize
def go(group: Int, acc: List[((Int, Int), ((Int, Int), Double))]): List[((In
t, Int), ((Int, Int), Double))] = {
if(group >= g)
return acc
else
return go(group+1, acc ++ List((
if (left)
(i, group)
else
(group, i)
, (k, v))))
}
return go(0, List())
}
val matrix1Map = matrix1.map(linesToRowColumn).flatMap(x => AssignGroups(x, true
))
val matrix2Map = matrix2.map(linesToRowColumn).flatMap(x => AssignGroups(x, fals
e))
println("Map output of Matrix5")
matrix1Map.collect().foreach(println)
println("Map output of Matrix6")
matrix2Map.collect().foreach(println)
println("Map output of Matrix3")
val matrix3 = matrix2Map.map(x=>((x._1, x._2._1._1), (x._2._1._2, x._2._2)))
matrix3.collect().foreach(println)
println("Map output of Matrix4")
val matrix4 = matrix1Map.map(x=>((x._1, x._2._1._2), (x._2._1._1, x._2._2)))
matrix4.collect().foreach(println)

val matrix5 = matrix4.join(matrix3)


matrix5.collect().foreach(println)

val matrix6 = matrix5.groupBy(x => (x._1._1, x._2._1._1, x._2._2._1))


matrix6.collect().foreach(println)
def AssignGroups2(row: ((Int, Int), Int, Int), Seq((Int, Int), Int)): List[(Int,
Int), Double)] = {
}
matrix7.map(x=>AssignGroups2).collect().foreach(println)
// AssignGroups2(matrix7).group()
//matrix7.map(x=>)

Вам также может понравиться