Details

    • Type: New Feature New Feature
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 0.5.0
    • Component/s: Query Processor
    • Labels:
      None
    • Hadoop Flags:
      Reviewed

      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.

      1. Hive-870_2.patch
        420 kB
        Ning Zhang
      2. Hive-870_3.patch
        147 kB
        Ning Zhang
      3. Hive-870.patch
        413 kB
        Ning Zhang

        Issue Links

          Activity

          Hide
          Ning Zhang added a comment -

          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.

          Show
          Ning Zhang added a comment - 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.
          Hide
          Namit Jain added a comment -

          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

          Show
          Namit Jain added a comment - 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
          Hide
          Ning Zhang added a comment -

          Uploading a new patch Hive-870_2.patch. This solves the issue in map-side left semi join, also fixed the case for mixing with right/full outer join.

          Show
          Ning Zhang added a comment - Uploading a new patch Hive-870_2.patch. This solves the issue in map-side left semi join, also fixed the case for mixing with right/full outer join.
          Hide
          Namit Jain added a comment -

          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.

          Show
          Namit Jain added a comment - 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.
          Hide
          Namit Jain added a comment -

          Ignore my earlier comment, i didnt see it is a outer join, and not a semi join

          Show
          Namit Jain added a comment - Ignore my earlier comment, i didnt see it is a outer join, and not a semi join
          Hide
          Namit Jain added a comment -

          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.

          Show
          Namit Jain added a comment - 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.
          Hide
          Ning Zhang added a comment -

          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.

          Show
          Ning Zhang added a comment - 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.
          Hide
          Namit Jain added a comment -

          Committed. Thanks Ning

          Show
          Namit Jain added a comment - Committed. Thanks Ning

            People

            • Assignee:
              Ning Zhang
              Reporter:
              Ning Zhang
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development