I currently have JSON file from which I'm able to dump it's data into a temporary view via. following Python (PySpark) logic:
departMentData = spark \
.read \
.option("multiLine", True) \
.option("mode", "PERMISSIVE") \
.json("C:\\Test\data.json") \
.createOrReplaceTempView("vw_TestView")
This temporary view has the data of departments and list of employees within that department in an array. One employee can be a part of multiple departments.
Following is this view's datatypes:
- DeptID: string
- DeptName: string
- EmployeeIDs: array<string.>
and the table data for vw_TestView is as follows
| DeptID | DeptName | EmployeeIDs |
|---|---|---|
| D01 | dev | ["U1234", "U6789"] |
| D02 | qa | ["U1234", "U2345"] |
and another table Employees has details of all these employees as follows:
| EmpID | EmpName |
|---|---|
| U1234 | jon |
| U6789 | smith |
| U2345 | natasha |
I need the final output for a new table to be as follows:
| DeptID | DeptName | EmployeeIDs | EmployeeNames |
|---|---|---|---|
| D01 | dev | ["U1234", "U6789"] | ["jon", "smith"] |
| D02 | qa | ["U1234", "U2345"] | ["jon", "natasha"] |
How can such joins be performed in either Databricks SQL or via PySPark?