以下是我用python编写的SQOOP代码的链接:
在其中一部分中,我正在创建一个sqoop命令列表,该命令将在Linux服务器中执行:
def sqoop_job(table_name):
#The last value which was loaded into the Data Hub is picked from the SQOOP Audit Table which holds the details from the last run.
lastvalue =last_value(table_name)
#Last Update Date is fetched from the source and this is also updated into the SQOOP Audit Table.
last_update_date = max_load_date(table_name)
#print(last_update_date)
init_query = create_query(table_name)
final_query = init_query+"'"+lastvalue+"'"+','+"'"+"DD/MM/YYYY HH24:MI:SS""'"+')'+' AND $CONDITIONS'
print(final_query)
cmd = ['sqoop', 'import', '-Dhadoop.security.credential.provider.path='+alias_provider, '--connect', oracle_url, '--username', username,'--password-alias', password_alias,'-m', '1', '--as-textfile','--target-dir', target_dir_incr+'/'+table_name, '--query',final_query]
#
问题是该列表在查询中打印了转义字符:
['sqoop', 'import', u'-Dhadoop.security.credential.provider.path=jceks://hdfs/tmp/symf.password.jceks', '--connect', u'jdbc:oracle:thin:@sl09.atradiusnet.com:1519/SYMF.atradiusnet.com', '--username', u'NLSMAY1', '--password-alias', u'symf.db.alias', '-m', '1', '--as-textfile', '--target-dir', u'/user/incoming_data/native_zone/symphony/incremental/TBOR_CURRENCY_EXCHANGE_RATES', '--query', u'"select ORCUY_CODE,ORCUY_CODE_BASE,TYP,EFFECT_TO_DAT,ORSUS_ID,EFFECT_FROM_DAT,AMT,LAST_UPDATE_DAT,LAST_UPDATE_SEQ ,current_timestamp, \'NLSMAY1\' from ORABUP0.TBOR_CURRENCY_EXCHANGE_RATES a where last_update_dat > to_timestamp(\'05/10/2018 15:13:05\',\'DD/MM/YYYY HH24:MI:SS\') AND $CONDITIONS']
现在查询部分在Oracle数据库中使用转义符执行,而这在oracle中失败:
Executing SQL statement: "select BUPIY_ID,EFFECT_FROM_DAT,EFFECT_TO_DAT,BUSINESS_TYP,ORSUS_ID,LAST_UPDATE_DAT ,current_timestamp, \'NLSMAY1\' from ORABUP0.TBPO_POL_BUSINESS_TYPES a where last_update_dat > to_timestamp(\'12/10/2018 20:42:59\',\'DD/MM/YYYY HH24:MI:SS\') AND (1 = 0)
有人可以帮我解决这个问题吗?