使用在hdfs上的文件導入到hive中

hive要打開,另一邊root@hadoop-virtual-machine:/# hdfs dfs -ls /user/hive查看hdfs上都有些什麼,

然後把數據文件導入到hdfs上 ,root@hadoop-virtual-machine:/# hdfs dfs -put /opt/os.txt /user/hive/

hive那邊用show databases;查看當前都有什麼數據庫

然後創建表(此表是用來裝導入進來的數據的)

hive> create table os
    > (pathid string,nodeweight int,pathweight string,nodeid int,shutdown string)
    > ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' LINES TERMINATED BY '\n'
    > STORED AS TEXTFILE;

要保證創建的表的格式要和數據文件中的格式一樣,例如字段間的間隔符是什麼行與行間的間隔符都要進行限定,

導入數據 hive> load data inpath '/user/hive/os.txt' into table os;

hive> select * from os;
OK
["12->22"] 9638 [52] 12 false
["19->78"] 11895 [51] 19 true
["16->17"] 8608 [58] 16 true
["16->17"] 10240 [54] 16 false
["12->22"] 9638 [52] 12 true
["2->22","2->3"] 9638 [52,44] 2 true
["19->78"] 11895 [51] 19 false
["16->17"] 8608 [58] 16 false
["16->17"] 10240 [54] 16 true
["1->65"] 13271 [53] 1 true
["11->17","11->13"] 10383 [50,56] 11 false
["6->21","6->22","6->19","6->7","6->44","6->10","6->9","6->11"] 5398 [54,58,54,55,50,59,55,55] 6 false
["0->52","0->91","0->53"] 9814 [52,58,54] 0 true
["1->65"] 13271 [53] 1 false
["11->17","11->13"] 10383 [50,56] 11 true
["6->21","6->22","6->19","6->7","6->44","6->10","6->9","6->11"] 5398 [54,58,54,55,50,59,55,55] 6 true
["0->52","0->91","0->53"] 9814 [52,58,54] 0 false
Time taken: 0.114 seconds, Fetched: 17 row(s)

進來了

其實我在導入的時候下面顯示Loading data to table default.os
Failed with exception Unable to alter table. For direct MetaStore DB connections, we don't support retries at the client level.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.MoveTask

但是之後我想查看一下表中到底有沒有數據,數據是導入進來的,但是爲什麼低下有failed那幾行我也不太清楚,如果有知道的可以告訴我,學習知識大家互相討論互相進步嘛

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章