title: Hive percentile_approx function is broken, isn't it?
body: <ul>
  <li>I am using Hive 1.2.1000.2.4.2.0-258.  </li>
  <li>There are 4850000+ rows in the table, 14511 rows of A between 73 and 74, and 3 cols-  group_id,  A  and B.     </li>
  <li>Group_id is actually equal to 0.  </li>
  <li>Almost all of A and B are integers.</li>
  </ul>
  
  <p>I was using the following scripts to find statistic summaries from a table:</p>
  
  <pre><code>select group_id, --group_id=0 a constant
    percentile_approx(A , 0.5) as A_mdn, 
    percentile_approx(A , 0.25) as A_Q1, 
    percentile_approx(A , 0.75) as A_Q3, 
    percentile_approx(A , array(0.2,0.15, 0.1,0.05,0.025,0.001)) as A_i, 
    min(A) as min_A,
    percentile_approx(B , 0.5) as B_mdn, 
    percentile_approx(B , 0.25) as B_Q1, 
    percentile_approx(B , 0.75) as B_Q3, 
    percentile_approx(B , array(0.8,0.85, 0.9, 0.95,0.975)) as B_i
    from table
    group by group_id;
  </code></pre>
  
  <p>The result I got is:</p>
  
  <pre><code>0   
  73.21058033222496   
  73.21058033222496   
  462.16968382794516
  [73.21058033222496,73.21058033222496,73.21058033222496,73.21058033222496,73.21058033222496,73.21058033222496]   
  0.0 
  1.0 
  1.0 
  2.0  
  [2.0,3.0,4.0,8.11278644563614,17.0]
  </code></pre>
  
  <p>Then I change the code as following:</p>
  
  <pre><code>select group_id, --group_id=0 a constant
    percentile(cast(A as bigint), 0.5) as A_mdn, 
    percentile(cast(A as bigint), 0.25) as A_Q1, 
    percentile(cast(A as bigint), 0.75) as A_Q3, 
    percentile(cast(A as bigint), array(0.2,0.15, 0.1,0.05,0.025,0.001)) as A_i, 
    min(A) as min_A,
    percentile(cast(B as bigint), 0.5) as B_mdn, 
    percentile(cast(B as bigint), 0.25) as B_Q1, 
    percentile(cast(B as bigint), 0.75) as B_Q3, 
    percentile(cast(B as bigint), array(0.8,0.85, 0.9, 0.95,0.975)) as B_i
    from table
    group by group_id
  </code></pre>
  
  <p>The new result is:</p>
  
  <pre><code> 0  
  72.0    
  6.0 
  762.0    
  [3.0,1.0,1.0,0.0,0.0,0.0]
  0.0
  1.0 
  1.0 
  2.0  
  [2.0,3.0,4.0,9.0,17.0]
  </code></pre>
  
  <p>To double check the truth, I also load this table to R. Following is the R-result:</p>
  
  <pre><code>A:
  Min 0
  Q1: 6
  Median: 72
  Q3: 762
  0.2 quantile:  3
  0.15 quantile: 1.5
  0.1 quantile:  1
  0.05 quantile: 0
  0.025 quantile:0
  0.001 quantile:0
  
  B
  Q1: 1
  Median: 1
  Q3: 2
  0.8 quantile:  2    
  0.85 quantile: 3
  0.9 quantile:  4
  0.95 quantile: 9
  0.975 quantile:17
  </code></pre>
  
  <p>Obviously, R result is consistent with percentile function, but percentile_approx gives me the wrong answer. </p>