Hive基本命令(2)

来源:互联网 发布:女生宿舍关系 知乎 编辑:程序博客网 时间:2024/05/16 02:55
1.创建表:
    create table if not exists student(id int,name string);
2.创建表并创建索引字段ds
    create table sutdent(id int,name string) PARTITIONED BY (ds string);
3.显示所有表:show tables;
4.按正则表达式显示表:SHOW TABLES '.*S';
5.表添加一列:ALTER TABLE student ADD COLUMNS(new_col int);
6.添加一列并增加字段注释:
ALTER TABLE student ADD columns(new_col2 int comment 'a comment');
7.更改表名:alter table student rename to student2;
8.删除列可以使用:alter table student replace columns(id int,name string);
这样表示除了id和name以外其他的都会被删除。但是只是删除元数据而已,并没有修改hdfs上的数据
9.删除表:drop table student;
10.将文件中的数据夹在到表中
LOAD DATA LOCAL INPATH 'data.txt' OVERWRITE INTO TABLE student;
11.创建一个气象数据表:
CREATE TABLE records(year STRING,temperature INT,quality INT) ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t';
12.加载数据:LOAD DATA INPATH'input/ncdc/micro-tab/sample.txt' OVERWRITE INTO TABLE records;
13.通过hadoop dfs -ls /user/hive/warehouse/records命令可以查看在该目录下存在sample.txt文件。
14.查询
select year,MAX(temperature) FROM records GROUP BY year;
15.查看hive中所有的函数(function):show functions;
16.查看具体函数的使用说明:describe functions 具体函数名(sum);
17.语法:
CREATE [EXTERNAL] TABLE [IF NOT EXISTS] table_name
[(col_name data_type [COMMENT col_comment],....)]
[COMMENT table_comment]
[PARTITIONED BY(col_name data_type [COMMENT col_comment],....)]
[CLUSTERED BY(col_name,col_name,.....) [SORTED BY(col_name[ASC|DESC],...)] INTO num_buckets BUCKETS]
[ROW FORMAT row_format][STORED AS file_format]|STORED BY 'storage.handler.class.name' [WITH SERDEPROPERTIES(....)]
(Note: only available starting with 0.6.0)]
[LOCATION hdsf_path]
[TBLPROPERTIES (property_name=property_value,...)] (Note: this feature is only available starting with 0.5.0)
18.拷贝某个表的结构:
CREATE TABLE IF NOT EXISTS student2 LIKE student;
19.HIVE的数据类型分为:
基本数据类型,复杂数据类型
基本数据类型:TINYINT,SMALLINT,INY,BIGINT,BOOLEAN,FLOAT,DOUBLE,STRING
复杂数据类型:ARRAY<data_type>,MAP<primitive_type,data_type>,STRUCT<col_name:data_type [COMMENT col_comment],....>
20.创建一个表,间隔符号为'\005' ,文件数据是纯文本的形式:
create table demo(id int,info string) row format delimited fields terminated by '\005' stored as textfile;
其中terminated by:关于来语的文本数据的字段间隔符,stored as textfile表示是纯文本数据的形式,如果是压缩则为stored as sequence;

原创粉丝点击