在 Spark SQL 中加入两个 DataFrame 并仅选择一列 [英] Joining two DataFrames in Spark SQL and selecting columns of only one

查看:24
本文介绍了在 Spark SQL 中加入两个 DataFrame 并仅选择一列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Spark SQL 中有两个 DataFrame(D1 和 D2).

I have two DataFrames in Spark SQL (D1 and D2).

我正在尝试内连接它们 D1.join(D2, "some column")并取回仅 D1 的数据,而不是完整的数据集.

I am trying to inner join both of them D1.join(D2, "some column") and get back data of only D1, not the complete data set.

D1 和 D2 都具有相同的列.

Both D1 and D2 are having the same columns.

有人可以帮我解决这个问题吗?

Could some one please help me on this?

我使用的是 Spark 1.6.

I am using Spark 1.6.

推荐答案

假设您想加入id"列.然后你可以写:

Let say you want to join on "id" column. Then you could write :

val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext.implicits._    
d1.as("d1").join(d2.as("d2"), $"d1.id" === $"d2.id").select($"d1.*")

这篇关于在 Spark SQL 中加入两个 DataFrame 并仅选择一列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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