title: DISTRIBUTE BY clause in HIVE
body: <p>I am not able to understand what this <code>DISTRIBUTE BY</code> clause does in <strong>Hive</strong>. I know the definition that says, if we have <code>DISTRIBUTE BY (city)</code>, this would send each city in a different <strong>reducer</strong> but I am not getting the same. Let us consider the data as follows:</p>
  <p>Say we have a table called <em>data</em> with columns <em>username</em> and <em>amount</em>:</p>
  <pre><code>+----------+--------+
  | username | amount |
  +----------+--------+
  | user_1   | 25     |
  +----------+--------+
  | user_1   | 53     |
  +----------+--------+
  | user_1   | 28     |
  +----------+--------+
  | user_1   | 50     |
  +----------+--------+
  | user_2   | 20     |
  +----------+--------+
  | user_2   | 50     |
  +----------+--------+
  | user_2   | 10     |
  +----------+--------+
  | user_2   | 5      |
  +----------+--------+
  </code></pre>
  <p>Now If I say -</p>
  <pre><code>SELECT username, SUM(amount) FROM data DISTRIBUTE BY (username)
  </code></pre>
  <p>Shouldn't this run 2 separate reducers? It is still running a single reducer and I don't know why. I thought this may have to do with <strong>clustering into buckets</strong> or <strong>partitioning</strong> but I tried everything, and it still runs a single reducer. Can anyone explain why?</p>