Hive----数据插入、导入、导出

简介: 数据的插入、导入、导出

向表中填充数据:

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

 

load data local inpath '/opt/module/datas/student.txt' into table student;  --hadoop fs -put

load data inpath '/datas/test.txt' into table test2; --hadoop fs -mv

 

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

load data local inpath '/opt/module/datas/test.txt' overwrite into table test; --覆盖原有的数据

load data local inpath '/opt/module/datas/class.txt' into table class_par partition(uyear='2022',umonth='11',uday='02');

 

 

create table c1(udate string,cost string,yue double)

partitioned by(name string)

row format delimited fields terminated by '\t';

 

多分区联合插入:

from tmp

insert into table c1 partition(name='Tomi')

select utime,cost,yue where name='Tomi'

insert into table c1 partition(name='Jony')

select utime,cost,yue where name='Jony'

insert into table c1 partition(name='Lisi')

select utime,cost,yue where name='Lisi';

 

多表联合插入:

create table c2(udate string,name string,cost string,yue double);

create table c3(udate string,name string,cost string,yue double);

create table c4(udate string,name string,cost string,yue double);

 

from tmp

insert into table c2

select utime,name,cost,yue where name='Tomi'

insert into table c3

select utime,name,cost,yue where name='Jony'

insert into table c4

select utime,name,cost,yue where name='Lisi';

 

 

数据的导出:

insert方式:

insert overwrite  local directory '/opt/module/datas/info' row format delimited fields terminated by '\t'

collection items terminated by ','

select children,friends from test;

 

 

export table tmp to '/output';

create table tmp2 like tmp;

import table tmp2 from '/output';

 

导入:

①load 方式:

导入本地数据

导入集群数据

追加方式:load data (local) inpath '/opt/module/datas/student.txt' into table student;

覆盖方式:load data local inpath '/opt/module/datas/student.txt' (overwrite) into table student;

指定分区

 

②insert方式:

追加方式: insert into table student [(字段1,字段2)] values(1,"male"),(2,"female");

覆盖方式: insert overwrite table student values(1,"male"),(2,"female");

insert into table stud

select 1,'张三','1','A' union all

select 2,'李四','2','C' union all

select 3,'王五','1','B' union all

select 4,'黄六','3','D' union all

select 5,'朱八','2','C'

 

③建表时使用as关键字从别的表中查询某些列:create table …… as ……

④建表时通过location关键字指定数据路径:create table …… location ……

⑤import方式(import的数据源必须是export导出的结果目录):

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

 

⑥sqoop工具:

 

 

导出:

 

①insert方式:

导出到本地

insert overwrite local directory '' select * from tmp;

导出到hdfs

insert overwrite  directory '' select * from tmp;

格式化后导出

 

②hadoop命令方式:

hive的命令行

dfs -get /user/hive/warehouse/student/month=201709/000000_0 /opt/module/datas/export/student3.txt;

hadoop的shell命令

hadoop fs -get /user/hive/warehouse/student/month=201709/000000_0 /opt/module/datas/export/student3.txt;

③hive交互命令:

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

 

④export方式:

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

⑤sqoop方式

 

 

目录
相关文章
|
4月前
|
SQL 分布式计算 Hadoop
创建hive表并关联数据
创建hive表并关联数据
60 0
|
1月前
|
SQL 物联网 数据处理
"颠覆传统,Hive SQL与Flink激情碰撞!解锁流批一体数据处理新纪元,让数据决策力瞬间爆表,你准备好了吗?"
【8月更文挑战第9天】数据时代,实时性和准确性至关重要。传统上,批处理与流处理各司其职,但Apache Flink打破了这一界限,尤其Flink与Hive SQL的结合,开创了流批一体的数据处理新时代。这不仅简化了数据处理流程,还极大提升了效率和灵活性。例如,通过Flink SQL,可以轻松实现流数据与批数据的融合分析,无需在两者间切换。这种融合不仅降低了技术门槛,还为企业提供了更强大的数据支持,无论是在金融、电商还是物联网领域,都将发挥巨大作用。
39 6
|
23天前
|
SQL 关系型数据库 HIVE
实时计算 Flink版产品使用问题之如何将PostgreSQL数据实时入库Hive并实现断点续传
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
23天前
|
SQL 分布式计算 数据处理
实时计算 Flink版产品使用问题之怎么将数据从Hive表中读取并写入到另一个Hive表中
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。
|
1月前
|
SQL 存储 分布式计算
|
1月前
|
SQL 存储 监控
Hive 插入大量数据
【8月更文挑战第15天】
|
2月前
|
SQL 关系型数据库 MySQL
实时计算 Flink版操作报错合集之从mysql读数据写到hive报错,是什么原因
在使用实时计算Flink版过程中,可能会遇到各种错误,了解这些错误的原因及解决方法对于高效排错至关重要。针对具体问题,查看Flink的日志是关键,它们通常会提供更详细的错误信息和堆栈跟踪,有助于定位问题。此外,Flink社区文档和官方论坛也是寻求帮助的好去处。以下是一些常见的操作报错及其可能的原因与解决策略。
|
2月前
|
SQL DataWorks 监控
DataWorks产品使用合集之同步数据到Hive时,如何使用业务字段作为分区键
DataWorks作为一站式的数据开发与治理平台,提供了从数据采集、清洗、开发、调度、服务化、质量监控到安全管理的全套解决方案,帮助企业构建高效、规范、安全的大数据处理体系。以下是对DataWorks产品使用合集的概述,涵盖数据处理的各个环节。
|
3月前
|
SQL 分布式计算 HIVE
实时计算 Flink版产品使用问题之同步到Hudi的数据是否可以被Hive或Spark直接读取
实时计算Flink版作为一种强大的流处理和批处理统一的计算框架,广泛应用于各种需要实时数据处理和分析的场景。实时计算Flink版通常结合SQL接口、DataStream API、以及与上下游数据源和存储系统的丰富连接器,提供了一套全面的解决方案,以应对各种实时计算需求。其低延迟、高吞吐、容错性强的特点,使其成为众多企业和组织实时数据处理首选的技术平台。以下是实时计算Flink版的一些典型使用合集。