title: How to execute hql files with multiple SQL queries per single file?
body: <p>I have hql file which have a lot of hive queries and I would like to execute the whole file using Spark SQL.</p>
  
  <p>This is what I have tried.</p>
  
  <pre><code>val sqlContext = new org.apache.spark.sql.hive.HiveContext(sc) 
  </code></pre>
  
  <p>Usually to execute individual queries we do it this way:  </p>
  
  <pre><code>sqlContext.sql("SELECT * from table")
  </code></pre>
  
  <p>However, when we have hql file with hundreds of queries, I use to do like this. </p>
  
  <pre><code>import scala.io.Source 
  
  val filename = "/path/to/file/filename.hql"
  for (line &lt;- Source.fromFile(filename).getLines) {
      sqlContext.sql(line)
  }
  </code></pre>
  
  <p>However, I get an error saying:</p>
  
  <pre><code>NoViableAltException
  </code></pre>
  
  <p>This is the top of the file.</p>
  
  <pre><code>DROP TABLE dat_app_12.12_app_htf;
  
  CREATE EXTERNAL TABLE dat_app_12.12_app_htf(stc string,
    ftg string,
    product_type string,
    prod_number string,
    prod_ident_number string,
    prod_family string,
    frst_reg_date date, gth_name string,
    address string,
    tel string,
    maker_name string) ROW format serde 'org.apache.hadoop.hive.ql.io.orc.OrcSerde'
  stored AS inputformat 'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat'
  outputformat 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat'
  LOCATION
    'file_location';
  </code></pre>
  
  <p>When the queries are multi-line queries like the above one, it doesn't work.
  However, when I format the queries and put all the lines into one line, it works. </p>
  
  <pre><code>CREATE EXTERNAL TABLE dat_app_12.12_app_htf(stc string, ftg string, product_type string, prod_number string, prod_ident_number string, prod_family string, frst_reg_date date, gth_name string, address string, tel string, maker_name string) ROW format serde 'org.apache.hadoop.hive.ql.io.orc.OrcSerde' stored AS inputformat 'org.apache.hadoop.hive.ql.io.orc.OrcInputFormat' outputformat 'org.apache.hadoop.hive.ql.io.orc.OrcOutputFormat' LOCATION 'file_location';
  </code></pre>
  
  <p>But I have thousands of lines like this. What is the proper way to do it.</p>
  
  <p>Can anyone help in getting this solved.</p>