一个双引号引发的血案---sqoop从mysql导入数据到hdfs

出现的错误

Warning: /opt/cloudera/parcels/CDH-5.9.0-1.cdh5.9.0.p0.23/bin/../lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
20/04/23 18:27:25 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6-cdh5.9.0
20/04/23 18:27:25 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
20/04/23 18:27:25 ERROR tool.BaseSqoopTool: Error parsing arguments for import:
20/04/23 18:27:25 ERROR tool.BaseSqoopTool: Unrecognized argument: 16:58:46.0

执行的脚本方法

MAX_V--------表示查询hive中表中最大的时间(时间是String类型)

下边的方法看似问题不大,导入的mysql表中EntryTime是datetime类型 

"--incremental lastmodified  --check-column EntryTime  --last-value ${MAX_V}" --做的是一个增量导入---问题也不是很大

function import_table(){

MAX_V=`hive -e "select max(entrytime) from raw_ientrancerecord.accecon_entryrecorddetail where entrytime!='默认'"`

fn_log "表中最大的ID 是: ${MAX_V} "

   sqoop import --hive-import --connect 'jdbc:mysql://127.0.0.1:3306/ientrancerecord?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&transformedBitIsBoolean=true&tinyInt1isBit=false'  \
    --username xxxx \
    --password xxxx \
    --driver com.mysql.jdbc.Driver \
    --query " SELECT  r.* FROM accecon_entryrecorddetail r  WHERE 1=1 and r.EntryTime !='0000-00-00 00:00:00'  and \$CONDITIONS" \
    --hive-table raw_ientrancerecord.accecon_entryrecorddetail -m 1  \
    --target-dir "/user/hive/dataTempA" \
    --input-null-string '\\N' --input-null-non-string '\\N' --null-string '\\N' --null-non-string '\\N' --hive-drop-import-delims --fields-terminated-by '\0001' \
    --incremental lastmodified  --check-column EntryTime  --last-value ${MAX_V};
}

一直在怀疑 entrytime的类型,跑到hive上确认是string类型,随后怀疑到 --last-value ${MAX_V} 所以在这个地方先写死

 --last-value '2020-04-23 18:10:38.0'

function import_table(){

MAX_V=`hive -e "select max(entrytime) from raw_ientrancerecord.accecon_entryrecorddetail where entrytime!='默认'"`

fn_log "表中最大的ID 是: ${MAX_V} "

   sqoop import --hive-import --connect 'jdbc:mysql://127.0.0.1:3306/ientrancerecord?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&transformedBitIsBoolean=true&tinyInt1isBit=false'  \
    --username xxxx \
    --password xxxx \
    --driver com.mysql.jdbc.Driver \
    --query " SELECT  r.* FROM accecon_entryrecorddetail r  WHERE 1=1 and r.EntryTime !='0000-00-00 00:00:00'  and \$CONDITIONS" \
    --hive-table raw_ientrancerecord.accecon_entryrecorddetail -m 1  \
    --target-dir "/user/hive/dataTempA" \
    --input-null-string '\\N' --input-null-non-string '\\N' --null-string '\\N' --null-non-string '\\N' --hive-drop-import-delims --fields-terminated-by '\0001' \
    --incremental lastmodified  --check-column EntryTime  --last-value '2020-04-23 18:10:38.0';
}

惊奇的发现,一点问题也没有,咦----,到了这一步,就要大胆的想出来,同事的脑洞大开,外边加个双引号("")试试,如下:

 --last-value "${MAX_V}"

果不其然,执行成功了!!!奥利给!!!

发布了1 篇原创文章 · 获赞 0 · 访问量 23

猜你喜欢

转载自blog.csdn.net/fxl3511/article/details/105714659