<?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: spark-submit and hive tables - 'Table not found' in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116866#M47001</link>
    <description>&lt;P&gt;Great! Thanks.&lt;/P&gt;</description>
    <pubDate>Wed, 23 Nov 2016 01:51:58 GMT</pubDate>
    <dc:creator>fernando_lopez</dc:creator>
    <dc:date>2016-11-23T01:51:58Z</dc:date>
    <item>
      <title>spark-submit and hive tables - 'Table not found'</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116863#M46998</link>
      <description>&lt;P&gt;I need to submit a Python process which uses Spark. This process needs to access Hive tables, but is unable to find them.&lt;/P&gt;&lt;P&gt;In order to schedule the process tu run, we use spark-submit, eg:&lt;/P&gt;&lt;PRE&gt;spark-submit pyspark_helloworld.py&lt;/PRE&gt;&lt;P&gt;This is the code (first 5 lines were added in order to run the process from outside pyspark command line, this is, via spark-submit):&lt;/P&gt;&lt;PRE&gt;from pyspark import SparkConf, SparkContext
from pyspark.sql import SQLContext
conf1 = SparkConf().setAppName("hellospark")
sc1 = SparkContext(conf=conf1)
sqlCtx = SQLContext(sc1)

print("Hello spark")
documents = sqlCtx.sql("SELECT count(*) as cnt FROM ext_contents")
print "Number of documents found:"
for content in documents.collect():
    print content.cnt


&lt;/PRE&gt;&lt;P&gt;And this is the output:&lt;/P&gt;&lt;PRE&gt;Hello spark 

Traceback (most recent call last):   

File "/home/bigdataquanam/pyspark_helloworld.py", line 10, in &amp;lt;module&amp;gt;
    documents = sqlCtx.sql("SELECT count(*) as cnt FROM ext_contents")   

File "/usr/hdp/2.4.2.0-258/spark/python/lib/pyspark.zip/pyspark/sql/context.py", line 580, in sql   

File "/usr/hdp/2.4.2.0-258/spark/python/lib/py4j-0.9-src.zip/py4j/java_gateway.py", line 813, in __call__   

File "/usr/hdp/2.4.2.0-258/spark/python/lib/pyspark.zip/pyspark/sql/utils.py", line 51, in deco
pyspark.sql.utils.AnalysisException: u'Table not found: ext_contents;' 

INFO SparkContext: Invoking stop() from shutdown hook&lt;/PRE&gt;&lt;P style="margin-left: 20px;"&gt;&lt;/P&gt;&lt;P style="margin-left: 20px;"&gt;&lt;/P&gt;&lt;P&gt;Any ideas? Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 01:22:35 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116863#M46998</guid>
      <dc:creator>fernando_lopez</dc:creator>
      <dc:date>2016-11-23T01:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: spark-submit and hive tables - 'Table not found'</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116864#M46999</link>
      <description>&lt;P&gt;You should use HiveContext, see &lt;A href="https://spark.apache.org/docs/1.6.1/sql-programming-guide.html#hive-tables" target="_blank"&gt;https://spark.apache.org/docs/1.6.1/sql-programming-guide.html#hive-tables&lt;/A&gt;&lt;/P&gt;&lt;PRE&gt;from pyspark.sql import HiveContext
sqlContext = HiveContext(sc1)&lt;/PRE&gt;&lt;P&gt;and then you can test access to your table. &lt;/P&gt;&lt;P&gt;Also try &lt;/P&gt;&lt;PRE&gt;sqlContext.sql("show databases").show()
sqlContext.sql("show tables").show()&lt;/PRE&gt;&lt;P&gt;to see what you can acccess&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 01:45:25 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116864#M46999</guid>
      <dc:creator>bwalter1</dc:creator>
      <dc:date>2016-11-23T01:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: spark-submit and hive tables - 'Table not found'</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116865#M47000</link>
      <description>&lt;A rel="user" href="https://community.cloudera.com/users/12839/fernandolopez.html" nodeid="12839"&gt;@Fernando Lopez Bello&lt;/A&gt;&lt;P&gt;You need to have a hivecontext to access hive tables.&lt;/P&gt;&lt;PRE&gt;from pyspark.sql import HiveContext 
sqlCtx = HiveContext(sc1)
&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 01:51:49 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116865#M47000</guid>
      <dc:creator>sandyy006</dc:creator>
      <dc:date>2016-11-23T01:51:49Z</dc:date>
    </item>
    <item>
      <title>Re: spark-submit and hive tables - 'Table not found'</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116866#M47001</link>
      <description>&lt;P&gt;Great! Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 01:51:58 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/spark-submit-and-hive-tables-Table-not-found/m-p/116866#M47001</guid>
      <dc:creator>fernando_lopez</dc:creator>
      <dc:date>2016-11-23T01:51:58Z</dc:date>
    </item>
  </channel>
</rss>

