1. 程式人生 > >Hive常用命令(三)--DML操作

Hive常用命令(三)--DML操作

Data Manipulation Language:資料操縱語言

資料匯入

1、load模式

LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename [PARTITION(partcol1=val1,partcol2=val2 ...)]
  • load data:表示載入資料
  • local:表示從本地載入資料到 hive 表;否則從 HDFS 載入資料到hive 表
  • inpath:表示載入資料的路徑
  • overwrite:表示覆蓋表中已有資料,否則表示繼續新增資料
  • into table tablename:表示要載入資料到哪個表
  • partition:表示上傳到指定分割槽
hive (bigdata)> create table student(id int,name string)
              > row format delimited fields terminated by '\t';
OK
Time taken: 1.404 seconds
hive (bigdata)> load data local inpath '/opt/test/student' into table student;
Loading data to table bigdata.student
OK
Time taken: 2.4 seconds

2、insert模式

INSERT OVERWRITE TABLE tablename1 [PARTITIO
N (partcol1=val1, partcol2=val2 ...) [IF NO
T EXISTS]] select_statement1 FROM from_stat
ement;
INSERT INTO TABLE tablename2 [PARTITION (pa
rtcol1=val1, partcol2=val2 ...)] select_sta
tement1 FROM from_statement;
hive (bigdata)> select
* from student;
OK student.id student.name 1 zhangsan 2 lisi Time taken: 4.057 seconds, Fetched: 2 row(s) #直接新增資料 hive (bigdata)> insert into table student values('3','wangwu'); hive (bigdata)> select * from student; OK student.id student.name 3 wangwu 1 zhangsan 2 lisi Time taken: 0.326 seconds, Fetched: 3 row(s) #從其他表載入資料 hive (bigdata)> create table student2(id int,name string) > row format delimited fields terminated by '\t'; hive (bigdata)> insert into table student2 values('4','chenliu'); hive (bigdata)> insert into table student select * from student2; hive (bigdata)> select * from student; OK student.id student.name 3 wangwu 4 chenliu 1 zhangsan 2 lisi Time taken: 0.311 seconds, Fetched: 4 row(s) #覆蓋掉原來表中資料 hive (bigdata)> insert overwrite table student select * from student2; #將一個表的資料新增到其它多個表中 #以下三種結果相同,都不覆蓋原表資料 hive (bigdata)> from student2 > insert overwrite table teacher partition(day=20180812) select * > insert into table teacher partition(day=20180813) select *; hive (bigdata)> from student3 > insert into table teacher partition(day=20180812) select * > insert overwrite table teacher partition(day=20180813) select *; hive (bigdata)> from student2 > insert into table aaa partition(day=20180812) select * > insert into table aaa partition(day=20180813) select *; #覆蓋原表資料 hive (bigdata)> from student3 > insert overwrite table aaa partition(day='20180812') select * > insert overwrite table aaa partition(day='20180813') select *;

3、as select模式

hive (bigdata)> create table student4 as select * from teacher;

4、location模式

#本地上傳到hdfs
hive (bigdata)> dfs -put /opt/test/student /student;
#從hdfs匯入
hive (bigdata)> create table student5(id int,name string)
              > row format delimited fields terminated by '\t'
              > location '/student';

5.import模式

#匯入的必須是經過export匯出的資料
hive (wangfang)> import table teacher from '/yyy';

資料匯出

1、insert模式

#匯出到本地
hive (bigdata)> insert overwrite local directory '/opt/test/export'
              > select * from teacher;
[[email protected] export]# more 000000_0 
4chenliu20180812
5wangfang20180812
1zhangsan20180812
2lisi20180812
4chenliu20180813
5wangfang20180813
1zhangsan20180813
2lisi20180813
#匯出到本地,新增格式
hive (bigdata)> insert overwrite local directory '/opt/test/export'
              > row format delimited fields terminated by '\t'
              > select * from teacher;
[[email protected] export]# more 000000_0 
4   chenliu 20180812
5   wangfang    20180812
1   zhangsan    20180812
2   lisi    20180812
4   chenliu 20180813
5   wangfang    20180813
1   zhangsan    20180813
2   lisi    20180813
#匯出到HDFS
hive (bigdata)> insert overwrite directory '/xxx'
              > row format delimited fields terminated by '\t'
              > select * from teacher;

2、export模式

#匯出路徑目錄需不存在,匯出是自行建立
hive (bigdata)> export table teacher to '/yyy';

3、dfs -get模式

hive (bigdata)> dfs -get /hive/warehouse/bigdata.db/student/000000_0 /opt/test/export/aaa.txt

4、hive -e 模式

[[email protected] export]# hive -e 'select * from student;' > /opt/test/export/bbb.txt;

相關推薦

Hive常用命令--DML操作

Data Manipulation Language:資料操縱語言 資料匯入 1、load模式 LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE tablename [PA

LinuxCentOS常用命令 —— 檔案操作命令

1、cp :(copy)複製檔案或資料夾到指定目錄 cp (空)資料夾或檔名 /指定目錄 cp (空)資料夾或檔名 /指定目錄/要更改的名稱 當要複製的資料夾不為空時,要加上引數 -r 或

Git常用命令------ 本地操作

mov ast 常用 stage director git reset 本地 posit 自動 本文總結自廖雪峰的網站。 幾個名詞: 工作區(Working Directory):電腦裏能看到的目錄 版本庫(Repository):包含暫存區和master 暫存區(Stag

linux常用命令

關閉 現象 磁盤空間 x文件 post div 掛載iso 硬盤 inux 磁盤空間相關的命令 1.mount : 掛載文件系統(包括硬盤,光盤,軟盤等) mount -t 設備類型 存放目錄 eg:在目錄/mnt下,掛載iso9660文件系統:mount -t iso96

LinuxUbuntu常用命令

需要 ip地址 useradd 賬號 his word color -a change 查看時間    cal :顯示當前日期。    cal 2018 :顯示全年日歷。/ cal -y 顯示當年日歷。    date :顯示當前時間。   這幾個一般不會用到了解即可。 查

linux 常用命令ssh

AD HA key direct password IT 常用 是否可用 erp linux 常用命令(三)ssh (1) 安裝並配置 SSH 無密碼登陸 CentOS 默認已安裝了 SSH client、SSH server,打開終端執行如下命令進行檢驗 rpm -qa

大資料學習第一天——linux常用命令

三 檔案操作 1建立檔案 touch somefile.txt 建立一個空檔案somefile.txt > 重定向操作符  echo "woshiwoa"> some.txt 將woshiwoa寫入到some.txt 檔案中,如果檔案不存在則會創建出來 echo "www.ba

跟我一起學Mysql常用命令

Mysql常用命令 select version(); 查詢mysql伺服器的版本 show databases; 顯示當前資料庫 use 庫名; 開啟指定的庫 show tables; 展示當前資料庫的所有表 show tables from 庫名; 展示某個庫裡的所有

Linux常用命令: uniq

Linux uniq命令用於檢查及刪除文字檔案中重複出現的行列。 uniq可檢查文字檔案中重複出現的行列。 語法 uniq [-cdu][-f<欄位>][-s<字元位置>][-w<字元位置>][--help][--version][輸入檔案][輸出檔案

linux基礎學習之軟體安裝以及常用命令

    新增和檢視使用者: [[email protected] ~]# useradd anderson [[email protected] ~]# cat /etc/passwd 顯示如下: [[email protected

linux常用命令檔案作業系統與磁碟管理

1.df -h  檢視磁碟容量 2.du -h  檢視目錄容量 3.du -h -d  檢視目錄深度 du -h -d 0 ~  檢視一級目錄資訊 du -h -d 1 ~檢視二級目錄資訊 4.du

004-Linux下操作目錄常用命令mkdir

刪除目錄 note 當前 目錄 name ges 否則 技術分享 mdi 1,mkdir 創建目錄 當前目錄下創建一個目錄 mkdir dir 創建含有子目錄的方式 mkdir -p dir/t11/t1

總結Linux 、Redis 操作常用命令

tab ESS 哈希 大對象 由於 edi always wan 情況下 Redis的配置 1. Redis默認不是以守護進程的方式運行,可以通過該配置項修改,使用yes啟用守護進程 daemonize no 2. 當Redis以守護進程方式運行時,Redis默認會把

java常用工具類—— Excel 操作工具

import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.*; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io

Spark採坑系列Spark操作Hive的坑

跟著教學試著用Idea程式設計,實現Spark查詢Hive中的表。結果上來就涼了。 搗鼓好久都不行,在網上查有說將hive-site.xml放到resource目錄就行,還有什麼hadoop針對windows使用者的許可權問題,結果都是扯淡。 其實問題還是處在程式碼上,直接附上程式碼了

python標準庫常用模組-----------------------------OS模組詳解,呼叫系統的命令

OS模組是呼叫系統命令的模組,和執行cmd的命令相似。 1.獲取當前的工作目錄:getcwd() 2.改變當前指令碼的工作目錄:chdir(path) 3.返回當前目錄:curdir() 4.獲取當前目錄的父目錄:pardir() 5.若目錄為空,則刪除,遞迴到上一

Hive程式設計指南-學習筆記 資料操作

一、向管理表中裝載資料 Hive沒有行級別的資料插入、更新和刪除操作,往表中裝載資料的唯一途徑就是使用一種“大量”的資料裝載操作。 LOAD:向表中裝載資料 (1)把目錄‘/usr/local/data’下的資料檔案中的資料裝載進usr表,並覆蓋原有資料:LOAD DA

Linux操作命令

重復 技術分享 href alt src 分頁顯示 continue img 搜索 本次實驗將介紹 Linux 命令中 more、less、head、tail 命令的用法。 more less head tail 1.more   ·mo

Linux Shell 常用shell命令基本系統命令

三、基本系統命令 1、man命令 功能:檢視某個命令的幫助,如果你不知道某個命令的用法不懂,可以問他,他知道就回告訴你 例如: man ls 顯示ls命令的幫助內容 2、w命令 功能:顯示登入使用者的詳細資訊 例如: Sarge:~# w 22:06:5

文件與目錄管理命令

信息 touch share 單位換算 目錄管理類命令包括:cd,pwd,ls,mkdir,rmdir,tree,cp,mv,rm,touch,stat1.1.ls功能:列出文件或目錄命令幫助:man lsinfo lsls --helphelp cd #只有內部命令才能用ls /usr/s