溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶(hù)服務(wù)條款》

hive中有哪些基礎(chǔ)執(zhí)行語(yǔ)句

發(fā)布時(shí)間:2021-12-10 10:19:26 來(lái)源:億速云 閱讀:106 作者:小新 欄目:云計(jì)算

小編給大家分享一下hive中有哪些基礎(chǔ)執(zhí)行語(yǔ)句,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!

hive簡(jiǎn)單概念

hive是一種基于Hadoop的數(shù)據(jù)倉(cāng)庫(kù)的處理工具,目前只支持簡(jiǎn)單的類(lèi)似傳統(tǒng)關(guān)系型數(shù)據(jù)庫(kù)的SQL查詢(xún),修改操作功能,他可以直接將SQL轉(zhuǎn)化為MapReduce程序,開(kāi)發(fā)人員不必一定要學(xué)會(huì)寫(xiě)MR程序,提高了開(kāi)發(fā)效率。

例子:基于mysql存儲(chǔ)的hive環(huán)境,hive元數(shù)據(jù)(hive相關(guān)表,表的各個(gè)字段屬性等信息)存放在mysql數(shù)據(jù)庫(kù)中,mysql數(shù)據(jù)存放在hdfs默認(rèn)是/user/hive/warehouse/hive.db中

ddl 語(yǔ)句

mysql作為元數(shù)據(jù)存儲(chǔ) 數(shù)據(jù)庫(kù)(hive)結(jié)構(gòu)目錄

創(chuàng)建表

hive> create table test (id int, name string);

引入分區(qū)的概念,因?yàn)閔ive 中的select 一般會(huì)掃描整個(gè)表,這樣會(huì)浪費(fèi)很多時(shí)間,所以引入分區(qū)的概念

hive> create table test2 (id int, name string) partitioned by (ds string);

瀏覽表

hive>show tables;

引入正則表達(dá)式 類(lèi)似like的功能

hive>show tables '.*t'

查看數(shù)據(jù)結(jié)構(gòu)

hive> DESCRIBE test;或desc test;

修改或刪除表

hive>alter table test rename to test3;

hive>alter table add columns (new_column type comment '注釋')

hive>drop table test;
DML操作語(yǔ)句

1、倒入數(shù)據(jù)

LOAD DATA LOCAL INPATH '/home/hadoop/test.txt' OVERWRITE INTO TABLE test;

local 表示執(zhí)行本地,如果去掉默認(rèn)是取hdfs上的文件,overwrite表示導(dǎo)入數(shù)據(jù)覆蓋,如果去掉表示append

2、執(zhí)行查詢(xún)

select * from test2 where test2.ds='2014-08-26'

3、值得注意的是 select count(*) from test 與我們平時(shí)關(guān)系型數(shù)據(jù)庫(kù)記錄查詢(xún)操作不同,他執(zhí)行的是一個(gè)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)

看完了這篇文章,相信你對(duì)“hive中有哪些基礎(chǔ)執(zhí)行語(yǔ)句”有了一定的了解,如果想了解更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI