为什么参加节目运营商后不可能?为什么参加节目运营商后不可能?(Why is join not pos

2019-05-12 13:30发布

直到我添加以下代码工作正常showagg 。 为什么show不可能?

 val tempTableB = tableB.groupBy("idB")
  .agg(first("numB").as("numB")) //when I add a .show here, it doesn't work

 tableA.join(tempTableB, $"idA" === $"idB", "inner")
 .drop("idA", "numA").show

错误说:

error: overloaded method value join with alternatives:
  (right: org.apache.spark.sql.Dataset[_],joinExprs: org.apache.spark.sql.Column,joinType: String)org.apache.spark.sql.DataFrame <and>
  (right: org.apache.spark.sql.Dataset[_],usingColumns: Seq[String],joinType: String)org.apache.spark.sql.DataFrame
 cannot be applied to (Unit, org.apache.spark.sql.Column, String)
              tableA.join(tempTableB, $"idA" === $"idB", "inner")
                     ^

这是为什么表现如此?

Answer 1:

.show()是一个功能,我们在斯卡拉,副作用调用。 它打印到标准输出,并返回Unit()就像println

例:

val a  = Array(1,2,3).foreach(println)
a: Unit = ()

在Scala中,你可以假设这一切都是一个函数,将返回的东西。 在你的情况下, Unit()被返回,这就是是越来越存储在tempTableB



Answer 2:

正如@philantrovert已经回答了很多有详细的解释。 所以,我无法解释。

如果你想看到什么在tempTableB那么你可以这样做,它已被如下分配后,你可以做。

 val tempTableB = tableB.groupBy("idB")
  .agg(first("numB").as("numB")) 

 tempTableB.show

 tableA.join(tempTableB, $"idA" === $"idB", "inner")
 .drop("idA", "numA").show

它应该工作,然后



文章来源: Why is join not possible after show operator?