Hadoop下hive資料庫基礎操作命令程式碼合集
阿新 • • 發佈:2019-02-09
create table useinfo(//建立表的名稱為useinfo
id int,//int 值
name string) //string值
row format delimited //設定分隔符的格式
fields terminated by '\t'; //以tab鍵分割欄位
create table classinfo9(
teacher string,
classname string)
row format delimited
fields terminated by '\t';
create table choice (
userid int,
classname string)
row format delimited
fields terminated by '\t';
load data local inpath '/home/liqifeng/hadoop' overwrite into table useinfo //從本地檔案匯入資料
loacl data local inpath '/home/lidafeng/hadoop' overwrite into table classinfo //從本地檔案匯入資料
loacl data loacl inpath '/home/lidafeng/hadoop' overwrite into table classinfo //從本地檔案匯入資料
create table ptest (
userid int)
partitioned by (name string) //以name作為分割槽欄位
row format delimited
fields terminated by '\t';
create external table liqifeng(
name string,
id int,
class string)
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile
location '/user/hadoop'
partitioned by (home string)
load data loacl inpath '/home/lidafeng/hadoop' overwrite into table ptest partition (name='xiapi'); 從本地檔案匯入資料到petst表的xiapi分割槽中
insert overwrite table ptest partitioned (name='xiapi') select id from useinfo where name='xiapi' 從useinfo表中插入name='xiapi'的欄位到petst表的name='xiapi'分割槽中
alter table petst drop partitioned(name='xiapi') //刪除分割槽
alter table petst add partitioned (name='liqifeng') //新增liqifeng分割槽
show partitioned patst //顯示分割槽欄位
create table mutill as select id,name from userinfo //建立mutill表,並且複製userinfo表中的id和name欄位
create table mutill2 like userinfo// 只複製userinfo的結構
from userinfo
insert overwrite table mutill select id,name insert overwrite table mutill2 select count(distinct id),name group by name;//把一個表的資料插入到兩個表裡
select userinfo.*,classinfo.* from userinfo join classinfo on (userinfo.id=classinfo.userid);//把userinfo和classinfo表中相同的值保留
select userinfo.*,classinfo.* from userinfo left outer join classinfo on (userinfo.id=classinfo.userid);//顯示左邊表的所有資料,右邊的一樣就顯示,不一樣就null
select userindo.*,classinfo.* from userinfo right outer join classinfo on (userinfo.id=classinfo.userid);//顯示右邊表的所有資料,左邊的一樣就顯示,不一樣就null
select userinfo.*,classinfo.* from userinfo fullo outer join classinfo on (userinfo.id=classinfo.userid);//兩邊的所有資料,遇到一樣的就都顯示,不一樣的就null
select userinfo.* from userinfo left semi join classinfo on (userinfo.id=classinfo.userid);//只顯示左表的所有資料,但是一定要和右邊一樣
create table phy_opt_course(
stname string,stID int,class string,opt_cour string)
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile//以txt文字格式儲存
local data local inpath '/home/liqifeng/liqifeng.txt' into table phy_opt_course; //把資料匯入到phy_opt_course表中;
local data local inpath '/root/liqifeng' into table phy_opt_course partition (home='yangzhou');
insert overwrite table liqifeng partition (name='xiapi') select id,name from userinfo;//向表中插入資料;
set hive.enforce.bucketing=true;//開啟桶
set hive.enforce.buckering;//檢視是否開啟桶
create table tests(
id int,
name string)
clustered by (id) into 3 buckets
row format delimited
field terminated by '\t'
id int,//int 值
name string) //string值
row format delimited //設定分隔符的格式
fields terminated by '\t'; //以tab鍵分割欄位
create table classinfo9(
teacher string,
classname string)
row format delimited
fields terminated by '\t';
create table choice (
userid int,
classname string)
row format delimited
fields terminated by '\t';
load data local inpath '/home/liqifeng/hadoop' overwrite into table useinfo //從本地檔案匯入資料
loacl data local inpath '/home/lidafeng/hadoop' overwrite into table classinfo //從本地檔案匯入資料
loacl data loacl inpath '/home/lidafeng/hadoop' overwrite into table classinfo //從本地檔案匯入資料
create table ptest (
userid int)
partitioned by (name string) //以name作為分割槽欄位
row format delimited
fields terminated by '\t';
create external table liqifeng(
name string,
id int,
class string)
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile
location '/user/hadoop'
partitioned by (home string)
load data loacl inpath '/home/lidafeng/hadoop' overwrite into table ptest partition (name='xiapi'); 從本地檔案匯入資料到petst表的xiapi分割槽中
insert overwrite table ptest partitioned (name='xiapi') select id from useinfo where name='xiapi' 從useinfo表中插入name='xiapi'的欄位到petst表的name='xiapi'分割槽中
alter table petst drop partitioned(name='xiapi') //刪除分割槽
alter table petst add partitioned (name='liqifeng') //新增liqifeng分割槽
show partitioned patst //顯示分割槽欄位
create table mutill as select id,name from userinfo //建立mutill表,並且複製userinfo表中的id和name欄位
create table mutill2 like userinfo// 只複製userinfo的結構
from userinfo
insert overwrite table mutill select id,name insert overwrite table mutill2 select count(distinct id),name group by name;//把一個表的資料插入到兩個表裡
select userinfo.*,classinfo.* from userinfo join classinfo on (userinfo.id=classinfo.userid);//把userinfo和classinfo表中相同的值保留
select userinfo.*,classinfo.* from userinfo left outer join classinfo on (userinfo.id=classinfo.userid);//顯示左邊表的所有資料,右邊的一樣就顯示,不一樣就null
select userindo.*,classinfo.* from userinfo right outer join classinfo on (userinfo.id=classinfo.userid);//顯示右邊表的所有資料,左邊的一樣就顯示,不一樣就null
select userinfo.*,classinfo.* from userinfo fullo outer join classinfo on (userinfo.id=classinfo.userid);//兩邊的所有資料,遇到一樣的就都顯示,不一樣的就null
select userinfo.* from userinfo left semi join classinfo on (userinfo.id=classinfo.userid);//只顯示左表的所有資料,但是一定要和右邊一樣
create table phy_opt_course(
stname string,stID int,class string,opt_cour string)
row format delimited
fields terminated by '\t'
lines terminated by '\n'
stored as textfile//以txt文字格式儲存
local data local inpath '/home/liqifeng/liqifeng.txt' into table phy_opt_course; //把資料匯入到phy_opt_course表中;
local data local inpath '/root/liqifeng' into table phy_opt_course partition (home='yangzhou');
insert overwrite table liqifeng partition (name='xiapi') select id,name from userinfo;//向表中插入資料;
set hive.enforce.bucketing=true;//開啟桶
set hive.enforce.buckering;//檢視是否開啟桶
create table tests(
id int,
name string)
clustered by (id) into 3 buckets
row format delimited
field terminated by '\t'