标签:
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 ‘<hdfs_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 BUCKETS
DROP TABLE records;
dfs -rmr /user/hive/warehouse/records;
DROP VIEW view_name
SELECT 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_statement
FROM 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]
标签:
原文地址:http://blog.csdn.net/lnho2015/article/details/51381198