首先,感谢您阅读我的问题。加入数据框火花java
我的问题是如下:在Spark与Java,我加载两个数据帧的两个CSV文件的数据。
这些数据帧将具有以下信息。
数据帧机场
Id | Name | City
-----------------------
1 | Barajas | Madrid
数据帧airport_city_state
City | state
----------------
Madrid | España
我想,这样它看起来像这样加入这两个dataframes:
数据帧结果
Id | Name | City | state
--------------------------
1 | Barajas | Madrid | España
其中dfairport.city = dfaiport_city_state.city
但我无法用语法澄清所以我可以正确地进行连接。我是如何创建的变量的一些代码:
// Load the csv, you have to specify that you have header and what delimiter you have
Dataset <Row> dfairport = Load.Csv (sqlContext, data_airport);
Dataset <Row> dfairport_city_state = Load.Csv (sqlContext, data_airport_city_state);
// Change the name of the columns in the csv dataframe to match the columns in the database
// Once they match the name we can insert them
Dfairport
.withColumnRenamed ("leg_key", "id")
.withColumnRenamed ("leg_name", "name")
.withColumnRenamed ("leg_city", "city")
dfairport_city_state
.withColumnRenamed("city", "ciudad")
.withColumnRenamed("state", "estado");