Return-Path: X-Original-To: apmail-hive-user-archive@www.apache.org Delivered-To: apmail-hive-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6935BEDE7 for ; Thu, 13 Dec 2012 19:12:55 +0000 (UTC) Received: (qmail 24684 invoked by uid 500); 13 Dec 2012 19:12:54 -0000 Delivered-To: apmail-hive-user-archive@hive.apache.org Received: (qmail 24527 invoked by uid 500); 13 Dec 2012 19:12:53 -0000 Mailing-List: contact user-help@hive.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@hive.apache.org Delivered-To: mailing list user@hive.apache.org Received: (qmail 24519 invoked by uid 99); 13 Dec 2012 19:12:53 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Dec 2012 19:12:53 +0000 X-ASF-Spam-Status: No, hits=1.7 required=5.0 tests=FREEMAIL_ENVFROM_END_DIGIT,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of chen.song.82@gmail.com designates 209.85.210.176 as permitted sender) Received: from [209.85.210.176] (HELO mail-ia0-f176.google.com) (209.85.210.176) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Dec 2012 19:12:46 +0000 Received: by mail-ia0-f176.google.com with SMTP id y26so2294540iab.35 for ; Thu, 13 Dec 2012 11:12:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ChnZqJXu/TGj0m5KbBfMiOFYnV5/KruH/OFo3G9dtLM=; b=bwEc8RUDs/8LKJg38CwnjlccpEbqP0FjI3nM/hod/+hhxnF848kmQGdNQBfPffdD5Z wagnE4ntt7SB9bRbomEkh9xhR35nBluSPdC4MOkTdU96XEkjczjMeysCEscIEqM+qr7J cTkzoZUoPb0rUKTiS7wPpAQWNr3hId4XFrUiWYTEvgObl9VQTS8Rvg+3N8yJTf16AKVt wI1MAHyDmAE/L1CkD/0otwthfqxJo09uEoCSbsTj9mTV3DVRAyOo9Ojyd9jBJCcQE+kY hNURFpU5hKs8bks3NZApPQ6ZzCavzZZvZ8F0jBmJERk+v1Lcr4zMowvVWbFjPWBpPE1H GKBQ== MIME-Version: 1.0 Received: by 10.50.152.231 with SMTP id vb7mr2848942igb.1.1355425945375; Thu, 13 Dec 2012 11:12:25 -0800 (PST) Received: by 10.231.231.200 with HTTP; Thu, 13 Dec 2012 11:12:25 -0800 (PST) In-Reply-To: References: Date: Thu, 13 Dec 2012 14:12:25 -0500 Message-ID: Subject: Re: map side join with group by From: Chen Song To: user@hive.apache.org Content-Type: multipart/alternative; boundary=e89a8f3b9e95fe550e04d0c0b1a7 X-Virus-Checked: Checked by ClamAV on apache.org --e89a8f3b9e95fe550e04d0c0b1a7 Content-Type: text/plain; charset=ISO-8859-1 Nitin Yeah. My original question is that is there a way to force Hive (or rather to say, is it possible) to execute map side join at mapper phase and group by in reduce phase. So instead of launching a map only job (join) and map reduce job (group by), doing it altogether in a single MR job. This is obviously not what Hive does but I am wondering if it is a nice feature to have. The point you made (different keys in join and group by) only matters when it is the time in reduce phase, right? As map side join takes care of join at mapper phase, it sounds to me natural that group by can be done in the reduce phase in the same job. The only hassle that I can think of is that map output have to be resorted (based on group by keys). Chen On Thu, Dec 13, 2012 at 1:42 PM, Nitin Pawar wrote: > chen in mapside join .. there are no reducers .. its MAP ONLY job > > > On Thu, Dec 13, 2012 at 11:54 PM, Chen Song wrote: > >> Understood that fact that it is impossible in the same MR job if both >> join and group by are gonna happen in the reduce phase (because the join >> keys and group by keys are different). But for map side join, the joins >> would be complete by the end of the map phase, and outputs should be ready >> to be distributed to reducers based on group by keys. >> >> Chen >> >> >> On Thu, Dec 13, 2012 at 11:04 AM, Nitin Pawar wrote: >> >>> Thats because for the first job the join keys are different and second >>> job group by keys are different, you just cant assume join keys and group >>> keys will be same so they are two different jobs >>> >>> >>> On Thu, Dec 13, 2012 at 8:26 PM, Chen Song wrote: >>> >>>> Yeah, my abridged version of query might be a little broken but my >>>> point is that when a query has a map join and group by, even in its >>>> simplified incarnation, it will launch two jobs. I was just wondering why >>>> map join and group by cannot be accomplished in one MR job. >>>> >>>> Best, >>>> Chen >>>> >>>> >>>> On Thu, Dec 13, 2012 at 12:30 AM, Nitin Pawar wrote: >>>> >>>>> I think Chen wanted to know why this is two phased query if I >>>>> understood it correctly >>>>> >>>>> When you run a mapside join .. it just performs the join query .. >>>>> after that to execute the group by part it launches the second job. >>>>> I may be wrong but this is how I saw it whenever I executed group by >>>>> queries >>>>> >>>>> >>>>> On Thu, Dec 13, 2012 at 7:11 AM, Mark Grover < >>>>> grover.markgrover@gmail.com> wrote: >>>>> >>>>>> Hi Chen, >>>>>> I think we would need some more information. >>>>>> >>>>>> The query is referring to a table called "d" in the MAPJOIN hint but >>>>>> there is not such table in the query. Moreover, Map joins only make >>>>>> sense when the right table is the one being "mapped" (in other words, >>>>>> being kept in memory) in case of a Left Outer Join, similarly if the >>>>>> left table is the one being "mapped" in case of a Right Outer Join. >>>>>> Let me know if this is not clear, I'd be happy to offer a better >>>>>> explanation. >>>>>> >>>>>> In your query, the where clause on a column called "hour", at this >>>>>> point I am unsure if that's a column of table1 or table2. If it's >>>>>> column on table1, that predicate would get pushed up (if you have >>>>>> hive.optimize.ppd property set to true), so it could possibly be done >>>>>> in 1 MR job (I am not sure if that's presently the case, you will have >>>>>> to check the explain plan). If however, the where clause is on a >>>>>> column in the right table (table2 in your example), it can't be pushed >>>>>> up since a column of the right table can have different values before >>>>>> and after the LEFT OUTER JOIN. Therefore, the where clause would need >>>>>> to be applied in a separate MR job. >>>>>> >>>>>> This is just my understanding, the full proof answer would lie in >>>>>> checking out the explain plans and the Semantic Analyzer code. >>>>>> >>>>>> And for completeness, there is a conditional task (starting Hive 0.7) >>>>>> that will convert your joins automatically to map joins where >>>>>> applicable. This can be enabled by enabling hive.auto.convert.join >>>>>> property. >>>>>> >>>>>> Mark >>>>>> >>>>>> On Wed, Dec 12, 2012 at 3:32 PM, Chen Song >>>>>> wrote: >>>>>> > I have a silly question on how Hive interpretes a simple query with >>>>>> both map >>>>>> > side join and group by. >>>>>> > >>>>>> > Below query will translate into two jobs, with the 1st one as a map >>>>>> only job >>>>>> > doing the join and storing the output in a intermediary location, >>>>>> and the >>>>>> > 2nd one as a map-reduce job taking the output of the 1st job as >>>>>> input and >>>>>> > doing the group by. >>>>>> > >>>>>> > SELECT >>>>>> > /*+ MAPJOIN(d) */ >>>>>> > table.a, sum(table2.b) >>>>>> > from table >>>>>> > LEFT OUTER JOIN table2 >>>>>> > ON table.id = table2.id >>>>>> > where hour = '2012-12-11 11' >>>>>> > group by table.a >>>>>> > >>>>>> > Why can't this be done within a single map reduce job? As what I >>>>>> can see >>>>>> > from the query plan is that all 2nd job mapper do is taking the 1st >>>>>> job's >>>>>> > mapper output. >>>>>> > >>>>>> > -- >>>>>> > Chen Song >>>>>> > >>>>>> > >>>>>> >>>>> >>>>> >>>>> >>>>> -- >>>>> Nitin Pawar >>>>> >>>> >>>> >>>> >>>> -- >>>> Chen Song >>>> >>>> >>>> >>> >>> >>> -- >>> Nitin Pawar >>> >> >> >> >> -- >> Chen Song >> >> >> > > > -- > Nitin Pawar > -- Chen Song --e89a8f3b9e95fe550e04d0c0b1a7 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Nitin

Yeah. My original question is that is there a way = to force Hive (or rather to say, is it possible) to execute map side join a= t mapper phase and group by in reduce phase. So instead of launching a map = only job (join) and map reduce job (group by), doing it altogether in a sin= gle MR job. This is obviously not what Hive does but I am wondering if it i= s a nice feature to have.

The point you made (different keys in join and group by= ) only matters when it is the time in reduce phase, right? As map side join= takes care of join at mapper phase, it sounds to me natural that group by = can be done in the reduce phase in the same job. The only hassle that I can= think of is that map output have to be resorted (based on group by keys).<= /div>

Chen

On Thu, D= ec 13, 2012 at 1:42 PM, Nitin Pawar <nitinpawar432@gmail.com>= wrote:
chen in mapside join .. there are no reducer= s .. its MAP ONLY job=A0
<= br>
On Thu, Dec 13, 2012 at 11:54 PM, Chen Song <chen.song.82@gmail.com> wrote:
Understood that fact that it is impossible i= n the same MR job if both join and group by are gonna happen in the reduce = phase (because the join keys and group by keys are different). But for map = side join, the joins would be complete by the end of the map phase, and out= puts should be ready to be distributed to reducers based on group by keys.<= div>
Chen


On Thu, Dec= 13, 2012 at 11:04 AM, Nitin Pawar <nitinpawar432@gmail.com><= /span> wrote:
Thats because for the first job the join key= s are different and second job group by keys are different, you just cant a= ssume join keys and group keys will be same so they are two different jobs= =A0


On Thu, Dec 13, 2012 at 8:26 PM, Chen Song <= span dir=3D"ltr"><chen.song.82@gmail.com> wrote:
Yeah, my abridged version of query might be a little broken but my point is= that when a query has a map join and group by, even in its simplified inca= rnation, it will launch two jobs. I was just wondering why map join and gro= up by cannot be accomplished in one MR job.

Best,
Chen


On Thu, Dec 13, 2012 at 12:30 AM, Nitin Pawar <nitinpawar432@gm= ail.com> wrote:
I think Chen wanted to know why this is two = phased query if I understood it correctly=A0

When you ru= n a mapside join .. it just performs the join query .. after that to execut= e the group by part it launches the second job.=A0
I may be wrong but this is how I saw it whenever I executed group by q= ueries=A0


On Thu, Dec 13, 2012 at 7:11 AM, Mark Grover = <grover= .markgrover@gmail.com> wrote:
Hi Chen,
I think we would need some more information.

The query is referring to a table called "d" in the MAPJOIN hint = but
there is not such table in the query. Moreover, Map joins only make
sense when the right table is the one being "mapped" (in other wo= rds,
being kept in memory) in case of a Left Outer Join, similarly if the
left table is the one being "mapped" in case of a Right Outer Joi= n.
Let me know if this is not clear, I'd be happy to offer a better
explanation.

In your query, the where clause on a column called "hour", at thi= s
point I am unsure if that's a column of table1 or table2. If it's column on table1, that predicate would get pushed up (if you have
hive.optimize.ppd property set to true), so it could possibly be done
in 1 MR job (I am not sure if that's presently the case, you will have<= br> to check the explain plan). If however, the where clause is on a
column in the right table (table2 in your example), it can't be pushed<= br> up since a column of the right table can have different values before
and after the LEFT OUTER JOIN. Therefore, the where clause would need
to be applied in a separate MR job.

This is just my understanding, the full proof answer would lie in
checking out the explain plans and the Semantic Analyzer code.

And for completeness, there is a conditional task (starting Hive 0.7)
that will convert your joins automatically to map joins where
applicable. This can be enabled by enabling hive.auto.convert.join
property.

Mark

On Wed, Dec 12, 2012 at 3:32 PM, Chen Song <chen.song.82@gmail.com> wrote:
> I have a silly question on how Hive interpretes a simple query with bo= th map
> side join and group by.
>
> Below query will translate into two jobs, with the 1st one as a map on= ly job
> doing the join and storing the output in a intermediary location, and = the
> 2nd one as a map-reduce job taking the output of the 1st job as input = and
> doing the group by.
>
> SELECT
> /*+ MAPJOIN(d) */
> table.a, sum(table2.b)
> from table
> LEFT OUTER JOIN table2
> ON table.id =3D table2.id
> where hour =3D '2012-12-11 11'
> group by table.a
>
> Why can't this be done within a single map reduce job? As what I c= an see
> from the query plan is that all 2nd job mapper do is taking the 1st jo= b's
> mapper output.
>
> --
> Chen Song
>
>



<= /div>--
Nitin Pawar



<= font color=3D"#888888">--
Chen Song





<= font color=3D"#888888">--
Nitin Pawar



<= font color=3D"#888888">--
Chen Song





--
Nitin Pawar



--
Chen Song


--e89a8f3b9e95fe550e04d0c0b1a7--