日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

hive 语句总结_Hive常用命令总结

發(fā)布時間:2023/12/20 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 hive 语句总结_Hive常用命令总结 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

本文只是總結(jié)一些在Hive中常用的命令,并且假設(shè)需要的目錄或者數(shù)據(jù)已經(jīng)存在。

創(chuàng)建表,\t作為列的分隔符

create table trade_detail (id bigint,income double,expenses double,time string) row formate delimited fields terminated by '\t';

create table user_info(id bigint, account string, name string, age int) row format delimited fields terminated by '\t';

接下來是稍復雜的語句,創(chuàng)建表的的同時進行賦值

create table result row format delimited fields terminated by '\t' as select t1.account, t1.income, t1.expenses, t1.surplus, t2.name from user_info t2 join (select account, sum(income) as income, sum(expenses) as expenses, sum(income-expenses) as surplus from trade_detail group by account) t1 on(t1.account = t2.account);

加載本地文件到數(shù)據(jù)表中

load data local inpath '/home/hadoop/data/student.txt' overwrite into table student;

load data local inpath '/home/hadoop/data/user_info.doc' overwrite into table user_info;

創(chuàng)建外部表 ,創(chuàng)建外部表的一般情況指的是:先有文件存放著數(shù)據(jù),之后我們再來創(chuàng)建表,也就是說創(chuàng)建一張表,然后指向這個有數(shù)據(jù)的目錄。以后只要是向這個目錄中上傳符合格式的數(shù)據(jù)會被自動裝在到數(shù)據(jù)庫表中,因為在metastore(元數(shù)據(jù))會記錄這些信息

create external table t_detail(id bigint, account string, income double, expenses double, time string) ) row format delimited fields terminated by '\t' location '/hive/td_partition';

創(chuàng)建分區(qū)表,一般用于數(shù)據(jù)量比較大的情況下, partitioned by (logdate string)用來指定按照什么進行分區(qū)

create external table t_detail(id bigint, account string, income double, expenses double, time string) row format delimited fields terminated by '\t' location '/hive/td_partition' partitioned by (logdate string);

將mysql中的數(shù)據(jù)直接保存到Hive中

sqoop export --connect jdbc:mysql://192.168.8.103:3306/hmbbs --username root --password hadoop --export-dir '/user/hive/warehouse/pv_2013_05_31/000000_0' --table pv

基本的插入語法

insert overwrite table tablename [partiton(partcol1=val1,partclo2=val2)]select_statement from t_statement

insert overwrite table test_insert select * from test_table;

更新表的名稱

hive> alter table source RENAME TO target;

添加新一列

alter table invites add columns (new_col2 INT COMMENT 'a comment');

刪除表:

DROP TABLE records;

刪除表中數(shù)據(jù),但要保持表的結(jié)構(gòu)定義

dfs -rmr /user/hive/warehouse/records;

顯示所有函數(shù)

show functions;

查看函數(shù)用法

describe function substr;

內(nèi)連接

SELECT sales.*, things.* FROM sales JOIN things ON (sales.id = things.id);

查看hive為某個查詢使用多少個MapReduce作業(yè)

Explain 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);

創(chuàng)建視圖

hive> CREATE VIEW valid_records AS SELECT * FROM records2 WHERE temperature !=9999;

查看視圖詳細信息

hive> DESCRIBE EXTENDED valid_records;

總結(jié)

以上是生活随笔為你收集整理的hive 语句总结_Hive常用命令总结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。