cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to perform Inner join using withcolumn

pramalin
New Contributor
 
3 REPLIES 3

daniel_sahal
Esteemed Contributor

@prudhvi ramalingamโ€‹ 

Here is example: https://stackoverflow.com/a/61029482

Nhan_Nguyen
Valued Contributor

@prudhvi ramalingamโ€‹ you could refer to this link: https://sparkbyexamples.com/spark/spark-sql-join-on-multiple-columns/

shan_chandra
Esteemed Contributor
Esteemed Contributor

@prudhvi ramalingamโ€‹ - Please refer to the below example code.

import org.apache.spark.sql.functions.expr
val person = Seq(
    (0, "Bill Chambers", 0, Seq(100)),
    (1, "Matei Zaharia", 1, Seq(500, 250, 100)),
    (2, "Michael Armbrust", 1, Seq(250, 100)))
  .toDF("id", "name", "graduate_program", "spark_status")
 
val graduateProgram = Seq(
    (0, "Masters", "School of Information", "UC Berkeley"),
    (2, "Masters", "EECS", "UC Berkeley"),
    (1, "Ph.D.", "EECS", "UC Berkeley"))
  .toDF("id", "degree", "department", "school")
 
val sparkStatus = Seq(
    (500, "Vice President"),
    (250, "PMC Member"),
    (100, "Contributor"))
  .toDF("id", "status")
 
person
  .withColumnRenamed("id", "personId")
  .join(sparkStatus, expr("array_contains(spark_status, id)"))
  .show()

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group