我在hive / impala中有两个表.我想将表中的数据作为rdds获取到spark并执行连接操作.
我不想直接在我的hive上下文中传递连接查询.这只是一个例子.
我有更多标准HiveQL无法实现的用例.
如何获取所有行,访问列并执行转换.
假设我有两个rdds:
val table1 = hiveContext.hql("select * from tem1") val table2 = hiveContext.hql("select * from tem2")
我想在名为“account_id”的列上对rdds执行连接
理想情况下,我想使用火花壳使用rdds这样做.
select * from tem1 join tem2 on tem1.account_id=tem2.account_id;
解决方法
我不确定我是否理解这个问题,但作为替代方案,您可以使用API来连接DataFrame,因此您可以以编程方式确定许多内容(例如,可以将join函数作为参数传递给应用自定义转换的方法) .
对于您的示例,它将是这样的:
val table1 = hiveContext.sql("select * from tem1") val table2 = hiveContext.sql("select * from tem2") val common_attributes = Seq("account_id") val joined = table1.join(table2,common_attributes)
DataFrame API中有许多常见的转换:
http://spark.apache.org/docs/latest/api/scala/index.html#org.apache.spark.sql.DataFrame
干杯