iis服务器助手广告广告
返回顶部
首页 > 资讯 > 数据库 >hive的指令操作及内外临时表的创建
  • 664
分享到

hive的指令操作及内外临时表的创建

2024-04-02 19:04:59 664人浏览 泡泡鱼
摘要

2、数据库: OLTP //online transaction process ,在线事务处理3、drop databases  if exists  mybase //删除


2、数据库: OLTP //online transaction process ,在线事务处理


3、drop databases  if exists  mybase //删除数据库


4、show tables //显示表


5、create  database  mybase //Mysql 创建库


6、create table test(id int ,name varchar(20)); //创建列表


7、select id from test        //查看表中的内容


8、两张表合成:select a.*,b.* fORM tbls a,columms_v2 b where a.tbl_id = b.tbl_id 


9、show databases; //显示数据库


10、在/soft/Hive/bin/下执行:hive 后再执行:create database if not exists mybase;


11、用自己的库的话就执行:use mybase ;   ------>记得加分号

show tables; ——————》显示表信息


12、创建表:create table test(id int , name varchar(20));


13、查看表的结构:desc test


14、往数据库里面放数据:insert into test(id,name)values(1,'tom');


15、select * form test      //查看表中所有的内容




具体流程是:创建库:create database mysbase ------>用那个库use mybase  ------->创建表create table test(id int ,name varchar(20))




-----------------------------------------------------


表的填写信息及创建语法:

1、create  table if not exists employee(edi int ,nam String,salary String, destination String)


2、comment ‘employee details’



4、 row format delimited  fields terminated by ‘\t’ //这行的格式分隔如何 :(1  tom  12 )


5、lines terminated by ‘\n’ //换行1  tom  12

     2  tod  13


6、stored as textfile;   //存储为文本文件



dfs -lsr / ; //查看它们的目录结构


-------------------------------------------------------------------------------------------

desc[ribe] database mybase ; //查看数据库信息

alter database mybase set dbproperties ('created'='xpc'); //修改数据库,增加数据库属性

desc database extended mybase ; //显示数据库扩展信息,不能格式化输出

desc extended default.test0 ; //显示表扩展信息

desc formatted default.test0 ; //显示表格式化信息

desc extended test ; //显示表的扩展信息

create database mybase location '/x/x/x/x' //指定数据库存放hdfs位置

create table default.test0 like mybase.test2 ; //复制表结构


load data local ... //上传本地文件到hdfs

load data '/x/x/x' into table xx //移动hdfs文件系统上的数据文件。

insert into mybase.test2 select * from default.test0 where id > 1204 ; //复制表数据


create table mybase.test3 as select * from default.test0 ; //复制表(表结构 + 数据)

select all id,name from test2 ; //查询所有记录(不去重)

select distinct id,name from test2 ; //查询所有记录(去重)


--------------------------------------------------------

拷贝一张已经存在的表模式

create table if ont exists mydb.employees2 like mydb.employees


-------------------------------------------


如何从本地插进文本文件:

load data local inpath '/home/user/sample.txt' overwrite into table tset;

----------------------------------------------------------

外部表的创建步骤:

1、create database mybase ;  //创建库

2、use  mybase  ;          //用库

3、create external table etest(id int ,name string,age int) row format delimited fields terminated by '\t' stored as textfile ;//创建外部表


4、查看表的参数: desc formatted etest ; 查看有 多少张表:show tables  看表的结构select * from etest ;


5、创建临时表create tempporary table temp(id int ,name string,age int) row format delimited fields terminated by '\t' stored as textfile ;


6、CTAS:create table as select 


7、truncate  :删除所有的行,只能用于内部的表


8、修改表分隔符:alter table table_name set serdeproperties (‘field,delimi’= ',')


9、修改表的位置:alter table 表名 set location 'hdfs:/xxx/x/表名'



分区表

------------

[手动分区--静态分区]

1.预先定义分区列和存储数据到表的子目录下。

2.创建分区表

create table xxx(...) partitioned by (year int ,month int) row format ...;


3.给分区表添加多个分区(手动分区)

alter table partest add partition (year=2016,month=4) partition (year=2016,month=5);

4.显示指定表的分区

show partitions partest ;

5.删除分区

ALTER TABLE partest DROP IF EXISTS PARTITION (year=2014, month=11);

6.加载数据到指定的分区目录下。

LOAD DATA LOCAL INPATH '..sample.txt' OVERWRITE INTO TABLE partest PARTITION (year=2016, month=4);

单是查询2016年4月份的数据:select * from  表名 where year=2016 and month = 4 ;


7.启动动态分区(默认是开启的)

SET hive.exec.dynamic.partition=true; //启动动态分区.

//默认是strict,是严格模式,至少要指定一个分区类,通过如下指令关闭严格模式。

SET hive.exec.dynamic.partition.mode=nonstrict; //设置分区模式,非严格.

8.测试动态分区

insert into table partest partition(year,month) select id,name,age,year,month from test ;



























您可能感兴趣的文档:

--结束END--

本文标题: hive的指令操作及内外临时表的创建

本文链接: https://www.lsjlt.com/news/36192.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作