Details

Description

Semi-join is an efficient way to unnest an IN/EXISTS subquery. For example,

select *
from A
where A.id IN
(select id
from B
where B.date> '2009-10-01');

returns from A whose ID is in the set of IDs found in B, whose date is greater than a certain date. This query can be unnested using a INNER join or LEFT OUTER JOIN, but we need to deduplicate the IDs returned by the subquery on table B. The semantics of LEFT SEMI JOIN is that as long as there is ANY row in the right-hand table that matches the join key, the left-hand table row will be emitted as a result w/o necessarily looking further in the right-hand table for further matches. This is exactly the semantics of the IN subquery.

Ning Zhang
added a comment - 09/Nov/09 22:40 A new patch Hive-870_3.patch is attached. This patch reverted the change to QTestUtils.java to handle comments in unit tests and output file changes due to this.

Do you want to separate out the comment changes and file a new jira for that ?
That is blowing up the number of files, and making it difficult to review. If you
think that will help, please file a new jira and submit a patch for that - I will try to
take a look at that asap.

Namit Jain
added a comment - 09/Nov/09 05:26 Can you add more tests with STREAMTABLE also ?
Do you want to separate out the comment changes and file a new jira for that ?
That is blowing up the number of files, and making it difficult to review. If you
think that will help, please file a new jira and submit a patch for that - I will try to
take a look at that asap.

Namit Jain
added a comment - 09/Nov/09 05:21
PREHOOK: query: select a.key from t3 a left outer join t1 b on a.key = b.key left semi join t2 c on b.key\
= c.key sort by a.key
Can you check the output ? I need to double-check it, but it looks wrong at the first glance.

Namit Jain
added a comment - 05/Nov/09 01:31 talked with Ning offline.
2 things need to be tested:
1. Why can't we have a group by in case of map join
2. There seems to be a problem in the case: A left semi join B right outer join C

1) enhance the HiveQL syntax to support left semi join.
2) introduce a new left semi join type in the CommonJoinOperator. This join operator implements early-exit whenever a match is found in the right-hand-side table of the left semi join.
3) At the map side, add a select operator to project the join keys only of the RHS table, followed by a map-side partial group-by operator that eliminate duplicate keys. We only need the key, the value is NULL.
4) if the RHS is used as map-side join, only the selection operator is introduced. The map-side groupby operator is not necessary.
5) some misc clean ups (e.g., allowing '--' comments appear in any place in the unit test qfiles). A lot of unit test diffs are due to this change. All the unit tests for semi join are in semijoin.q.

Ning Zhang
added a comment - 04/Nov/09 07:18 Uploading Hive-870.patch. This patch includes the following changes:
1) enhance the HiveQL syntax to support left semi join.
2) introduce a new left semi join type in the CommonJoinOperator. This join operator implements early-exit whenever a match is found in the right-hand-side table of the left semi join.
3) At the map side, add a select operator to project the join keys only of the RHS table, followed by a map-side partial group-by operator that eliminate duplicate keys. We only need the key, the value is NULL.
4) if the RHS is used as map-side join, only the selection operator is introduced. The map-side groupby operator is not necessary.
5) some misc clean ups (e.g., allowing '--' comments appear in any place in the unit test qfiles). A lot of unit test diffs are due to this change. All the unit tests for semi join are in semijoin.q.