【Hive |
您所在的位置:网站首页 › 怎么把本地文件导入虚拟机上去 › 【Hive |
表数据的导出、导入(HDFS、本地)
一、数据导入1.1 向表中装载数据(Load)1.2 通过查询语句向表中插入数据(Insert)1.3 查询语句中创建表并加载数据(As Select)1.4 创建表时通过Location指定加载数据路径1.5 Import数据到指定Hive表中
二、数据导出2.1 Insert导出2.2 Hadoop命令导出到本地2.3 Hive Shell 命令导出2.4 Export导出到HDFS上2.5 Sqoop导出
一、数据导入
1.1 向表中装载数据(Load)
1)语法 load data [local] inpath '数据的path' [overwrite] into table student [partition (partcol1=val1,…)];(1)load data:表示加载数据 (2)local:表示从本地加载数据到hive表;否则从HDFS加载数据到hive表 (加local是从本地复制过去,不加local是从hdfs上剪切过去) (3)inpath:表示加载数据的路径 (4)overwrite:表示覆盖表中已有数据,否则表示追加 (overwrite会把之前的数据文件删除,在把新的数据文件传上去) (5)into table:表示加载到哪张表 (6)student:表示具体的表 (7)partition:表示上传到指定分区 2)实操案例 (1)加载本地文件到hive load data local inpath '/opt/module/hive/datas/student.txt' into table student;(2)加载HDFS文件到hive中 # 上传文件到HDFS hadoop fs -put /opt/module/hive/datas/student.txt /user/qinjl; # 加载HDFS上数据,导入完成后去hdfs查看文件是否还存在 load data inpath '/user/qinjl/student.txt' into table student;(3)加载数据覆盖表中已有的数据 # 上传文件到HDFS hdfs -put /opt/module/hive/datas/student.txt /user/qinjl; # 加载数据覆盖表中已有的数据 load data inpath '/user/qinjl/student.txt' overwrite into table student; 1.2 通过查询语句向表中插入数据(Insert)1)创建一张表 create table student2(id int, name string) row format delimited fields terminated by '\t';2)基本模式插入数据 insert into table student2 values(1,'wangwu'),(2,'zhaoliu');3)根据查询结果插入数据( 插入select的表,的字段、类型要匹配,否则报错) insert overwrite table student2 select id, name from student where id dfs -get /user/hive/warehouse/student/student.txt /opt/module/hive/datas/export/student3.txt; 2.3 Hive Shell 命令导出 基本语法:(hive -f/-e 执行语句或者脚本 >> file) [qinjl@hadoop102 hive]$ bin/hive -e 'select * from default.student;' >> /opt/module/hive/datas/export/student4.txt; 2.4 Export导出到HDFS上 注意:export导出的数据,里面包含了具体数据和元数据 hive (default)> export table default.student to '/user/hive/warehouse/export/student'; export和import主要用于两个Hadoop平台集群之间Hive表迁移,不能直接导出的本地。 2.5 Sqoop导出 |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |