<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Converting Lab3 PIG script to HIVE in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141060#M27900</link>
    <description>&lt;P&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/214/agillan.html" nodeid="214"&gt;@Ana Gillan&lt;/A&gt;.. I'll try that..&lt;/P&gt;</description>
    <pubDate>Thu, 12 May 2016 11:28:53 GMT</pubDate>
    <dc:creator>vebs0205</dc:creator>
    <dc:date>2016-05-12T11:28:53Z</dc:date>
    <item>
      <title>Converting Lab3 PIG script to HIVE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141057#M27897</link>
      <description>&lt;P&gt;
	In Lab3 - using PIG to calculate risk factor, the PIG script mentioned is:&lt;/P&gt;&lt;PRE&gt;a = LOAD 'geolocation' using org.apache.hive.hcatalog.pig.HCatLoader();
b = filter a by event != 'normal';
c = foreach b generate driverid, event, (int) '1' as occurance;
d = group c by driverid;
e = foreach d generate group as driverid, SUM(c.occurance) as t_occ;
g = LOAD 'drivermileage' using org.apache.hive.hcatalog.pig.HCatLoader();
h = join e by driverid, g by driverid;
final_data = foreach h generate $0 as driverid, $1 as events, $3 as totmiles, (float) $3/$1 as riskfactor;
store final_data into 'riskfactor' using org.apache.hive.hcatalog.pig.HCatStorer();


&lt;/PRE&gt;&lt;P&gt;
	I tried doing the same using HIVE. Below is HIVE script:&lt;/P&gt;&lt;PRE&gt;CREATE TABLE riskfactor_hive STORED AS ORC AS 
select 
	t2.driverid as driverid, 
	t2.events as events, 
	dm.totmiles as totmiles, 
	dm.totmiles/t2.events as riskfactor
from
(
  select t1.driverid, count(t1.occurance) as events
	from 
	(
	  select driverid, event, 1 as occurance from geolocation
	  where event != 'normal'
	) t1
  group by t1.driverid
) t2
join drivermileage dm
on t2.driverid = dm.driverid
;
&lt;/PRE&gt;&lt;P&gt;
	Can we further optimise the HIVE script to make it run even faster?&lt;/P&gt;&lt;P&gt;
	Much Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 11:57:00 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141057#M27897</guid>
      <dc:creator>vebs0205</dc:creator>
      <dc:date>2016-05-11T11:57:00Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Lab3 PIG script to HIVE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141058#M27898</link>
      <description>&lt;P&gt;Hi &lt;A rel="user" href="https://community.cloudera.com/users/10376/vebs0205.html" nodeid="10376"&gt;@Vaibhav Yadav&lt;/A&gt;, I won't comment on the SQL optimisation (perhaps someone else can), but you can do a lot of tuning to improve Hive performance and there are a lot of articles in the community to advise you. First of all, you should be using Tez as the hive execution engine instead of MapReduce and then you can do a lot of further tweaks: see for example &lt;A href="https://community.hortonworks.com/content/kbentry/14309/demystify-tez-tuning-step-by-step.html"&gt;this article&lt;/A&gt; which provides some advice on tuning Tez.&lt;/P&gt;&lt;P&gt;I'll leave the thread open for others to comment further, but this will definitely get you started!&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 18:47:42 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141058#M27898</guid>
      <dc:creator>agillan</dc:creator>
      <dc:date>2016-05-11T18:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Lab3 PIG script to HIVE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141059#M27899</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/10376/vebs0205.html" nodeid="10376"&gt;@Vaibhav Yadav&lt;/A&gt;I think you can try collapsing the inner query as follows: &lt;/P&gt;&lt;PRE&gt; select driverid, count(event)  from geolocation where event!='normal' group by driverid; &lt;/PRE&gt;</description>
      <pubDate>Wed, 11 May 2016 21:16:26 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141059#M27899</guid>
      <dc:creator>grajagopal</dc:creator>
      <dc:date>2016-05-11T21:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Lab3 PIG script to HIVE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141060#M27900</link>
      <description>&lt;P&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/214/agillan.html" nodeid="214"&gt;@Ana Gillan&lt;/A&gt;.. I'll try that..&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 11:28:53 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141060#M27900</guid>
      <dc:creator>vebs0205</dc:creator>
      <dc:date>2016-05-12T11:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Lab3 PIG script to HIVE</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141061#M27901</link>
      <description>&lt;P style="margin-left: 40px;"&gt;Thanks &lt;A rel="user" href="https://community.cloudera.com/users/33/grajagopal.html" nodeid="33"&gt;@grajagopal&lt;/A&gt;. That just worked&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 11:29:47 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/Converting-Lab3-PIG-script-to-HIVE/m-p/141061#M27901</guid>
      <dc:creator>vebs0205</dc:creator>
      <dc:date>2016-05-12T11:29:47Z</dc:date>
    </item>
  </channel>
</rss>

