<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: query hive tables with spark sql in Support Questions</title>
    <link>https://community.cloudera.com/t5/Support-Questions/query-hive-tables-with-spark-sql/m-p/145380#M107948</link>
    <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/3093/oscaricardo4.html" nodeid="3093"&gt;@Jan J&lt;/A&gt; &lt;/P&gt;&lt;P&gt;First you need to Create hive-site in the Spark conf directory:&lt;/P&gt;&lt;P&gt;As user root, create the file &lt;CODE&gt;SPARK_HOME/conf/hive-site.xml&lt;/CODE&gt;. Edit the file to contain only the following configuration setting:&lt;/P&gt;&lt;PRE&gt;&amp;lt;configuration&amp;gt;
  &amp;lt;property&amp;gt;
    &amp;lt;name&amp;gt;hive.metastore.uris&amp;lt;/name&amp;gt;
    &amp;lt;!--Make sure that &amp;lt;value&amp;gt; points to the Hive Metastore URI in your cluster --&amp;gt;
    &amp;lt;value&amp;gt;thrift://sandbox.hortonworks.com:9083&amp;lt;/value&amp;gt;
    &amp;lt;description&amp;gt;URI for client to contact metastore server&amp;lt;/description&amp;gt;
  &amp;lt;/property&amp;gt;
&amp;lt;/configuration&amp;gt;

&lt;/PRE&gt;&lt;H4&gt;Set SPARK_HOME&lt;/H4&gt;&lt;P&gt;If you haven’t already, make sure to set &lt;CODE&gt;SPARK_HOME&lt;/CODE&gt; before proceeding: &lt;/P&gt;&lt;P&gt;export SPARK_HOME=/usr/hdp/current/spark-client&lt;/P&gt;&lt;H4&gt;Create Hive Context&lt;/H4&gt;&lt;P&gt;At a &lt;CODE&gt;scala&amp;gt;&lt;/CODE&gt; REPL prompt type the following:&lt;/P&gt;&lt;PRE&gt;valhiveContext=neworg.apache.spark.sql.hive.HiveContext(sc)
&lt;/PRE&gt;&lt;H4&gt;Create Hive Table&lt;/H4&gt;&lt;PRE&gt;hiveContext.sql("CREATE TABLE IF NOT EXISTS TestTable (key INT, value STRING)")&lt;/PRE&gt;&lt;H4&gt;Load example KV value data into Table&lt;/H4&gt;&lt;PRE&gt;hiveContext.sql("LOAD DATA LOCAL INPATH 'examples/src/main/resources/kv1.txt' INTO TABLE TestTable")&lt;/PRE&gt;&lt;P&gt;scala&amp;gt; hiveCTX.hql("SHOW TABLES").collect().foreach(println) &lt;/P&gt;&lt;P&gt;scala&amp;gt;hCTX.hql("DESCRIBE raw_users").collect().foreach(println)&lt;/P&gt;</description>
    <pubDate>Tue, 29 Mar 2016 23:46:19 GMT</pubDate>
    <dc:creator>azeltov</dc:creator>
    <dc:date>2016-03-29T23:46:19Z</dc:date>
  </channel>
</rss>

