Hive-DML数据操作_hive dml操作student-程序员宅基地

技术标签: 笔记-Hive  

数据导入

向表中装载数据(Load)

1.语法

load data [local] inpath '/opt/module/datas/student.txt' [overwrite] into table student [partition (partcol1=val1,…)];

(1)load data:表示加载数据

(2)local:表示从本地加载数据到hive表;否则从HDFS加载数据到hive表

(3)inpath:表示加载数据的路径

(4)overwrite:表示覆盖表中已有数据,否则表示追加

(5)into table:表示加载到哪张表

(6)student:表示具体的表

(7)partition:表示上传到指定分区

2.案例

加载本地文件到hive中

创建一张表

create table student(
id string, name string
)
row format delimited fields terminated by '\t';

加载本地文件到hive

load data local inpath '/opt/module/datas/student.txt' into table default.student;

加载HDFS文件到hive中

上传文件到HDFS

dfs -put /opt/module/datas/student.txt /user/liun/hive;

加载HDFS上数据

load data inpath '/user/liun/hive/student.txt' into table default.student;

加载数据覆盖表中已有的数据,overwrite

load data inpath '/user/liun/hive/student.txt' overwrite into table default.student;

通过查询语句向表中插入数据(Insert)

1.创建一张分区表

create table student(
id int, name string
) partitioned by (month string) row format delimited fields terminated by '\t';

2.基本插入数据

insert into table  student partition(month='201909') values(1,'liu');

3.基本模式插入(根据单张表查询结果)

insert overwrite table student partition(month='201908')
select id, name from student where month='201909';

4.多插入模式(根据多张表查询结果)

from student
              insert overwrite table student partition(month='201907')
              select id, name where month='201909'
              insert overwrite table student partition(month='201906')
              select id, name where month='201909';

注:insert into追加,insert overwrite覆盖

查询语句中创建表并加载数据(As Select)

create table if not exists student2 as select id, name from student;

注意创建表后面不能指定列字段名

创建表时通过Location指定加载数据路径

1.创建表,并指定在hdfs上的位置

create table if not exists student5(
              id int, name string
              )
              row format delimited fields terminated by '\t'
              location '/user/hive/warehouse/student4';

2.上传数据到hdfs上

dfs -put /opt/module/datas/student.txt /user/hive/warehouse/student4;

3.查询数据

select * from student4;

Import数据到指定Hive表中

注意:先用export导出后,再将数据导入。因为export导出数据带有元数据信息。表中不能有数据。

import table student2 partition(month='201909') from '/user/hive/warehouse/export/student';

数据导出

 Insert导出

1.将查询的结果导出到本地

insert overwrite local directory '/opt/module/datas/export/student'
select * from student;

2.将查询的结果格式化导出到本地

insert overwrite local directory '/opt/module/datas/export/student1'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t'
select * from student;

3.将查询的结果导出到HDFS上(没有local)

insert overwrite directory '/user/liun/student2'
ROW FORMAT DELIMITED FIELDS TERMINATED BY '\t' 
select * from student;

Hadoop命令导出到本地

dfs -get /user/hive/warehouse/student/ /opt/module/datas/export/student.txt;

Hive Shell 命令导出

基本语法:(hive -f/-e 执行语句或者脚本 > file)

bin/hive -e 'select * from default.student;' > /opt/module/datas/export/student2.txt;

 Export导出到HDFS上

export table default.student to '/user/hive/warehouse/export/student';

清除表中数据(Truncate)

注意:Truncate只能删除管理表,不能删除外部表中数据

truncate table student;

 

 

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/liu_1221/article/details/101369301

智能推荐

Spring Security OAuth2.0_实现分布式认证授权_集成测试_Spring Security OAuth2.0认证授权---springcloud工作笔记155_spring security oauth2.0实现分布式系统授权(nacos注册中心+网关+认证授-程序员宅基地

文章浏览阅读302次。技术交流QQ群【JAVA,C++,Python,.NET,BigData,AI】:170933152然后前面我们已经把分布式微服务的,认证授权全部集成了,然后我们来测试.启动资源微服务order微服务.启动网关微服务然后启动注册中心微服务然后注意我们,这里以后访问就可以统一通过网关来访问了,我们网关的端口是53010 对吧,我们先去请求一个令牌可以看到.我们通过密码模式.获取了这个令牌以后,我们去check检查一下这个token,可以看到把token._spring security oauth2.0实现分布式系统授权(nacos注册中心+网关+认证授权服务(j

Oracle_oracle left join 临时表-程序员宅基地

文章浏览阅读278次。Oracle一、Oracle语句关系型数据库:mysql,oracle,sqlserver非关系型数据库:mogodbSQL支持下列类别的命令:数据定义语言(DDL):create创建,alter修改,drop删除数据操作语言(DML):insert 、select、update、delete事务控制语言(TCL):commit 提交;rollback回滚数据控制语言(DCL):grant授权;revoke撤销sql:结构化查询语言数据类型;字符:char(定长度)_oracle left join 临时表

基于tensorflow的keras中GPU的使用_keras 识别检测时需要用gpu吗-程序员宅基地

文章浏览阅读1.8w次。在基于tensorflow的keras中,其会自动检测运行的机器中是否有gpu,如果有的话,其会自动在gpu上执行运算。但是keras并没有提供像基于theano如下所示的接口来对要运行的gpu进行选择# the name 'gpu' might have to be changed depending on your device's identifier (e.g. gpu0, gpu1, et_keras 识别检测时需要用gpu吗

03 一些常用的gulp插件-程序员宅基地

文章浏览阅读463次。首发于github于gulp的插件数量虽然没有grunt那么多,但也可以说是应有尽有了,下面列举一些常用的插件。_gulp插件

elasticsearch初探-程序员宅基地

文章浏览阅读168次。1.es大致介绍 分布式搜索引擎,底层为lucene,核心思想多台机器启动多个es进程构成集群. index->type->mapping->document->field shard 横向扩展 提高性能 primary shard-> replica shard 高可用2.写入原理,查询...

Python: PS 滤镜--万花筒效果-程序员宅基地

文章浏览阅读402次。本文用 Python 实现 PS 的一种滤镜效果,称为万花筒。也是对图像做各种扭曲变换,最后图像呈现的效果就像从万花筒中看到的一样:图像的效果可以参考之前的博客:http://blog.csdn.net/matrix_space/article/details/46789783import matplotlib.pyplot as pltfrom..._opencv 万花筒

随便推点

论文浅尝 - EMNLP2020 | 通过词重排序跨语言解析-程序员宅基地

文章浏览阅读280次。笔记整理 | 吴林娟,天津大学硕士来源:EMNLP2020链接:https://www.aclweb.org/anthology/2020.findings-emnlp.265.pdf动..._吴林娟 天津大学

python中sklearn包计算AUC——sklearn.metrics.auc函数解析_sklearn auc-程序员宅基地

文章浏览阅读1.3w次,点赞8次,收藏22次。代码示例:sklearn.metrics.auc函数的输入是FPR和TPR的值,即ROC曲线中的真阳性率(true positive rate)和假阳性率(false positive rate)。得到的输出结果是一个float格式的数值,代指ROC曲线下的面积(AUC的值)。python所给的代码示例中用到了metrics.roc_curve函数,这个函数主要是用来计算ROC曲线面积的;在这里的输入参数有三个:第一个参数是一个二进制数组y,代表“真”或“假”,默认为0或者1的._sklearn auc

素数筛-程序员宅基地

文章浏览阅读46次。埃氏筛法const int max1=1e7;int prime[max1+1];bool visit[max1+1];int E_sieve(int n){ for(int i=0; i<=n; i++) { visit[i]=false; } for(int i=2; i*i<=n; i++) { if(!visit[i]) { for(int j=i*i; j&_素数筛

vue3+element-plus实现form表单提交_element-plus form submit-程序员宅基地

文章浏览阅读2.2w次,点赞19次,收藏48次。vue2.0可以使用this,如果配合element的form表单的话,会比较方便,至于写这次的笔记是因为,3.0使用setup()以后不存在this,里面的model以及rules校验,最后的提交都跟之前有所不同,故有此文章。vue2.0配合element的代码如下<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm"> <el-fo_element-plus form submit

sublime 文件路径_如何在Sublime文本中快速插入文件路径[Quicktip]-程序员宅基地

文章浏览阅读1.1k次。Sublime Text是一个非常小的代码编辑器。 它没有很多GUI。 甚至设置都是以基于文本的方式完成的。 这种极简主义有助于我们将更多的精力集中在编写代码上,而不会因代码编辑器的外观而分心。 但这还带来了一个问题: 我们如何插入文件路径? 其他代码编辑器,例如Coda ,允许您通过简单的拖放操作为图像或样式表插入文件路径,只需将文件拖放到工作区即可。 另一方面,Sublime Te..._sublime text加入电脑路径

SpringBoot 视频(廖师兄)_2小时学会springboot 廖师兄 视频哪里有-程序员宅基地

文章浏览阅读654次。1-1 Springboot引见.mp42-1 第一个SpringBoot应用.mp43-1 项目属性配置.mp44-1 Controller运用.mp45-1 数据库操作(上).mp45-2 数据库操作(下).mp46-1 事务管理.mp47-1 课程回顾.mp4百度网盘..._2小时学会springboot 廖师兄 视频哪里有

推荐文章

热门文章

相关标签