Sqoop导入HDFS格式问题

12 篇文章 0 订阅

(1)使用Text格式

sqoop import --connect jdbc:oracle:thin:@//IP:1521/ASMP2 --username --password --query "SELECT * FROM SBPOPT.TT_MAINTENANCE_TIMES_CORRECT where \$CONDITIONS" --fields-terminated-by '\t' --delete-target-dir --target-dir /user/asmp/hive/asmp/tt_maintenance_times_correct -m 1 

导入到HDFS结果如下:
在这里插入图片描述
原本Oracle是NULL的字段,被转成字符串"null",结果我在SQL使用
NVL(c.business_correct_times,c.sys_definition_times) 才发现针对 null 无效。。。

(2)只能换成Parquet格式

sqoop import --connect jdbc:oracle:thin:@//IP:1521/ASMP2 --username --password --query "SELECT * FROM SBPOPT.TT_MAINTENANCE_TIMES_CORRECT where \$CONDITIONS" --as-parquetfile --delete-target-dir --target-dir /user/asmp/hive/asmp/tt_maintenance_times_correct -m 1 

导入到HDFS结果如下:
在这里插入图片描述

Hive建表语句:(字段类型必须和sqoop导出的文件保持一致)

drop table asmp.tt_maintenance_times_correct;
create external table if not exists asmp.tt_maintenance_times_correct
(
id	string,
product_code	string,
product_name	string,
first_billing_date	bigint,
last_billing_date	bigint,
sale_amount	string,
sys_definition_times	string,
business_correct_times	string,
correct_status	string,
correct_date	bigint,
correct_people	string,
create_by	string,
create_date	bigint,
update_by	string,
update_date	bigint
) COMMENT 'asmp临时表'
STORED AS parquet
location '/user/asmp/hive/asmp/tt_maintenance_times_correct';

如果oracle表中字段中会有换行符,会导致数据存入hive后,条数增多(每个换行符前后拆分成两行),所以需要特殊字符处理,方法如下:

#对换行等特殊字符的替换成" "
--hive-delims-replacement " "
#对换行等特殊字符删除
--hive-drop-import-delims
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好,要将HDFS上的数据导入到Hive中,可以使用Sqoop工具。Sqoop是一个用于在Hadoop和关系型数据库之间进行数据传输的工具。 以下是使用Sqoop导入HDFS数据到Hive的一般步骤: 1. 确保您已经安装并配置好了Sqoop和Hive。 2. 在终端中使用以下命令执行Sqoop导入操作: ``` sqoop import \ --connect jdbc:mysql://mysql_host:port/database \ --username username \ --password password \ --table table_name \ --hive-import \ --hive-table hive_table_name \ --hive-overwrite ``` 其中,`mysql_host`是MySQL数据库的主机名,`port`是MySQL的端口号,`database`是要导入的数据库名称,`username`和`password`是连接MySQL所需的用户名和密码,`table_name`是要导入的MySQL表名,`hive_table_name`是要在Hive中创建的表名。 3. 根据需要,您可以为Sqoop导入操作提供其他参数,如`--target-dir`来指定HDFS中的目标目录,以及其他Sqoop支持的参数。可以使用`sqoop import --help`命令查看完整的参数列表。 4. 执行命令后,Sqoop将会从MySQL数据库中抽取数据,并将其存储在HDFS上的目标目录中。然后,它将自动在Hive中创建一个与MySQL表结构相匹配的表,并将数据加载到该表中。 请注意,上述命令中的参数和示例是基于MySQL数据库的。如果您使用其他类型的关系型数据库,请根据需要修改连接字符串和其他参数。 希望这些信息对您有所帮助!如果您还有其他问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值