title: Hive bucketing is generating more files than expected, why?
body: <p>I have a partitioned and clustered hive table (using hive 1.2):</p>
  
  <pre><code>hive&gt; describe formatted myClusteredTable;
  # col_name              data_type              
  utc_timestamp           timestamp
  ...
  clusteredId             bigint
  
  # Partition Information
  # col_name              data_type        
  datePartition           string
  
  # Detailed Table Information
  Num Buckets:            100
  Bucket Columns:         [clusteredId]
  Sort Columns:           [Order(col:clusteredId, order:1), Order(col:utc_timestamp, order:1)]
  Storage Desc Params:
      serialization.format    1
  </code></pre>
  
  <p>And I insert data into it like this:</p>
  
  <pre><code>SET hive.enforce.bucketing=true;
  SET hive.enforce.sorting=true;
  INSERT OVERWRITE TABLE myClusteredTable  PARTITION (datePartition)
  SELECT   ...
   utcTimestamp,
   clusteredId,
   datePartition
  FROM (
    ... subquery ...
    ) subquery
  SORT BY datePartition, clusteredId, utcTimestamp;
  </code></pre>
  
  <p>I expect it to generate 100 files for each partition.
  Instead it is generating a lot more:</p>
  
  <pre><code>$ find /path/to/partition/dt=2017-01-01 -type f | wc -l
  1425
  $ find /path/to/partition/dt=2017-01-02 -type f | wc -l
  1419
  $ find /path/to/partition/dt=2017-01-03 -type f | wc -l
  1427
  </code></pre>
  
  <p>Please help me to understand why this might be happening and how I can avoid it.</p>