安慶網(wǎng)站設(shè)計百度拍照搜索
目錄
- idea/dg遠程連接
- 導入數(shù)據(jù)
- 建表
- 數(shù)據(jù)導入
idea/dg遠程連接
hive的詳細安裝不多展示,自行搜索即可。
依次啟動zookeeper,hadoop
在zookeeper的節(jié)點上啟動如下指令(我的是1個主節(jié)點和2個備用節(jié)點)
啟動Hive的metastore(存儲和管理元數(shù)據(jù)的服務(wù))和hiveserver2(遠程連接服務(wù))
nohup hive --service metastore > /root/training/apache-hive-3.1.3-bin/logs/metastore.log 2>&1 &
nohup hive --service hiveserver2 > /root/training/apache-hive-3.1.3-bin/logs/hiveserver2.log 2>&1 &
遠程連接方面,以idea為例(datagrip在idea有集成)
注意下端口和用戶即可,其他的沒什么特別需要注意的地方。
報錯
[08S01][1] Error while processing statement: FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Got exception: org.apache.hadoop.security.AccessControlException Permission denied: user=anonymous, access=WRITE, inode=“/user/hive/warehouse”:root:supergroup:drwxr-xr-x at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:506) at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:346) at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermissionWithContext(FSPermissionChecker.java:3 …
連接完成后敲代碼,遇到這樣的錯誤表明:當前用戶操作的hdfs目錄(hdfs中的hive目錄)權(quán)限不夠
我這里是匿名用戶,沒有寫的權(quán)限,因此需要修改
解決
在虛擬機上修改hadoop中的warehouse目錄下的權(quán)限,這也是hive的目錄
這個目錄修改為你自己的即可,具體看報錯內(nèi)容
hdfs dfs -chmod 777 /user/hive/warehouse
導入數(shù)據(jù)
自己建立一個csv文件(數(shù)據(jù)描述)
由于虛擬機大小限制,自己重新做了個。
關(guān)于csv文件自行編寫即可
建表
創(chuàng)建表user_log和user_info。
create table user_info(id int comment "唯一表示id",age_range int comment "年齡范圍",gender int comment "性別 0女 1男 2保密"
)
row format delimited
fields terminated by ","
lines terminated by "\n";create table user_log(user_id int comment "買家id",item_id int comment "產(chǎn)品id",cat_id int comment "分類id",seller_id int comment "賣家id",brand_id int comment "品牌id",time_stamp bigint comment "時間戳",action_type int
)
row format delimited
fields terminated by ","
lines terminated by "\n";
數(shù)據(jù)導入
值得說明的是,csv文件首行(列名描述)應(yīng)當刪去,不然導入數(shù)據(jù)時會出現(xiàn)首行因數(shù)據(jù)類型不一致而出現(xiàn)空的情況
上傳數(shù)據(jù)至hive中(用hive的客戶端)
load data local inpath '/root/tools/user_log.csv' into table user_log;
load data local inpath '/root/tools/user_info.csv' into table user_info;