HiveQL基本操作整理

2022-04-08 22:57:24 字數 4175 閱讀 5576

create table pokes (foo int, bar string);create table new_table like records;create view valid_records as select * from records2 where temperature !=9999;create external table page_view(viewtime int, userid bigint,

page_url string, referrer_url string,

ip string comment 'ip address of the user',

country string comment 'country of origination')

comment 'this is the staging page view table'

row format delimited fields terminated by '\054'

stored as textfile

location '';create table par_table(viewtime int, userid bigint,

page_url string, referrer_url string,

ip string comment 'ip address of the user')

comment 'this is the page view table'

partitioned by(date string, pos string)

row format delimited fields terminated by '\t'

lines terminated by '\n';

stored as sequencefile;hive不支援用insert語句一條一條的進行插入操作,也不支援update操作。資料是以load的方式載入到建立好的表中。資料一旦匯入就不可以修改。

路徑支援:

* 相對路徑,例如:project/data1

* 絕對路徑,例如: /user/hive/project/data1

* 包含模式的完整 uri,例如:hdfs://namenode:9000/user/hive/project/data1

load data local inpath '/home/hadoop/input/ncdc/micro-tab/sample.txt' overwrite into table records;load data local inpath '/home/hadoop/input/hive/partitions/file1' into table logs partition (dt='2001-01-01',country='gb');show tables;

show tables '.*s'; //按正條件(正規表示式)顯示表describe invites;show partitions logs;show functions;describe function substr;select col1[0],col2['b'],col3.c from complex;explain select sales.*, things.* from sales join things on (sales.id = things.id);describe extended valid_records;alter table source rename to target;alter table invites add|replace columns (new_col2 int comment 'a comment');alter table table_name add [if not exists] partition_spec [ location 'location1' ] partition_spec [ location 'location2' ] ...

partition_spec:

: partition (partition_col = partition_col_value, partition_col = partiton_col_value, ...)

alter table table_name drop partition_spec, partition_spec,...alter table table_name set tblproperties table_properties table_properties:

:[property_name = property_value…..]alter table table_name set fileformat file_format

alter table table_name clustered by(userid) sorted by(viewtime) into num_buckets bucketsdrop table records;dfs -rmr /user/hive/warehouse/records;drop view view_nameselect sales.*, things.* from sales join things on (sales.id = things.id);select sales.*, things.* from sales left outer join things on (sales.id = things.id);

select sales.*, things.* from sales right outer join things on (sales.id = things.id);

select sales.*, things.* from sales full outer join things on (sales.id = things.id);select * from things left semi join sales on (sales.id = things.id);select /*+ mapjoin(things) */ sales.*, things.* from sales join things on (sales.id = things.id);insert overwrite table ..select:新錶預先存在

from records2

insert overwrite table stations_by_year select year, count(distinct station) group by year

insert overwrite table records_by_year select year, count(1) group by year

insert overwrite table good_records_by_year select year, count(1) where temperature != 9999 and (quality = 0 or quality = 1 or quality = 4 or quality = 5 or quality = 9) group by year;create table … as select:新表表預先不存在

create table target as select col1,col2 from source;insert overwrite table tablename1 [partition (partcol1=val1, partcol2=val2 ...)] select_statement1 from from_statementfrom from_statement

insert overwrite table tablename1 [partition (partcol1=val1, partcol2=val2 ...)] select_statement1

[insert overwrite table tablename2 [partition ...] select_statement2] ...insert overwrite table tablename partition (partcol1[=val1], partcol2[=val2] ...) select_statement from from_statement資料寫入檔案系統時進行文字序列化,且每列用^a 來區分,\n換行

insert overwrite [local] directory directory1 select ... from ...

from from_statement

insert overwrite [local] directory directory1 select_statement1

[insert overwrite [local] directory directory2 select_statement2]

HiveQL之Database相關操作

1 create database 建立資料庫語法 create database schema if not exists database name comment database comment location hdfs path with dbproperties property na...

ceph基本操作整理

啟動osd mon程序 start ceph osd id x start ceph mon id yyy 關閉osd mon程序 stop ceph osd id x stop ceph mon id yyy 檢視osd的狀態 status ceph osd id x scale up 同一節點上...

整理 CFileDialog基本操作

include stdafx.h include cmyfiledialog.h ifdef debug define new debug new undef this file static char this file file endif using namespace std int fno...