hive資料操作常用語法

2021-07-23 03:13:03 字數 1176 閱讀 2008

1、建立臨時表:

先create臨時表,然後insert資料

insert into tmp_table_name select * from (

select * from …寫查詢語句

)tmp(子查詢的別名)

2、清空表中的資料:

truncate table tablename

3、刪除表中的部分資料(不支援delete):

將查詢出的資料覆蓋掉原來的資料,也就相當於產出了部分不符合條件的資料

insert overwrite table table_name select *from table_name where…

4、判斷欄位不為空:

id is not null and  id !=''

(<>相當於!=)

5、取出json串中的某個字段:

以下查詢查出a中的所有字段以及b的content_id欄位

content_id是**於detail_fields的json串的乙個叫做content_id的字段

select a.*,b.content_id from maidian_event alateral view json_tuple(detail_fields,』content_id』) b as content_id

6、時間為yyyy-mm-dd:hh-mm-ss格式的要取出日期:

to_date(table.datetime)

7、條件判斷:

case

when  then

when  then

else

end8、新增分割槽,將mapreduce執行出的資料作為表的分割槽加在資料庫表中

alter tablemid.event_session_begin_end add if not exists partition(ymd='$',biztype='$') location"/user/hive/warehouse/mid.db/event_session_begin_end/$/$";

不用load資料,分割槽裡面自然就有資料了

load data inpath'/user/pv.txt' into table day_hour_table partition(dt='2008-08- 08', hour='08')

9、建表時記得』\t』分隔符,否則mapreduce之後的資料全在一列

hive常用語法

指定分隔符為逗號 create table student id string,birthday string,grade int,m1 int,m2 int,m3 int,m4 int,memo string row format delimited fields terminated by 外部...

hive常用語法

hive基本操作 檢視資料庫 show databases 檢視表資訊 show tables 檢視分割槽 show partitions 檢視函式 show functions 檢視詳細資訊 格式模糊 desc extended t tablename 檢視詳細資訊 格式清晰 desc forma...

Hive(三)常用語法(Hive QL)

1.hive建立資料庫 create database schema if notexists 2.hive建立表 hive裡一般有兩種表的結構,表和外部表,以下分別是兩種表的建立 create table phone info id int,name string,storage string,p...