forked from veeraravi/Spark-notes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspark-join-notes_1.txt
552 lines (477 loc) · 25.1 KB
/
spark-join-notes_1.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
In this article I will try to explain all the join types spark supports. and is 10 mins read.
Case 1: First example inner join
The INNER JOIN selects all rows from both participating tables as long as there is a match between the columns
Case 2: All Spark supported joins in a loop example inner join
0) INNER JOIN : Inner Join on column Id will return columns from both the tables and only the matching records:
1) OUTER | FULL | FULL_OUTER : Full Outer Join on column Id will return columns from both the tables and matching records with records from left table (Null values from right table) and records from right table (Null values from left table):
Note : FULL OUTER JOIN is a combination of a LEFT JOIN and a RIGHT JOIN .
2) LEFT | LEFT_OUTER : Left Join (or Left Outer join) on column Id will return columns from both the tables and matching records with records from left table (Null values from right table):
3) RIGHT | RIGHT_OUTER : Right Join (or Right Outer join) on column Id will return columns from both the tables and matching records with records from right table (Null values from left table):
4) LEFT_SEMI : Left Semi Join on column Id will return columns only from left table and matching records only from left table in other words....left_semi join type is essentially a filter on the left table based on the join condition.
5) LEFT_ANTI : filters out all entries from the left table which have a corresponding entry in the right table.
Case 3 : Cartesian product or Cross join :
A Cartesian join, also known as a Cartesian product, is a join of every row of one table to every row of another table.
Case 4 : createOrReplaceTempView example
Creates a local temporary view using the given name. The lifetime of this temporary view is tied to the [[SparkSession]] that was used to create this Dataset. Generally its used to query with SQL rather than programatic way. SQL Master love this feature. explained in the below program with inner join all join types can be achieved in SQL Way
Case 5 : Except : return a new DataFrame containing rows in left hand side dataframe but not in right hand side dataframe.
Standalone program to demonstrate afore mentioned...
import org.apache.spark.sql._
import org.apache.spark.sql.functions._
/**
* @author : Ram Ghadiyaram
*/
object SparkJoinTypesDemo extends App {
private implicit val spark = SparkSession.builder().master("local[*]").getOrCreate()
spark.sparkContext.setLogLevel("ERROR")
case class Person(name: String, age: Int, personid: Int)
case class Profile(profileName: String, personid: Int, profileDescription: String)
/**
* * @param joinTypes Type of join to perform. Default `inner`. Must be one of:
* * `inner`, `cross`, `outer`, `full`, `full_outer`, `left`, `left_outer`,
* * `right`, `right_outer`, `left_semi`, `left_anti`.
*/
val joinTypes = Seq(
"inner"
, "outer"
, "full"
, "full_outer"
, "left"
, "left_outer"
, "right"
, "right_outer"
, "left_semi"
, "left_anti"//, "cross"
)
val personDataFrame = spark.sqlContext.createDataFrame(
Person("Nataraj", 45, 2)
:: Person("Srinivas", 45, 5)
:: Person("Ashik", 22, 9)
:: Person("Deekshita", 22, 8)
:: Person("Siddhika", 22, 4)
:: Person("Madhu", 22, 3)
:: Person("Meghna", 22, 2)
:: Person("Snigdha", 22, 2)
:: Person("Harshita", 22, 6)
:: Person("Ravi", 42, 0)
:: Person("Ram", 42, 9)
:: Person("Chidananda Raju", 35, 9)
:: Person("Sreekanth Doddy", 29, 9)
:: Nil)
val profileDataFrame = spark.sqlContext.createDataFrame(
Profile("Spark", 2, "SparkSQLMaster")
:: Profile("Spark", 5, "SparkGuru")
:: Profile("Spark", 9, "DevHunter")
:: Profile("Spark", 3, "Evangelist")
:: Profile("Spark", 0, "Committer")
:: Profile("Spark", 1, "All Rounder")
:: Nil
)
println("Case 1: First example inner join ")
val df_asPerson = personDataFrame.as("dfperson")
val df_asProfile = profileDataFrame.as("dfprofile")
val joined_df = df_asPerson.join(
df_asProfile
, col("dfperson.personid") === col("dfprofile.personid")
, "inner")
// you can do alias to refer column name with aliases to increase readability
joined_df.select(
col("dfperson.name")
, col("dfperson.age")
, col("dfprofile.profileName")
, col("dfprofile.profileDescription"))
.show
file:\\D:\\veeraravi\\veeraravi\\drivedata\\DataSets\\wordCount14\\"
println("Case 2: All Spark supported joins in a loop example inner join ")
joinTypes.zipWithIndex.foreach {
case (element, index) => println(s" Index :$index -> ${element.toUpperCase()}")
}
println("all joins in a loop")
joinTypes.zipWithIndex.foreach { case (joinType, index) =>
println(s"-----> $index ${joinType.toUpperCase()} JOIN")
df_asPerson.join(right = df_asProfile, Seq("personid"), joinType)
.orderBy("personid")
.show()
}
println(""" Case 3 Cartesian product:
|Till 1.x cross join is : df_asPerson.join(df_asProfile)
|
| Explicit Cross Join in 2.x :
|
| Cartesian joins are very expensive without an extra filter that can be pushed down.
|
| cross join or cartesian product
|
|
""".stripMargin)
val crossJoinDf = df_asPerson.crossJoin(right = df_asProfile)
crossJoinDf.show(200, false)
crossJoinDf.explain()
println("number of rows of cartesian product " + crossJoinDf.count.toString)
println("Case 4 : createOrReplaceTempView example ")
println(
"""
|Creates a local temporary view using the given name. The lifetime of this
| temporary view is tied to the [[SparkSession]] that was used to create this Dataset.
""".stripMargin)
df_asPerson.createOrReplaceTempView("dfperson");
df_asProfile.createOrReplaceTempView("dfprofile")
val sql =
s"""
|SELECT dfperson.name
|, dfperson.age
|, dfprofile.profileDescription
| FROM dfperson JOIN dfprofile
| ON dfperson.personid == dfprofile.personid
""".stripMargin
println(s"createOrReplaceTempView sql $sql")
val sqldf = spark.sql(sql)
sqldf.show
println(
"""
|Case 5 :
|**** EXCEPT DEMO ***
|
""".stripMargin)
println("Case 5.1 df_asPerson.except(df_asProfile) Except demo")
df_asPerson.except(df_asProfile).show
println("Case 5.2 df_asProfile.except(df_asPerson) Except demo")
df_asProfile.except(df_asPerson).show
}
Result :
Case 1: First example inner join
+---------------+---+-----------+------------------+
| name|age|profileName|profileDescription|
+---------------+---+-----------+------------------+
| Nataraj| 45| Spark| SparkSQLMaster|
| Srinivas| 45| Spark| SparkGuru|
| Ashik| 22| Spark| DevHunter|
| Madhu| 22| Spark| Evangelist|
| Meghna| 22| Spark| SparkSQLMaster|
| Snigdha| 22| Spark| SparkSQLMaster|
| Ravi| 42| Spark| Committer|
| Ram| 42| Spark| DevHunter|
|Chidananda Raju| 35| Spark| DevHunter|
|Sreekanth Doddy| 29| Spark| DevHunter|
+---------------+---+-----------+------------------+
Case 2: All Spark supported joins in a loop example inner join
Index :0 -> INNER
Index :1 -> OUTER
Index :2 -> FULL
Index :3 -> FULL_OUTER
Index :4 -> LEFT
Index :5 -> LEFT_OUTER
Index :6 -> RIGHT
Index :7 -> RIGHT_OUTER
Index :8 -> LEFT_SEMI
Index :9 -> LEFT_ANTI
all joins in a loop
-----> 0 INNER JOIN
+--------+---------------+---+-----------+------------------+
|personid| name|age|profileName|profileDescription|
+--------+---------------+---+-----------+------------------+
| 0| Ravi| 42| Spark| Committer|
| 2| Snigdha| 22| Spark| SparkSQLMaster|
| 2| Nataraj| 45| Spark| SparkSQLMaster|
| 2| Meghna| 22| Spark| SparkSQLMaster|
| 3| Madhu| 22| Spark| Evangelist|
| 5| Srinivas| 45| Spark| SparkGuru|
| 9| Ram| 42| Spark| DevHunter|
| 9| Ashik| 22| Spark| DevHunter|
| 9|Chidananda Raju| 35| Spark| DevHunter|
| 9|Sreekanth Doddy| 29| Spark| DevHunter|
+--------+---------------+---+-----------+------------------+
-----> 1 OUTER JOIN
+--------+---------------+----+-----------+------------------+
|personid| name| age|profileName|profileDescription|
+--------+---------------+----+-----------+------------------+
| 0| Ravi| 42| Spark| Committer|
| 1| null|null| Spark| All Rounder|
| 2| Nataraj| 45| Spark| SparkSQLMaster|
| 2| Meghna| 22| Spark| SparkSQLMaster|
| 2| Snigdha| 22| Spark| SparkSQLMaster|
| 3| Madhu| 22| Spark| Evangelist|
| 4| Siddhika| 22| null| null|
| 5| Srinivas| 45| Spark| SparkGuru|
| 6| Harshita| 22| null| null|
| 8| Deekshita| 22| null| null|
| 9| Ashik| 22| Spark| DevHunter|
| 9|Sreekanth Doddy| 29| Spark| DevHunter|
| 9| Ram| 42| Spark| DevHunter|
| 9|Chidananda Raju| 35| Spark| DevHunter|
+--------+---------------+----+-----------+------------------+
-----> 2 FULL JOIN
+--------+---------------+----+-----------+------------------+
|personid| name| age|profileName|profileDescription|
+--------+---------------+----+-----------+------------------+
| 0| Ravi| 42| Spark| Committer|
| 1| null|null| Spark| All Rounder|
| 2| Nataraj| 45| Spark| SparkSQLMaster|
| 2| Meghna| 22| Spark| SparkSQLMaster|
| 2| Snigdha| 22| Spark| SparkSQLMaster|
| 3| Madhu| 22| Spark| Evangelist|
| 4| Siddhika| 22| null| null|
| 5| Srinivas| 45| Spark| SparkGuru|
| 6| Harshita| 22| null| null|
| 8| Deekshita| 22| null| null|
| 9| Ashik| 22| Spark| DevHunter|
| 9|Chidananda Raju| 35| Spark| DevHunter|
| 9| Ram| 42| Spark| DevHunter|
| 9|Sreekanth Doddy| 29| Spark| DevHunter|
+--------+---------------+----+-----------+------------------+
-----> 3 FULL_OUTER JOIN
+--------+---------------+----+-----------+------------------+
|personid| name| age|profileName|profileDescription|
+--------+---------------+----+-----------+------------------+
| 0| Ravi| 42| Spark| Committer|
| 1| null|null| Spark| All Rounder|
| 2| Nataraj| 45| Spark| SparkSQLMaster|
| 2| Meghna| 22| Spark| SparkSQLMaster|
| 2| Snigdha| 22| Spark| SparkSQLMaster|
| 3| Madhu| 22| Spark| Evangelist|
| 4| Siddhika| 22| null| null|
| 5| Srinivas| 45| Spark| SparkGuru|
| 6| Harshita| 22| null| null|
| 8| Deekshita| 22| null| null|
| 9| Ashik| 22| Spark| DevHunter|
| 9|Chidananda Raju| 35| Spark| DevHunter|
| 9| Ram| 42| Spark| DevHunter|
| 9|Sreekanth Doddy| 29| Spark| DevHunter|
+--------+---------------+----+-----------+------------------+
-----> 4 LEFT JOIN
+--------+---------------+---+-----------+------------------+
|personid| name|age|profileName|profileDescription|
+--------+---------------+---+-----------+------------------+
| 0| Ravi| 42| Spark| Committer|
| 2| Snigdha| 22| Spark| SparkSQLMaster|
| 2| Nataraj| 45| Spark| SparkSQLMaster|
| 2| Meghna| 22| Spark| SparkSQLMaster|
| 3| Madhu| 22| Spark| Evangelist|
| 4| Siddhika| 22| null| null|
| 5| Srinivas| 45| Spark| SparkGuru|
| 6| Harshita| 22| null| null|
| 8| Deekshita| 22| null| null|
| 9| Ashik| 22| Spark| DevHunter|
| 9|Chidananda Raju| 35| Spark| DevHunter|
| 9|Sreekanth Doddy| 29| Spark| DevHunter|
| 9| Ram| 42| Spark| DevHunter|
+--------+---------------+---+-----------+------------------+
-----> 5 LEFT_OUTER JOIN
+--------+---------------+---+-----------+------------------+
|personid| name|age|profileName|profileDescription|
+--------+---------------+---+-----------+------------------+
| 0| Ravi| 42| Spark| Committer|
| 2| Snigdha| 22| Spark| SparkSQLMaster|
| 2| Meghna| 22| Spark| SparkSQLMaster|
| 2| Nataraj| 45| Spark| SparkSQLMaster|
| 3| Madhu| 22| Spark| Evangelist|
| 4| Siddhika| 22| null| null|
| 5| Srinivas| 45| Spark| SparkGuru|
| 6| Harshita| 22| null| null|
| 8| Deekshita| 22| null| null|
| 9|Chidananda Raju| 35| Spark| DevHunter|
| 9|Sreekanth Doddy| 29| Spark| DevHunter|
| 9| Ram| 42| Spark| DevHunter|
| 9| Ashik| 22| Spark| DevHunter|
+--------+---------------+---+-----------+------------------+
-----> 6 RIGHT JOIN
+--------+---------------+----+-----------+------------------+
|personid| name| age|profileName|profileDescription|
+--------+---------------+----+-----------+------------------+
| 0| Ravi| 42| Spark| Committer|
| 1| null|null| Spark| All Rounder|
| 2| Meghna| 22| Spark| SparkSQLMaster|
| 2| Snigdha| 22| Spark| SparkSQLMaster|
| 2| Nataraj| 45| Spark| SparkSQLMaster|
| 3| Madhu| 22| Spark| Evangelist|
| 5| Srinivas| 45| Spark| SparkGuru|
| 9|Sreekanth Doddy| 29| Spark| DevHunter|
| 9| Ram| 42| Spark| DevHunter|
| 9|Chidananda Raju| 35| Spark| DevHunter|
| 9| Ashik| 22| Spark| DevHunter|
+--------+---------------+----+-----------+------------------+
-----> 7 RIGHT_OUTER JOIN
+--------+---------------+----+-----------+------------------+
|personid| name| age|profileName|profileDescription|
+--------+---------------+----+-----------+------------------+
| 0| Ravi| 42| Spark| Committer|
| 1| null|null| Spark| All Rounder|
| 2| Snigdha| 22| Spark| SparkSQLMaster|
| 2| Meghna| 22| Spark| SparkSQLMaster|
| 2| Nataraj| 45| Spark| SparkSQLMaster|
| 3| Madhu| 22| Spark| Evangelist|
| 5| Srinivas| 45| Spark| SparkGuru|
| 9|Sreekanth Doddy| 29| Spark| DevHunter|
| 9|Chidananda Raju| 35| Spark| DevHunter|
| 9| Ram| 42| Spark| DevHunter|
| 9| Ashik| 22| Spark| DevHunter|
+--------+---------------+----+-----------+------------------+
-----> 8 LEFT_SEMI JOIN
+--------+---------------+---+
|personid| name|age|
+--------+---------------+---+
| 0| Ravi| 42|
| 2| Snigdha| 22|
| 2| Meghna| 22|
| 2| Nataraj| 45|
| 3| Madhu| 22|
| 5| Srinivas| 45|
| 9| Ashik| 22|
| 9| Ram| 42|
| 9|Chidananda Raju| 35|
| 9|Sreekanth Doddy| 29|
+--------+---------------+---+
-----> 9 LEFT_ANTI JOIN
+--------+---------+---+
|personid| name|age|
+--------+---------+---+
| 4| Siddhika| 22|
| 6| Harshita| 22|
| 8|Deekshita| 22|
+--------+---------+---+
Case 3 Cartesian product:
Till 1.x cross join is : df_asPerson.join(df_asProfile)
Explicit Cross Join in 2.x :
Cartesian joins are very expensive without an extra filter that can be pushed down.
cross join or cartesian product
+---------------+---+--------+-----------+--------+------------------+
|name |age|personid|profileName|personid|profileDescription|
+---------------+---+--------+-----------+--------+------------------+
|Nataraj |45 |2 |Spark |2 |SparkSQLMaster |
|Nataraj |45 |2 |Spark |5 |SparkGuru |
|Nataraj |45 |2 |Spark |9 |DevHunter |
|Nataraj |45 |2 |Spark |3 |Evangelist |
|Nataraj |45 |2 |Spark |0 |Committer |
|Nataraj |45 |2 |Spark |1 |All Rounder |
|Srinivas |45 |5 |Spark |2 |SparkSQLMaster |
|Srinivas |45 |5 |Spark |5 |SparkGuru |
|Srinivas |45 |5 |Spark |9 |DevHunter |
|Srinivas |45 |5 |Spark |3 |Evangelist |
|Srinivas |45 |5 |Spark |0 |Committer |
|Srinivas |45 |5 |Spark |1 |All Rounder |
|Ashik |22 |9 |Spark |2 |SparkSQLMaster |
|Ashik |22 |9 |Spark |5 |SparkGuru |
|Ashik |22 |9 |Spark |9 |DevHunter |
|Ashik |22 |9 |Spark |3 |Evangelist |
|Ashik |22 |9 |Spark |0 |Committer |
|Ashik |22 |9 |Spark |1 |All Rounder |
|Deekshita |22 |8 |Spark |2 |SparkSQLMaster |
|Deekshita |22 |8 |Spark |5 |SparkGuru |
|Deekshita |22 |8 |Spark |9 |DevHunter |
|Deekshita |22 |8 |Spark |3 |Evangelist |
|Deekshita |22 |8 |Spark |0 |Committer |
|Deekshita |22 |8 |Spark |1 |All Rounder |
|Siddhika |22 |4 |Spark |2 |SparkSQLMaster |
|Siddhika |22 |4 |Spark |5 |SparkGuru |
|Siddhika |22 |4 |Spark |9 |DevHunter |
|Siddhika |22 |4 |Spark |3 |Evangelist |
|Siddhika |22 |4 |Spark |0 |Committer |
|Siddhika |22 |4 |Spark |1 |All Rounder |
|Madhu |22 |3 |Spark |2 |SparkSQLMaster |
|Madhu |22 |3 |Spark |5 |SparkGuru |
|Madhu |22 |3 |Spark |9 |DevHunter |
|Madhu |22 |3 |Spark |3 |Evangelist |
|Madhu |22 |3 |Spark |0 |Committer |
|Madhu |22 |3 |Spark |1 |All Rounder |
|Meghna |22 |2 |Spark |2 |SparkSQLMaster |
|Meghna |22 |2 |Spark |5 |SparkGuru |
|Meghna |22 |2 |Spark |9 |DevHunter |
|Meghna |22 |2 |Spark |3 |Evangelist |
|Meghna |22 |2 |Spark |0 |Committer |
|Meghna |22 |2 |Spark |1 |All Rounder |
|Snigdha |22 |2 |Spark |2 |SparkSQLMaster |
|Snigdha |22 |2 |Spark |5 |SparkGuru |
|Snigdha |22 |2 |Spark |9 |DevHunter |
|Snigdha |22 |2 |Spark |3 |Evangelist |
|Snigdha |22 |2 |Spark |0 |Committer |
|Snigdha |22 |2 |Spark |1 |All Rounder |
|Harshita |22 |6 |Spark |2 |SparkSQLMaster |
|Harshita |22 |6 |Spark |5 |SparkGuru |
|Harshita |22 |6 |Spark |9 |DevHunter |
|Harshita |22 |6 |Spark |3 |Evangelist |
|Harshita |22 |6 |Spark |0 |Committer |
|Harshita |22 |6 |Spark |1 |All Rounder |
|Ravi |42 |0 |Spark |2 |SparkSQLMaster |
|Ravi |42 |0 |Spark |5 |SparkGuru |
|Ravi |42 |0 |Spark |9 |DevHunter |
|Ravi |42 |0 |Spark |3 |Evangelist |
|Ravi |42 |0 |Spark |0 |Committer |
|Ravi |42 |0 |Spark |1 |All Rounder |
|Ram |42 |9 |Spark |2 |SparkSQLMaster |
|Ram |42 |9 |Spark |5 |SparkGuru |
|Ram |42 |9 |Spark |9 |DevHunter |
|Ram |42 |9 |Spark |3 |Evangelist |
|Ram |42 |9 |Spark |0 |Committer |
|Ram |42 |9 |Spark |1 |All Rounder |
|Chidananda Raju|35 |9 |Spark |2 |SparkSQLMaster |
|Chidananda Raju|35 |9 |Spark |5 |SparkGuru |
|Chidananda Raju|35 |9 |Spark |9 |DevHunter |
|Chidananda Raju|35 |9 |Spark |3 |Evangelist |
|Chidananda Raju|35 |9 |Spark |0 |Committer |
|Chidananda Raju|35 |9 |Spark |1 |All Rounder |
|Sreekanth Doddy|29 |9 |Spark |2 |SparkSQLMaster |
|Sreekanth Doddy|29 |9 |Spark |5 |SparkGuru |
|Sreekanth Doddy|29 |9 |Spark |9 |DevHunter |
|Sreekanth Doddy|29 |9 |Spark |3 |Evangelist |
|Sreekanth Doddy|29 |9 |Spark |0 |Committer |
|Sreekanth Doddy|29 |9 |Spark |1 |All Rounder |
+---------------+---+--------+-----------+--------+------------------+
== Physical Plan ==
BroadcastNestedLoopJoin BuildRight, Cross
:- LocalTableScan [name#0, age#1, personid#2]
+- BroadcastExchange IdentityBroadcastMode
+- LocalTableScan [profileName#7, personid#8, profileDescription#9]
number of rows of cartesian product 78
Case 4 : createOrReplaceTempView example
Creates a local temporary view using the given name. The lifetime of this
temporary view is tied to the [[SparkSession]] that was used to create this Dataset.
createOrReplaceTempView sql
SELECT dfperson.name
, dfperson.age
, dfprofile.profileDescription
FROM dfperson JOIN dfprofile
ON dfperson.personid == dfprofile.personid
+---------------+---+------------------+
| name|age|profileDescription|
+---------------+---+------------------+
| Nataraj| 45| SparkSQLMaster|
| Srinivas| 45| SparkGuru|
| Ashik| 22| DevHunter|
| Madhu| 22| Evangelist|
| Meghna| 22| SparkSQLMaster|
| Snigdha| 22| SparkSQLMaster|
| Ravi| 42| Committer|
| Ram| 42| DevHunter|
|Chidananda Raju| 35| DevHunter|
|Sreekanth Doddy| 29| DevHunter|
+---------------+---+------------------+
Case 5 :
**** EXCEPT DEMO ***
Case 5.1 df_asPerson.except(df_asProfile) Except demo
+---------------+---+--------+
| name|age|personid|
+---------------+---+--------+
| Ashik| 22| 9|
| Harshita| 22| 6|
| Madhu| 22| 3|
| Ram| 42| 9|
| Ravi| 42| 0|
|Chidananda Raju| 35| 9|
| Siddhika| 22| 4|
| Srinivas| 45| 5|
|Sreekanth Doddy| 29| 9|
| Deekshita| 22| 8|
| Meghna| 22| 2|
| Snigdha| 22| 2|
| Nataraj| 45| 2|
+---------------+---+--------+
Case 5.2 df_asProfile.except(df_asPerson) Except demo
+-----------+--------+------------------+
|profileName|personid|profileDescription|
+-----------+--------+------------------+
| Spark| 5| SparkGuru|
| Spark| 9| DevHunter|
| Spark| 2| SparkSQLMaster|
| Spark| 3| Evangelist|
| Spark| 0| Committer|
| Spark| 1| All Rounder|
+-----------+--------+------------------+