Joining Spark dataframes on the key

后端 未结 8 2170
情书的邮戳
情书的邮戳 2020-11-28 03:02

I have constructed two dataframes. How can we join multiple Spark dataframes ?

For Example :

PersonDf, ProfileDf with a common col

8条回答
  •  半阙折子戏
    2020-11-28 03:48

    From https://spark.apache.org/docs/1.5.1/api/java/org/apache/spark/sql/DataFrame.html, use join:

    Inner equi-join with another DataFrame using the given column.

    PersonDf.join(ProfileDf,$"personId")
    

    OR

    PersonDf.join(ProfileDf,PersonDf("personId") === ProfileDf("personId"))
    

    Update:

    You can also save the DFs as temp table using df.registerTempTable("tableName") and you can write sql queries using sqlContext.

提交回复
热议问题