Hive Common Commands

Source: Internet
Author: User

#创建新表

Hive> CREATE TABLE t_hive (a int, b int, c int) ROW FORMAT delimited fields TERMINATED by ' \ t ';

#导入数据t_hive. txt to t_hive table

hive> LOAD DATA LOCAL inpath '/home/cos/demo/t_hive.txt ' OVERWRITE into TABLE t_hive;

#正则匹配表名

Hive>show tables ' *t* ';

#增加一个字段

hive> ALTER TABLE t_hive ADD COLUMNS (New_col String);

#重命令表名

hive> ALTER TABLE t_hive RENAME to T_hadoop;

#从HDFS加载数据

hive> LOAD DATA inpath '/user/hive/warehouse/t_hive/t_hive.txt ' OVERWRITE into TABLE t_hive2;

#从其他表导入数据

hive> INSERT OVERWRITE TABLE t_hive2 SELECT * from t_hive;

#创建表并从其他表导入数据

Hive> CREATE TABLE t_hive as SELECT * from T_hive2;

#仅复制表结构不导数据

Hive> CREATE TABLE t_hive3 like t_hive;

#通过Hive导出到本地文件系统

hive> INSERT OVERWRITE LOCAL DIRECTORY '/tmp/t_hive ' SELECT * from t_hive;

#Hive查询HiveQL

From (select B,c as C2 from t_hive) t select t.b, T.C2 limit 2;

Select B,c from t_hive limit 2;

#创建视图

Hive> CREATE VIEW v_hive as SELECT A, from t_hive;

#删表

drop table if exists t_hft;

#创建分区表

DROP TABLE IF EXISTS t_hft;
CREATE TABLE T_HFT (
Securityid STRING,
Tradetime STRING,
PRECLOSEPX DOUBLE
) partitioned by (Tradedate INT)
ROW FORMAT delimited TERMINATED by ', ';

#导入分区数据

hive> Load Data local inpath '/home/bluebreeze/data/t_hft_1.csv ' overwrite into table T_HFT partition (tradedate= 20130627);

#查看分区表

hive> SHOW partitions t_hft;

Hive Common Commands

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.