Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In spark join, does table order matter like in pig?

Related to Spark - Joining 2 PairRDD elements

When doing a regular join in pig, the last table in the join is not brought into memory but streamed through instead, so if A has small cardinality per key and B large cardinality, it is significantly better to do join A, B than join A by B, from performance perspective (avoiding spill and OOM)

Is there a similar concept in spark? I didn't see any such recommendation, and wonder how is it possible? The implementation looks to me pretty much the same as in pig: https://github.com/apache/spark/blob/master/core/src/main/scala/org/apache/spark/rdd/CoGroupedRDD.scala

Or am I missing something?

like image 502
ihadanny Avatar asked Feb 24 '15 11:02

ihadanny


People also ask

Does table order matter in join?

Summary. Table join order matters for reducing the number of rows that the rest of the query needs to process. By default SQL Server gives you no control over the join order - it uses statistics and the query optimizer to pick what it thinks is a good join order.

How does a join work in Spark?

The default join operation in Spark includes only values for keys present in both RDDs, and in the case of multiple values per key, provides all permutations of the key/value pair. The best scenario for a standard join is when both RDDs contain the same set of distinct keys.

How do you join tables in Spark?

In order to explain join with multiple tables, we will use Inner join, this is the default join in Spark and it's mostly used, this joins two DataFrames/Datasets on key columns, and where keys don't match the rows get dropped from both datasets.


1 Answers

It does not make a difference, in spark the RDD will only be brought into memory if it is cached. So in spark to achieve the same effect you can cache the smaller RDD. Another thing you can do in spark which I'm not sure that pig does, is if all RDD's being joined have the same partitioner no shuffle needs to be done.

like image 151
aaronman Avatar answered Sep 24 '22 11:09

aaronman