您好,登錄后才能下訂單哦!
小編給大家分享一下hive中有哪些基礎執行語句,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
hive是一種基于Hadoop的數據倉庫的處理工具,目前只支持簡單的類似傳統關系型數據庫的SQL查詢,修改操作功能,他可以直接將SQL轉化為MapReduce程序,開發人員不必一定要學會寫MR程序,提高了開發效率。
例子:基于mysql存儲的hive環境,hive元數據(hive相關表,表的各個字段屬性等信息)存放在mysql數據庫中,mysql數據存放在hdfs默認是/user/hive/warehouse/hive.db中
mysql作為元數據存儲 數據庫(hive)結構目錄
創建表
hive> create table test (id int, name string);
引入分區的概念,因為hive 中的select 一般會掃描整個表,這樣會浪費很多時間,所以引入分區的概念
hive> create table test2 (id int, name string) partitioned by (ds string);
瀏覽表
hive>show tables;
引入正則表達式 類似like的功能
hive>show tables '.*t'
查看數據結構
hive> DESCRIBE test;或desc test;
修改或刪除表
hive>alter table test rename to test3;
hive>alter table add columns (new_column type comment '注釋')
1、倒入數據
LOAD DATA LOCAL INPATH '/home/hadoop/test.txt' OVERWRITE INTO TABLE test;
local 表示執行本地,如果去掉默認是取hdfs上的文件,overwrite表示導入數據覆蓋,如果去掉表示append
2、執行查詢
select * from test2 where test2.ds='2014-08-26'
3、值得注意的是 select count(*) from test 與我們平時關系型數據庫記錄查詢操作不同,他執行的是一個mr
hive> select count(*) from test2;
Total MapReduce jobs = 1
Launching Job 1 out of 1
Number of reduce tasks determined at compile time: 1
In order to change the average load for a reducer (in bytes):
set hive.exec.reducers.bytes.per.reducer=<number>
In order to limit the maximum number of reducers:
set hive.exec.reducers.max=<number>
In order to set a constant number of reducers:
set mapred.reduce.tasks=<number>
Starting Job = job_1411720827309_0004, Tracking URL = http://master:8031/proxy/application_1411720827309_0004/
Kill Command = /usr/local/cloud/hadoop/bin/hadoop job -kill job_1411720827309_0004
Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1
Stage-1 map = 0%, reduce = 0%
Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.93 sec
Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.93 sec
Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.93 sec
Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.93 sec
Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.93 sec
Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.93 sec
Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.93 sec
Stage-1 map = 100%, reduce = 0%, Cumulative CPU 0.93 sec
Stage-1 map = 100%, reduce = 100%, Cumulative CPU 2.3 sec
Stage-1 map = 100%, reduce = 100%, Cumulative CPU 2.3 sec
MapReduce Total cumulative CPU time: 2 seconds 300 msec
Ended Job = job_1411720827309_0004
MapReduce Jobs Launched:
Job 0: Map: 1 Reduce: 1 Cumulative CPU: 2.3 sec HDFS Read: 245 HDFS Write: 2 SUCCESS
Total MapReduce CPU Time Spent: 2 seconds 300 msec
OK
3
Time taken: 27.508 seconds, Fetched: 1 row(s)
看完了這篇文章,相信你對“hive中有哪些基礎執行語句”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。