<?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: I can't find my tables in Spark SQL using Beeline in Archives of Support Questions (Read Only)</title>
    <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113022#M26023</link>
    <description>&lt;P&gt;This is set up by default on the HDP sandbox. See reply above.&lt;/P&gt;</description>
    <pubDate>Mon, 25 Apr 2016 22:08:57 GMT</pubDate>
    <dc:creator>adam_doyle</dc:creator>
    <dc:date>2016-04-25T22:08:57Z</dc:date>
    <item>
      <title>I can't find my tables in Spark SQL using Beeline</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113017#M26018</link>
      <description>&lt;P&gt;I'm using the latest HDP (2.4) Sandbox. I have a class that attempts to establish a HiveThriftServer and write a table called cumulativeVitals. When I go to look for the table using Beeline, I can't find it.&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;PRE&gt;package stlhug.streaming;


import java.util.ArrayList;
import java.sql.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;


import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;


import org.apache.spark.sql.DataFrame;
import org.apache.spark.sql.hive.HiveContext;
import org.apache.spark.sql.hive.thriftserver.HiveThriftServer2;
import org.apache.spark.streaming.Durations;
import org.apache.spark.streaming.api.java.JavaDStream;
import org.apache.spark.streaming.api.java.JavaPairReceiverInputDStream;
import org.apache.spark.streaming.api.java.JavaStreamingContext;
import org.apache.spark.streaming.kafka.KafkaUtils;
import stlhug.domain.VitalRecord;
import stlhug.streaming.function.ConvertStreamToDataFrame;
import stlhug.streaming.function.MapMessageToVital;


public class PatientVitalStream2 {


	@SuppressWarnings("deprecation")
	public static void main(String[] args) {


		String zkQuorum = args[1];
		String kafkaConsumerGroupId = args[2];


		SparkConf conf = new SparkConf().setMaster("local[2]").setAppName("PatientVitals");
		JavaStreamingContext jssc = new JavaStreamingContext(conf, Durations.seconds(1));
		


		HiveContext sqlContext = new HiveContext(jssc.sparkContext().sc());
		sqlContext.setConf("hive.server2.thrift.port", "10001");
		
		
		initializeTable(jssc, sqlContext, "cumulativeVitals");
		sqlContext.sql("select * from cumulativeVitals").show();


		Map&amp;lt;String, Integer&amp;gt; map = new HashMap&amp;lt;String, Integer&amp;gt;();
		map.put("patientVitals", 1);
		JavaPairReceiverInputDStream&amp;lt;String, String&amp;gt; kafkaStream = KafkaUtils.createStream(jssc, zkQuorum,
				kafkaConsumerGroupId, map);


		JavaDStream&amp;lt;VitalRecord&amp;gt; vitals = kafkaStream.map(new MapMessageToVital());


		vitals.foreach(new ConvertStreamToDataFrame("cumulativeVitals"));
		
		HiveThriftServer2.startWithContext(sqlContext);
		jssc.start();
		jssc.awaitTermination();
	}


	//TODO: &lt;A href="http://stackoverflow.com/questions/32362206/spark-dataframe-saveastable-with-partitionby-creates-no-orc-file-in-hdfs" target="_blank"&gt;http://stackoverflow.com/questions/32362206/spark-dataframe-saveastable-with-partitionby-creates-no-orc-file-in-hdfs&lt;/A&gt;
	@SuppressWarnings("deprecation")
	private static void initializeTable(JavaStreamingContext jssc, HiveContext sqlContext, String tableName) {
		List&amp;lt;VitalRecord&amp;gt; records = new ArrayList&amp;lt;VitalRecord&amp;gt;();
		VitalRecord record = new VitalRecord(0, new Date(new java.util.Date().getTime()), 0,0,0,0);
		records.add(record);
		JavaRDD&amp;lt;VitalRecord&amp;gt; recordRDD = jssc.sparkContext().parallelize(records);
		DataFrame recordDF = sqlContext.createDataFrame(recordRDD, VitalRecord.class);
		recordDF.registerTempTable(tableName);
//		String fileName = "/home/"+new Random().nextInt(20000);
//		recordDF.saveAsParquetFile(fileName);
//		DataFrame parquetFile = sqlContext.parquetFile(fileName);
//		sqlContext.registerDataFrameAsTable(parquetFile, tableName);
		
	}


}



&lt;/PRE&gt;&lt;P&gt;Start Beeline. Connect to Database:&lt;/P&gt;&lt;PRE&gt;[root@sandbox spark-client]# pwd
/usr/hdp/current/spark-client
[root@sandbox spark-client]# ./bin/beeline
Beeline version 1.6.0.2.4.0.0-169 by Apache Hive
beeline&amp;gt; !connect jdbc:hive2://localhost:10001
Connecting to jdbc:hive2://localhost:10001
Enter username for jdbc:hive2://localhost:10001: root
Enter password for jdbc:hive2://localhost:10001: **********
16/04/22 22:19:10 INFO Utils: Supplied authorities: localhost:10001
16/04/22 22:19:10 INFO Utils: Resolved authority: localhost:10001
16/04/22 22:19:10 INFO HiveConnection: Will try to open client transport with JDBC Uri: jdbc:hive2://localhost:10001
Connected to: Spark SQL (version 1.6.0)
Driver: Spark Project Core (version 1.6.0.2.4.0.0-169)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10001&amp;gt; show tables;
+------------+--------------+--+
| tableName  | isTemporary  |
+------------+--------------+--+
| sample_07  | false        |
| sample_08  | false        |
+------------+--------------+--+
2 rows selected (0.305 seconds)
0: jdbc:hive2://localhost:10001&amp;gt; 

&lt;/PRE&gt;</description>
      <pubDate>Sat, 23 Apr 2016 05:26:13 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113017#M26018</guid>
      <dc:creator>adam_doyle</dc:creator>
      <dc:date>2016-04-23T05:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: I can't find my tables in Spark SQL using Beeline</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113018#M26019</link>
      <description>&lt;P&gt;If you create a table via Spark/Beeline and you can see that table, but not the table that exist within Hive, that typically means Spark isn't configured to use Hive metastore. &lt;/P&gt;&lt;P&gt;Pl see &lt;A href="http://hortonworks.com/hadoop-tutorial/a-lap-around-apache-spark/"&gt;this&lt;/A&gt; and can you verify that there is a hive-site.xml under spark/conf and it pointing to right host, port corresponding to Hive Meta store.&lt;/P&gt;</description>
      <pubDate>Sat, 23 Apr 2016 07:13:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113018#M26019</guid>
      <dc:creator>vshukla</dc:creator>
      <dc:date>2016-04-23T07:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: I can't find my tables in Spark SQL using Beeline</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113019#M26020</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://community.cloudera.com/users/690/adamdoyle.html" nodeid="690"&gt;@Adam Doyle&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In Spark 1.6, by default the Thrift server runs in multi-session mode. Which means each JDBC/ODBC connection owns a copy of their own SQL configuration and temporary function registry. Cached tables are still shared. You are registering a temp table and so in order to see the temp table, you need to run the Thrift server in single-session mode. In spark-default.conf set spark.sql.hive.thriftServer.singleSession to true. When you call for an instance of the Thrift server in you code, it should start up in single session mode. When you initialize and register the temp table, it should show up when you connect and issue show tables command. You can create a permanent table in which case it should show up in multi session mode and from Hive (You have the code to do that but it's commented out).&lt;/P&gt;</description>
      <pubDate>Sun, 24 Apr 2016 00:57:01 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113019#M26020</guid>
      <dc:creator>vvaks</dc:creator>
      <dc:date>2016-04-24T00:57:01Z</dc:date>
    </item>
    <item>
      <title>Re: I can't find my tables in Spark SQL using Beeline</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113020#M26021</link>
      <description>&lt;P&gt;You need to have hive-site.xml with HMS(hive metastore service) properties under your SPARK_CONF_DIR&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 13:35:39 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113020#M26021</guid>
      <dc:creator>nyadav</dc:creator>
      <dc:date>2016-04-25T13:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: I can't find my tables in Spark SQL using Beeline</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113021#M26022</link>
      <description>&lt;P&gt;Under /usr/hdp/current/spark-client/conf on the sandbox:&lt;/P&gt;&lt;PRE&gt;[root@sandbox conf]# cat hive-site.xml 
  &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;value&amp;gt;thrift://sandbox.hortonworks.com:9083&amp;lt;/value&amp;gt; 
    &amp;lt;/property&amp;gt; 
  &amp;lt;/configuration&amp;gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 25 Apr 2016 22:07:27 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113021#M26022</guid>
      <dc:creator>adam_doyle</dc:creator>
      <dc:date>2016-04-25T22:07:27Z</dc:date>
    </item>
    <item>
      <title>Re: I can't find my tables in Spark SQL using Beeline</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113022#M26023</link>
      <description>&lt;P&gt;This is set up by default on the HDP sandbox. See reply above.&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 22:08:57 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113022#M26023</guid>
      <dc:creator>adam_doyle</dc:creator>
      <dc:date>2016-04-25T22:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: I can't find my tables in Spark SQL using Beeline</title>
      <link>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113023#M26024</link>
      <description>&lt;P&gt;This wasn't set up for me by default. It also wasn't mentioned in any of the documentation that I've reviewed. &lt;/P&gt;&lt;P&gt;Thanks for the help!&lt;/P&gt;</description>
      <pubDate>Mon, 25 Apr 2016 22:14:36 GMT</pubDate>
      <guid>https://community.cloudera.com/t5/Archives-of-Support-Questions/I-can-t-find-my-tables-in-Spark-SQL-using-Beeline/m-p/113023#M26024</guid>
      <dc:creator>adam_doyle</dc:creator>
      <dc:date>2016-04-25T22:14:36Z</dc:date>
    </item>
  </channel>
</rss>

