sqoop在将数据从hdfs导出到oracle时不能将long转换为timestamp

qqrboqgw  于 2021-06-03  发布在  Sqoop
关注(0)|答案(1)|浏览(672)

我有一个hdfs格式的csv文件:

000000131,2020-07-22,0.0,"","",1595332359218,khf987ksdfi34
000000112,2020-07-22,0.0,"","",1595442610265,khf987ksdfi34
000000150,2020-07-22,0.0,"","",1595442610438,khf987ksdfi34

我想使用sqoop将此文件导出到oracle,如下所示:

sqoop export --connect "jdbc:oracle:thin:@(description=(address=(protocol=tcp)(host=oracledb)(port=1521))(connect_data=(service_name=stgdb)))" --table CORE_ETL.DEPOSIT_TURNOVER --username xxxx --password xxxx --export-dir /tmp/merged_deposit_turnover/ --input-fields-terminated-by "," --input-lines-terminated-by '\n' --input-optionally-enclosed-by '\"' --map-column-java DATE=java.sql.Date,INSERT_TS=java.sql.Timestamp

但过程以以下错误结束:

Caused by: java.lang.RuntimeException: Can't parse input data: '1595332359218' at 
CORE_ETL_DEPOSIT_TURNOVER.__loadFromFields(CORE_ETL_DEPOSIT_TURNOVER.java:546) at 
CORE_ETL_DEPOSIT_TURNOVER.parse(CORE_ETL_DEPOSIT_TURNOVER.java:431) at   
org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:88) ... 10 more Caused 
by: java.lang.IllegalArgumentException at java.sql.Date.valueOf(Date.java:143) at 
CORE_ETL_DEPOSIT_TURNOVER.__loadFromFields(CORE_ETL_DEPOSIT_TURNOVER.java:529) ... 12 more

我想知道有没有一种不改变hdfs中数据格式的方法,我可以将这个文件导出到oracle。
也包括oracle架构:

eimct9ow

eimct9ow1#

根据sqoop官方文件:https://sqoop.apache.org/docs/1.4.6/sqoopuserguide.html#_export_date_and_timestamp_data_types_into_oracle
从hdfs导出数据时,如果数据不是所需格式,并且时间戳的所需格式为:yyyy-mm-dd hh24:mi:ss.ff,则sqoop export命令将失败。因此,您必须格式化文件中的时间戳,以符合上述格式,才能正确地导出到oracle。

相关问题