title: Accessing Spark SQL RDD tables through the Thrift Server
body: <p>I have registered a temporary table with Spark SQL, as described in <a href="https://spark.apache.org/docs/1.1.0/sql-programming-guide.html#inferring-the-schema-using-reflection">[this section]</a>:</p>
  
  <pre><code>people.registerTempTable("people")
  // I can run queries on it all right.
  val teenagers = sqlContext.sql("SELECT name FROM people WHERE age &gt;= 13 AND age &lt;= 19")
  </code></pre>
  
  <p>Now I want to access this table remotely through JDBC. I start up the Thrift Server as described in <a href="https://spark.apache.org/docs/1.1.0/sql-programming-guide.html#running-the-thrift-jdbc-server">[this other section]</a>.</p>
  
  <pre><code>./sbin/start-thriftserver.sh --master spark://same-master-as-above:7077
  </code></pre>
  
  <p>But the table is not visible.</p>
  
  <pre><code>0: jdbc:hive2://localhost:10000&gt; show tables;         
  +---------+
  | result  |
  +---------+
  +---------+
  No rows selected (2.216 seconds)
  </code></pre>
  
  <p>I guess this is because the table is "temporary" (i.e. tied to the lifetime of the <code>SqlContext</code> object). But how do I make non-temporary tables?</p>
  
  <p>I can see <a href="https://spark.apache.org/docs/1.1.0/sql-programming-guide.html#hive-tables">Hive tables</a> through the Thrift Server, but I don't see how I could expose an RDD like this. I've found <a href="https://github.com/apache/spark/blob/42389b1780311d90499b4ce2315ceabf5b6ab384/sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveMetastoreCatalog.scala#L309">a comment</a> that suggests I cannot.</p>
  
  <p>Or should I run the Thrift Server in my application with my own <code>SqlContext</code>? Almost all classes around it are <code>private</code>, and this code is not in Maven Central (as far as I see). Am I supposed to use <code>HiveThriftServer2.startWithContext</code>? It's undocumented and <code>@DeveloperApi</code>, but might work.</p>