Spark 讀寫hive 表


spark 讀寫hive表主要是通過sparkssSession

讀表的時候,很簡單,直接像寫sql一樣sparkSession.sql("select * from xx") 就可以了。

 

這里主要是寫數據,因為數據格式有很多類型,比如orc,parquet 等,這里就需要按需要的格式寫數據。

首先 , 對於特殊的格式這里就要制定

   dataFrame.write.format("orc")的方式。

其次, 對於寫入分區表有2種方式,insertInto 和saveAsTable,

  a)  insertInto 不需要制定分區 ,分區應該是你創建表的時候已經寫明了的。

  insertInto() can't be used together with partitionBy().Partition columns have already be defined for the table. It is not necessary to use partitionBy().

  b) saveAsTable 拋異常: 提示你用 insertInto, 忘了把日志保存了。暫時記着吧。

   

類似問題:

http://blog.csdn.net/lc0817/article/details/78211695?utm_source=debugrun&utm_medium=referral

https://stackoverflow.com/questions/32362206/spark-dataframe-saveastable-with-partitionby-creates-no-orc-file-in-hdfs

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM