使用registerTempTable注冊表是一個臨時表,生命周期只在所定義的sqlContext或hiveContext實例之中。換而言之,在一個sqlontext(或hiveContext)中registerTempTable的表不能在另一個sqlContext(或hiveContext)中使用。
而saveAsTable則是永久的,只要連接存在,spark再啟的時候,這個表還是在的。
官網上的描述:
Unlike theregisterTempTable command, saveAsTable will materialize the contents of the dataframe and create a pointer to the data in the HiveMetastore. Persistent tables will still exist even after your Spark program has restarted, as long as you maintain your connection to the same metastore. A DataFrame for a persistent table can be created by calling the table method on a SQLContext with the name of the table.
