title: Last few mappers with skew data set taking long time to run on groupby hive map reduce
body: <p>I am running a simple groupby query as shown below on dataset size 3.5 TB. I know there is skew in my dataset.  The "partno" column is contributing 95% of dataset, because of this the entire job is taking 9 hrs to complete and last few mappers take the longest time of all.</p>
  
  <p>Can you please help me with this, I need to optimize this to efficiently. Basically I need help to tackle skew data in terms of groupby and join.</p>
  
  <pre><code>select cntry,partno
  percentile_approx(part_pr,0.999) as part_pr_cutoff
  from sourceTable 
  GROUP BY cntry,partno;
  </code></pre>
  
  <p>Below are the hive.properties I am using in the hql files.</p>
  
  <pre><code>SET hive.exec.compress.intermediate=true;
  SET hive.intermediate.compression.codec=org.apache.hadoop.io.compress.SnappyCodec;
  SET hive.intermediate.compression.type=BLOCK;
  SET hive.exec.compress.output=true;
  SET mapreduce.output.fileoutputformat.compress=true;
  SET mapreduce.output.fileoutputformat.compress.codec=org.apache.hadoop.io.compress.SnappyCodec;
  SET mapreduce.output.fileoutputformat.compress.type=BLOCK;
  SET hive.auto.convert.join=true;
  SET hive.auto.convert.join.noconditionaltask=true;
  SET hive.auto.convert.join.noconditionaltask.size=10000000;
  SET hive.groupby.skewindata=true;
  SET hive.optimize.skewjoin.compiletime=true;
  SET hive.optimize.skewjoin=true;
  SET hive.optimize.bucketmapjoin=true;
  SET hive.exec.parallel=true;
  SET hive.cbo.enable=true;
  SET hive.stats.autogather=true;
  SET hive.compute.query.using.stats=true;
  SET hive.stats.fetch.column.stats=true;
  SET hive.stats.fetch.partition.stats=true;
  SET hive.vectorized.execution.enabled=true;
  SET hive.vectorized.execution.reduce.enabled=true;
  SET hive.optimize.index.filter=true;
  SET hive.optimize.ppd=true;
  SET hive.mapjoin.smalltable.filesize=25000000;
  SET hive.exec.dynamic.partition=true;
  SET hive.exec.dynamic.partition.mode=nonstrict;
  SET hive.exec.max.dynamic.partitions.pernode=1000;
  SET mapreduce.reduce.memory.mb=10240;
  SET mapreduce.reduce.java.opts=-Xmx9216m;
  SET mapreduce.map.memory.mb=10240;
  SET mapreduce.map.java.opts=-Xmx9216m;
  SET mapreduce.task.io.sort.mb=1536;
  SET hive.optimize.groupby=true;
  SET hive.groupby.orderby.position.alias=true;
  SET hive.multigroupby.singlereducer=true;
  SET hive.optimize.point.lookup=true;
  SET hive.optimize.point.lookup.min=true;
  SET hive.merge.mapfiles=true;
  SET hive.merge.smallfiles.avgsize=128000000;
  SET hive.merge.size.per.task=268435456;
  SET hive.map.aggr=true;
  SET hive.optimize.distinct.rewrite=true;
  SET mapreduce.map.speculative=false;
  set hive.fetch.task.conversion = more;
  set hive.fetch.task.aggr=true;
  set hive.fetch.task.conversion.threshold=1024000000;
  </code></pre>