sqoop从HDFS导出数据到oracle时无法将long转换为timestamp
sqoop can't convert long to timestamp when export data from HDFS to oracle
我在 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 模式:
根据 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 导出命令将失败。因此,您必须将文件中的时间戳格式化为符合上述格式才能正确导出到 Oracle。
我在 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 模式:
根据 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 导出命令将失败。因此,您必须将文件中的时间戳格式化为符合上述格式才能正确导出到 Oracle。