[Hive笔记]Hive常用命令整理
Commonly used Hive Commands
DDL Commands
COMMAND | OBJECTS |
---|---|
CREATE | Database, Table |
DROP | Database, Table |
TRUNCATE | Table |
ALTER | Database, Table |
SHOW | Database, Tables, Table Properties, Partitions, Functions, Index |
DESCRIBE | Database, Table, View |
- Create database
hive> create database if not exist demoDB comment "This is a demo"
location '/user/hive/warehouse/demodb';
- Drop database
hive> drop database if not exist demoDB CASCADE;
- Describe database
hive>describe database extended demoDB;
- Show databases
hive> show databses;
- Use database
hive> use demoDB;
DML Commands
-
LOAD
LOAD DATA [LOCAL] INPATH 'filepath' [OVERWRITE] INTO TABLE [PARTITION (partcol1=val1, partcol2=val2...)]
filepath 可以是:
*相对路径, 例如 project/data1
*绝对路径, 例如 /user/hive/project/data1
*包含schema和authority的完整URL, 例如hdfs://namenode:9000/user/hive/project/data1filepath 可以用引用一个文件或者一个目录
如果指定关键字LOCAL, 那么:
- load命令将会从本地文件系统中查找文件路径
- load命令将会拷贝所以文件到目标文件系统
如果没有指定 LOCAL关键字,那么Hive将使用指定了的完整URL,或者使用以下规则:
- 如未指定schema或authority, Hive将从记录了namenode URL的配置变量fs.default.name中获取
*如果路径不是绝对路径,那么Hive将会默认关联/user/
*Hive会将所有相关文件移动到目前表或分区下
-
INSERT
Standard Syntax
INSERT OVERWRITE TBALE tablename1 [PARTITION (partcol1=val1,partcol2=val2) [IF NOT EXISTS]] select_statement1 FROM from_statement; INSERT INTO TABLE tablename1 [PARTITION (partcol1=val1,partcol2=val2)] select_statement1 FROM from_statement;
Standard Syntax2
INSERT INTO TABLE tablename [PARTITION (partcol1=val1, partcol2=val2)] VALUES values_row [, value_row ...];
-
UPDATE
Standard SyntaxUPDATE tablename SET column = value [, col2 = val2 ] [WHERE expression];
-
DELETE
Standard SyntaxDELETE FROM tablename [WHERE expression];
-
MERGE
[未完待续]