为什么在显示操作符后无法加入? [英] Why is join not possible after show operator?

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

问题描述

以下代码工作正常,直到我在 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 中称之为副作用.它打印到标准输出并返回 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天全站免登陆