近日學習hive過程中,其基本操作與mysql類似,不做贅述;特別的,針對一些hive中的建表命令進行了整理。
//建立表,external 外部表
$hive>create external table if not exists t2(id int,name string,age int) comment 'xx' row format delimited fields terminated by ',' stored as textfile ;
//檢視表資料
$hive>desc t2 ;
$hive>desc formatted t2 ;
//載入資料到hive表
$hive>load data local inpath '/home/***/customers.txt' into table t2 ; //local上傳檔案
$hive>load data inpath '/user/***/customers.txt' [overwrite] into table t2 ; //移動檔案
//複製表
mysql>create table tt as select * from users ; //攜帶資料和表結構
mysql>create table tt like users ; //不帶資料,只有表結構
hive>create table tt as select * from users ;
hive>create table tt like users ;
//count()查詢要轉成mr
$hive>select count(*) from t2 ;
$hive>select id,name from t2 ;
//$hive>select * from t2 order by id desc ; //mr
//啟用/禁用表
$hive>alter table t2 enable no_drop; //不允許刪除
$hive>alter table t2 disable no_drop; //允許刪除
//分割槽表,優化手段之一,從目錄的層面控制搜尋資料的範圍。
//建立分割槽表.
$hive>create table t3(id int,name string,age int) partitioned by (year int, month int) row format delimited fields terminated by ',' ;
//顯式表的分割槽資訊
$hive>show partitions t3;
//新增分割槽,建立目錄
$hive>alter table t3 add partition (year=2014, month=12);
//刪除分割槽
hive>alter table employee_partitioned drop if exists partition (year=2014, month=11);
//分割槽結構
hive>/user/hive/warehouse/mydb2.db/t3/year=2014/month=11
hive>/user/hive/warehouse/mydb2.db/t3/year=2014/month=12
//載入資料到分割槽表
hive>load data local inpath '/home/centos/customers.txt' into table t3 partition(year=2014,month=11);
//建立桶表
$hive>create table t4(id int,name string,age int) clustered by (id) into 3 buckets row format delimited fields terminated by ',' ;
//載入資料不會進行分桶操作
$hive>load data local inpath '/home/centos/customers.txt' into table t4 ;
//查詢t3表資料插入到t4中。
$hive>insert into t4 select id,name,age from t3 ;
//桶表的數量如何設定?
//評估資料量,保證每個桶的資料量block的2倍大小。
//連線查詢
$hive>create table customers(id int,name string,age int) row format delimited fields terminated by ',' ;
$hive>create table orders(id int,orderno string,price float,cid int) row format delimited fields terminated by ',' ;
//載入資料到表
//內連線查詢
hive>select a.*,b.* from customers a , orders b where a.id = b.cid ;
//左外
hive>select a.*,b.* from customers a left outer join orders b on a.id = b.cid ;
hive>select a.*,b.* from customers a right outer join orders b on a.id = b.cid ;
hive>select a.*,b.* from customers a full outer join orders b on a.id = b.cid ;
//explode,炸裂,表生成函式。
//使用hive實現單詞統計
//1.建表
$hive>create table doc(line string) row format delimited fields terminated by ',' ;
hive執行建表命令報錯
hive執行建表命令報錯 failed execution error,return code 1 from org.apache.hadoop.hive.ql.exec.ddltask.metaexception message for direct metastore db connection...
hive建表範例
建表範例 支援update和delete create table aaa id string visitor name string clustered by id into 2buckets stored as orc tblproperties transactional true 目前只有o...
hive建表範例
建表範例 支援update和delete create table aaa id string visitor name string clustered by id into 2buckets stored as orc tblproperties transactional true 目前只有o...