spark使用Hive表操作

2021-07-05 11:39:05 字數 533 閱讀 1247

之前很長一段時間是通過hiveserver操作hive表的,一旦hiveserver宕掉就無法進行操作。

比如說乙個修改表分割槽的操作

val tblname = "hive_table"

defdroppartitions

(tblname: string): unit =

後來發現通過hivecontext可以實現同樣的功能,卻方便的多,也不用通過hiveserver,再也不怕hiveserver宕機啦~

先建立乙個hivecontext,當然hivecontext也是可以對hive表進行查詢操作的

val sqlcontext = new hivecontext(sc)
同樣功能的函式

val tblname = "hive_table"

defdroppartitions

(tblname: string,sqlcontext :hivecontext): unit =

Spark 操作hive實戰練習

比如 user3,已經有了5月5號的訂單 不公開 來評測模型的 我們有的是5月4號之前的歷史資料 我們需要 通過歷史 5月4號之前訂單資料 這個使用者5月5號買了什麼 1 資料準備 a 在hive中建立orders訂單外部表 b 在hive中建立products商品外部表 c 在hive中建立pri...

Hive操作表分割槽

建立分割槽表語句,使用關鍵字partition a 單分割槽建表語句 create table table name id int,content string partitioned by dt string 單分割槽表,按天分割槽,在表結構增加了dt列。以dt為資料夾區分 b 雙分割槽建表語句 ...

常用Hive表操作

一 hive建表語句 create table if not exists test id int,name string,age int 預設底層儲存為文字檔案,且為預設分隔符 create table if not exists test id int,name string,age int r...