Looping using Hiveql
<p>I'm trying to merge 2 datasets, say A and B. The dataset A has a variable "Flag" which takes 2 values. Rather than jut merging both data together I was trying to merge 2 datasets based on "flag" variable. </p>

<p>The merging code is the following:</p>

<pre><code>create table new_data as
select a.*,b.y
from A as a left join B as b
on a.x=b.x
</code></pre>

<p>Since I'm running Hive code through CLI, I'm calling this through the following command</p>

<pre><code>hive -f new_data.hql
</code></pre>

<p>The looping part of the code I'm calling to merge data based on "Flag" variable is the following:</p>

<pre><code>for flag in 1 2;
do
  hive -hivevar flag=$flag -f new_data.hql
done
</code></pre>

<p>I put the above code in another ".hql" file asn calling it:</p>

<pre><code>hive -f loop_data.hql
</code></pre>

<p>But it's throwing error.</p>

<blockquote>
  <p>cannot recognize input near 'for' 'flag' 'in'</p>
</blockquote>

<p>Can anybody please tell me where I'm making mistake.</p>

<p>Thanks!</p>