为什么在节目主持人之后无法加入? [英] Why is join not possible after show operator?

查看:183
本文介绍了为什么在节目主持人之后无法加入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我在agg之后添加show之前,以下代码可以正常工作.为什么show不可能?

The following code works fine until I add show after agg. Why is show not possible?

 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")
                     ^

为什么这种方式?

推荐答案

.show()是一个函数,在Scala中称为副作用.它打印到stdout并返回Unit(),就像println

.show() is a function with, what we call in Scala, a side-effect. It prints to stdout and returns Unit(), just like println

示例:

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

在scala中,您可以假定所有内容都是一个函数,并且将返回某些内容.在您的情况下,将返回Unit(),这就是存储在tempTableB中的内容.

In scala, you can assume that everything is a function and will return something. In your case, Unit() is being returned and that's what's getting stored in tempTableB.

这篇关于为什么在节目主持人之后无法加入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆