Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.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
Scala 为什么在show操作符之后不能连接?_Scala_Apache Spark_Join_Apache Spark Sql - Fatal编程技术网

Scala 为什么在show操作符之后不能连接?

Scala 为什么在show操作符之后不能连接?,scala,apache-spark,join,apache-spark-sql,Scala,Apache Spark,Join,Apache Spark Sql,在我在agg之后添加show之前,以下代码工作正常。为什么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: ov

在我在
agg
之后添加
show
之前,以下代码工作正常。为什么
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")
                     ^
错误:重载方法值与可选项联接:
(右:org.apache.spark.sql.Dataset[\ux],joinExprs:org.apache.spark.sql.Column,joinType:String)org.apache.spark.sql.DataFrame
(右:org.apache.spark.sql.Dataset[173],使用columns:Seq[String],joinType:String)org.apache.spark.sql.DataFrame
无法应用于(单位,org.apache.spark.sql.Column,字符串)
表A.join(表B,$“idA”==$“idB”,“内部”)
^
为什么会这样?

.show()
是一个函数,我们在Scala中称之为副作用。它打印到标准输出并返回
Unit()
,就像
println

例如:

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

在scala中,您可以假设所有内容都是函数,并将返回某些内容。在您的情况下,
Unit()
将被返回,这就是存储在
atterableb

中的内容,因为@philantrover已经给出了详细的解释。因此,我将不作解释

如果您想查看诱惑B中的内容,那么您可以在如下所示分配它之后执行此操作

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

 tempTableB.show

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