天天看點

hive基本操作

hive是一個基于hadoop的資料倉庫工具。hive的查詢語言是hive ql。一種類似sql的語言。

hive支援的資料類型有

1整形:

tinyint  1位元組整型

smallint  2位元組整型

bigint   8位元組整型

2.布爾型

boolean

3浮點型 

float

double

4字元串類型

string

5.符合類型

1structs:

2.maps

3.arrays

4.uniontype

5.timestamp

6.binary

操作符:

like

數學運算符

% & | ^ ~

邏輯運算符

and or ! not

函數

round(x)

floor(x)

ceil(x)

concat(x)

substr(x,x,x)

upper(x)

lower(x)

trim(x)

regexp_replace(x,x,x)

size(x)

cast(x)

from _unixtime(x)

to_date(x)to_date()

year(x)

mouth(x)

day(x)

hour()

minute()

second()

weekofyear(x)

get_json_object(string json_string, string path)

聚合函數:

count(*), count(expr), count(distinct expr[, expr_.])

sum(col), sum(distinct col)

avg(col), avg(distinct col)

min(col)

max(col)

語句:

建表語句

create table

表名(字段類型);

修改表

alter table 表明(字段,類型)

顯示資料庫名和表名

show databases/tables

為表添加一列

alter table aa add columns (new_col int);

添加一列并增加列字段注釋

alter table aa add columns (new_col2 int comment ‘a comment‘);

更改表名

hive> alter table  aa rename to bb;

删除列

drop table aa;

将檔案中的資料加載到表中

load data local inpath ‘./examples/files/kv1.txt‘ overwrite into table pokes;