val a =
spark
.read
.option("header", "true")
.option("delimiter", "|")
.csv("/tmp/1.csv")
.drop("unwanted_column").
.cache()
val b =
spark
.read
.option("header", "true")
.option("delimiter", "|")
.csv("/tmp/2.csv")
.drop("unwanted_column")
.cache()
val c = a.join(b, Seq("id", "year"), "left_outer").cache()
c.count() // this is returning 600,000
现在我试图通过在两个数据集a和b中随机选取一个具有相同id和年份的行来找出差异。
val a1 = a.filter(i => i.get(0).equals("1") && i.get(1).equals("2016")).first()
val b1 = b.filter(i => i.get(0).equals("1") && i.get(1).equals("2016")).first()
然后我试着比较a1和b1中的每一列。
(0 to (a1.length -1)).foreach { i =>
if (a1.getString(i) != null && !a1.getString(i).equals(b1.getString(i))) {
System.out.println(i + " = " + a1.getString(i) + " = " + b1.getString(i))
}
}
我不明白为什么c.count()会像那样返回60万。