Amazon Data Pipeline:如何在 SqlActivity 中使用脚本参数?

2023-11-25

尝试在 sqlActivity 中使用脚本参数时:

 {
"id" : "ActivityId_3zboU",
  "schedule" : { "ref" : "DefaultSchedule" },
  "scriptUri" : "s3://location_of_script/unload.sql",
  "name" : "unload",
  "runsOn" : { "ref" : "Ec2Instance" },
  "scriptArgument" : [ "'s3://location_of_unload/#format(minusDays(@scheduledStartTime,1),'YYYY/MM/dd/hhmm/')}'", "'aws_access_key_id=????;aws_secret_access_key=*******'" ],
  "type" : "SqlActivity",
  "dependsOn" : { "ref" : "ActivityId_YY69k" },
  "database" : { "ref" : "RedshiftCluster" }
}

其中 unload.sql 脚本包含:

 unload ('
    select *
    from tbl1 
 ')  
 to ?
 credentials  ?
 delimiter ',' GZIP;

or :

 unload ('
    select *
    from tbl1 
 ')  
 to ?::VARCHAR(255)
 credentials  ?::VARCHAR(255) 
 delimiter ',' GZIP;

进程失败:

syntax error at or near "$1" Position

知道我做错了什么吗?


这是在 psql shell 中运行良好的脚本:

insert into tempsdf select * from source where source.id = '123';

这是我的一些测试sql活动使用数据管道:


Test 1: 使用?'s

insert into mytable select * from source where source.id = ?;- 如果通过 SqlActivity 对象上的“script”和“scriptURI”选项使用,则工作正常。

where "ScriptArgument" : "123"

这里 ?可以替换条件的值,但不能替换条件本身。


Test 2 : Using 参数仅当使用“脚本”选项指定命令时才有效

insert into #{myTable} select * from source where source.id = ?;- 如果仅通过“脚本”选项使用则工作正常

insert into #{myTable} select * from source where source.id = #{myId};
  • 如果仅通过“脚本”选项使用则工作正常

where #{myTable} , #{myId}是可以在模板中声明其值的参数。

http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-custom-templates.html

(当您仅使用参数时,请确保删除未使用的 scriptArguments - 否则它仍然会抛出错误)


失败的测试和推论:

插入 ?从源中选择 *,其中 source.id = ?;

插入 ?从源中选择 *,其中 source.id = '123';

上面的两个命令都不起作用,因为

表名称不能用作脚本参数的占位符。 '?' 只能用于传递比较条件和列值的值。


插入#{myTable} select * from source where source.id = #{myId}; - 如果用作“SciptURI”则不起作用

插入到 tempsdf select * from source where source.id = #{myId}; - 与“ScriptURI”一起使用时不起作用

上面 2 个命令不起作用,因为

如果脚本存储在 S3 中,则无法评估参数。


插入到 tempsdf select * from source where source.id = $1 ; - 不适用于“scriptURI”

插入 tempsdf 值 ($1,$2,$3); - 不起作用。

使用 $'s - 在任何组合中都不起作用


其他测试:

“脚本参数”:“123” “脚本参数”:“456” “脚本参数”:“789”

insert into tempsdf values (?,?,?);- 既可用作 scriptURI ,也可用作 script 并转换为insert into tempsdf values ('123','456','789');

scriptArguments 将遵循您插入的顺序并替换“?”在 剧本。


本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Amazon Data Pipeline:如何在 SqlActivity 中使用脚本参数? 的相关文章

随机推荐