HIVE常用SQL语句及语法
HIVE建内部表语句
create table dll102.sougou
(id string,pwd string,name string,count int,seqno int,address string)
row format delimited fields terminated by '\t' ;

创建字段中含有数组类型,对象类型的表,并查询特殊字段







外部表默认 存在HDFS下的 ‘/user/hadoop/指定路径’
将本地文件加载到HIVE
load data local inpath '/home/hadoop/sgtest' into table sougou;
查看表结构
desc formatted emp;[table_name];

常用SQL语句
// 创建内部表 student
create table student(id int, name string, sex string, age int, department string)
row format delimited fields terminated by ',' //行分隔符用 lines
stored as textfile; // 从本地导入数据
load data local inpath '/home/hadoop/student.txt' into table student; // 查询数据
select id, name, sex, age, department from student; // 创建一个external表
create external table ext_student(id int, name string, sex string, age int, department string)
row format delimited fields terminated by ','
location '/ext_student'; // 导入数据
hadoop fs -put student.txt /ext_student;
load data local inpath '/home/hadoop/mingxing.txt' into table ext_student; // 查询数据
select id, name ,sex, age , department from ext_student; // 创建内部表引用外部路径
create table mng_student(id int, name string, sex string, age int, department string)
row format delimited fields terminated by ','
location '/ext_student'; // 创建分区表
create table ptn_student(id int, name string, sex string, age int, department string)
partitioned by(code string)
row format delimited fields terminated by ','; // 往分区表导入数据
load data local inpath '/home/hadoop/student.txt' into table ptn_student partition(code='');
load data local inpath '/home/hadoop/student.txt' into table ptn_student1 partition(code=''); //Hive表数据导出到HDSF
export table table_name to '/test/xx'; //Hive查询结果的导出
insert overwrite local directory '/opt/bigdata/export/student' select * from student;
insert overwrite local directory '/opt/bigdata/export/student' row format delimited fields terminated by ',' select * from student; 有local指的是导出到本地 ,没有local 导出到HDFS
// 创建多字段分区表
create table ptn_student1(id int, name string, sex string, age int, department string)
partitioned by(code string, province string)
row format delimited fields terminated by ','; // 往多分区表导入数据,需指定两个分区字段值
load data local inpath '/home/hadoop/student.txt'
into table ptn_student1 partition(code='', province='beijing');
load data local inpath '/home/hadoop/student.txt'
into table ptn_student1 partition(code='', province='tianjing');
load data local inpath '/home/hadoop/student.txt'
into table ptn_student1 partition(code='kk', province='tianjing'); // 创建分桶表
create table bck_student(id int, name string, sex string, age int, department string)
clustered by(department) into 4 buckets
row format delimited fields terminated by ','; // 重命名表
alter table student rename to studentss; // 修改表的字段
alter table studentss add columns(abc string, efg int); // 删除表的字段,有一些问题。drop字段有问题。不确定能不能执行成功
alter table studentss drop column efg; // 修改表的字段
alter table studentss change abc code int; // 修改表的字段,并且改变字段的位置
alter table studentss change efg province string after name; // 替换所有字段
alter table studentss replace columns(id int, name string, sex string ,
age int , department string); // 删除表
drop table bck_student;
drop table if exists bck_student; // 添加分区
alter table ptn_student add partition(code='');
alter table ptn_student add partition(code='') partition(code=''); // 删除分区
alter table ptn_student drop partition(code=''); // insert ... select .....
insert into table student select id, name, sex, age, department from studentss where department = 'MA'; // 以下两句操作是为多重插入准备两张表
create table student11(id int, name string)
row format delimited fields terminated by ','
stored as textfile; create table student22(sex string, age int, department string)
row format delimited fields terminated by ','
stored as textfile; // 多重插入
from studentss
insert into table student11 select id, name
insert into table student22 select sex, age, department; // 静态分区插入
load data local inpath 'student.txt' into table ptn_student partition(code=''); // 动态分区插入
set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
insert into table d_student partition(age) select id, name, sex, department,age from studentss; // 创建一个分区表,为上面的动态分区做准备的
create table d_student(id int, name string, sex string ,department string)
partitioned by(age int)
row format delimited fields terminated by ','; // CTAS
create table my_student as select id, name , sex, age, department from studentss; // like
create table like_student like studentss; // insert导出hive表数据到本地
insert overwrite local directory '/home/hadoop/myoutput'
select id, name, sex, age, department from studentss;
HIVE常用SQL语句及语法的更多相关文章
- 【知识库】-数据库_MySQL常用SQL语句语法大全示例
简书作者:seay 文章出处: 关系数据库常用SQL语句语法大全 Learn [已经过测试校验] 一.创建数据库 二.创建表 三.删除表 四.清空表 五.修改表 六.SQL查询语句 七.SQL插入语句 ...
- oracle常用SQL语句(汇总版)
Oracle数据库常用sql语句 ORACLE 常用的SQL语法和数据对象一.数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, ...
- 常用SQL语句(增删查改、合并统计、模糊搜索)
转自:http://www.cnblogs.com/ljianhui/archive/2012/08/13/2695906.html 常用SQL语句 首行当然是最基本的增删查改啦,其中最重要的是查. ...
- GP数据库 常用SQL语句
GP数据库 常用SQL语句 --1,查看列名以及类型 select upper(column_name) ,data_type from information_schema.columns wher ...
- Oracle数据库常用Sql语句大全
一,数据控制语句 (DML) 部分 1.INSERT (往数据表里插入记录的语句) INSERT INTO 表名(字段名1, 字段名2, ……) VALUES ( 值1, 值2, ……); INSE ...
- 经典MSSQL语句大全和常用SQL语句命令的作用
下列语句部分是Mssql语句,不可以在access中使用. SQL分类: DDL类型包括数据库.表的创建,修改,删除,声明—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML类 ...
- mysql 常用 sql 语句 - 快速查询
Mysql 常用 sql 语句 - 快速查询 1.mysql 基础 1.1 mysql 交互 1.1.1 mysql 连接 mysql.exe -hPup ...
- 常用SQL语句大全
一些常用SQL语句大全 一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql se ...
- DB2常用sql语句
转 DB2 提供了关连式资料库的查询语言sql(structured query language),是一种非常口语化.既易学又易懂的语法.此一语言几乎是每个资料库系统都必须提供的,用以表示关连式的操 ...
随机推荐
- celery中配置redis密码时的ValueError: invalid literal for int() with base 10: 'xxxx'
原配置: celery_broker = 'redis://:xxxx#xxxx@172.17.0.1:6379/0' # docker0 错误原因: 密码中不能有 # ? 等特殊字符 (无语O__O ...
- Begin at this time
学习了一段时间的Python,今天终于下定决心建立博客来记录自己的机器学习之路了.希望这是一个好的开始,希望自己永远不放弃,坚持努力下去.
- PHP-移除元素
给定一个数组 nums 和一个值 val,你需要原地移除所有数值等于 val 的元素,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成 ...
- 08-03-re-模块
一组特殊符号组成的表达式,用于描述某种规则.该应用场景生活中随处可见. 例如:让有志青年过上体面的生活,这里面就由规则,即有志青年. 正则表达式的作用,以及使用场景 1.用于从字符串中匹配满足 ...
- 58. jdk1.5新特性之静态导入
jdk1.5新特性之--------静态导入 作用:简化书写(在我们使用静态方法的时候要用 类名.方法名的方式调用.而用静态导入只需要写方法名就可以调用) 语法: 1.作用于一个方法: ...
- Java中的杂流(闸总)
标准输入输出流 System.in: 标准输入流是InputStream的子类对象,字节输入流,只不过是jvm给定的唯一一个从键盘控制条读入的流. public static final InputS ...
- 牛客Another Distinct Values
题目 我一开始试了一下n=3,发现不行,于是就猜测只有2可以,交了一发,通过了50%.所以我猜测只有偶数可以,奇数都不行. 中间空白部分放n=2的情况就行.因为n=2的情况时,最大只有2,所以我们可以 ...
- Go 方法、接口
在 Go 中,类型可以定义接收此类型的函数,即方法.每个类型都有接口,意味着对那个类型定义了方法集合. 下面定义了结构体类型 S 以及它的两个方法: type S struct { i int ...
- OpenLayers绘制图形
OpenLayers绘制图形 OpenLayers的显示构成由外向内为: ol.Map:地图对象. ol.layer.Vector:图层对象layer.Map含有多个layer,最终的显示效果是由 ...
- 4.2 react patterns(转)
修改 Props Immutable data representation 确定性 在 getInitialState 中使用 props 私有状态和全局事件 render 包含 side effe ...