hive資料操作

來源:互聯網
上載者:User

標籤:streaming   表示   本地   border   語言   匯入資料   alter   order   儲存   

mdl是資料操作類的語言,包括向資料表負載檔案,寫查詢結果等操作

hive有四種匯入資料的方式
》從本地載入資料 LOAD DATA LOCAL INPATH ‘./examples/files/kv1.txt‘ OVERWRITE INTO TABLE [tableName];》從hdfs上載入資料 load data inpath ‘hdfs://192.168.177.124:9000/opt/hive/warehouse/student.txt‘》從其他表中查出資料並載入到其他表中 insert overwrite table student_1 partition(ds=‘20161219‘,country =‘B eiJing‘) select studentid,sex,address,email from student_3 where ad dress=‘BeiJing‘;》建立表的時候從其他表中查出資料
向表中負載檔案當資料載入到表裡的時候不會對資料進行任何轉換,只是單純的複製/移動 到hive表對應的位置  從本地檔案載入到表
hive> LOAD DATA LOCAL INPATH ‘./examples/files/kv1.txt‘ OVERWRITE INTO TABLE [tableName];
local:表示從本地負載檔案(想從hdfs中負載檔案,則不適用locall)inPath:要負載檔案的位置(可以是絕對路徑或者相對路徑,相對路徑會從預設目前使用者下的相對路徑)overwrite:覆蓋表中的資料,如果沒有overwrite則會在表中資料的後面追加資料tableName:要載入的表名載入的目標可以是一個表或者是一個分區,如果表中含有分區的話則必須指定每個分區的分區名。可以應用一個檔案(hive會將檔案移動到表所對應的目錄中)或者一個目錄 向分區表中添加資料(將查詢的結果寫入檔案系統)(1)通常情況下需要預先建立好該分區,才能使用
alter table student_1 add partition (ds=‘20161219‘,country =‘BeiJing‘);
hdfs上會建立給相應的檔案目錄
/opt/hive/warehouse/student_1/ds=20161219/country=BeiJing

(2)插入sql(可以向表/分區中寫入多條資料寫入多條資料)hive> insert overwrite table student_1 partition(ds=‘20161219‘,country =‘BeiJing‘) select studentid,sex,address,email from student_3 where address=‘BeiJing‘;插入成功 從hdfs上匯出資料到hive表中
load data inpath ‘hdfs://192.168.177.124:9000/opt/hive/warehouse/student.txt‘into table tableNamepartition (address=‘BeiJing‘);
可以使用Regex
select ‘(name|age)?+‘ form [tableName]
 基於分區查詢select 是對全表進行掃描,如果建立表中有parttion by語句,可以對查詢的語句進行剪枝,hive現在只對在where分區中的欄位進行掃描
select*from tableName where address=‘BeiJing‘
hive目前不支援having,可以子查詢來完成hive有很多文法都跟sql類似,比如group by ,join,having,多表insert,streaming 刪除表資料
truncate table tableName;
刪除hive中的表
drop table tableName;
刪除表中的特定行
delete from tableName t where t....
hive執行檔案中的sql(Hive可以運行儲存在檔案裡面的一條或多條的語句,只要用-f參數)
bin/hive -f [檔案名稱] //這種是沒有進入hive命令列文法

一般檔案的名稱尾碼是‘.hsql 或者.q‘

source [檔案名稱]; 例:source /home/wyp/Documents/test;//進入hive命令列後的文法
 

hive資料操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.