amazon-web-services - 亚马逊数据管道 : How to use a script argument in a SqlActivity?

标签 amazon-web-services amazon-s3 amazon-redshift amazon-data-pipeline

尝试在 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;

或者 :
 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';

以下是我使用 Data-Pipelines 对 SqlActivity 进行的一些测试:

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

哪里 "ScriptArgument" : "123"
这里 ?可以替换条件的值,但不能替换条件本身。

测试 2:使用 参数 在仅使用 'script' 选项指定命令时有效
insert into #{myTable} select * from source where source.id = ?; - 如果仅通过“脚本”选项使用,则工作正常
insert into #{myTable} select * from source where source.id = #{myId};

如果仅通过“脚本”选项使用
  • 工作正常

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

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

    (when you are using only parameters, make sure you delete an unused scriptArguments - otherwise it will still throw and error)



    失败的测试和推论:

    插入 ? select * from source where source.id = ?;

    插入 ? select * from source where source.id = '123';

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

    Table names cannot be used for placeholders for script arguments. '?''s can only be used to pass values for a comparison condition and column values.



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

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

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

    Parameters cannot be evaluated if script is stored in S3.



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

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

    using $'s - doesn't not work in any combination



    其他测试:

    “脚本参数”:“123”
    “脚本参数”:“456”
    “脚本参数”:“789”
    insert into tempsdf values (?,?,?); - 作为 scriptURI 、 script 并转换为 insert into tempsdf values ('123','456','789');

    scriptArguments will follow the order you insert and replaces "?" in the script.

    关于amazon-web-services - 亚马逊数据管道 : How to use a script argument in a SqlActivity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27481264/

    相关文章:

    amazon-web-services - 使用 Elastic Beanstalk 全局安装包

    node.js - 无法在 serverless.yml 中引用 CloudFormation 资源。变量 UserPoolId 的变量引用语法无效

    amazon-web-services - 在 CloudFront 中更改 "Origin Path"需要很长时间才能启动

    java - 用于授予图片访问权限的 S3 存储桶签名 URL

    sql - 需要对某个日期期间的行进行计数,然后根据该日期期间使用其他条件的情况对行进行计数

    amazon-web-services - 如何检测Azure/Amazon VM

    Java:如何处理可能需要大约 10 秒的 API 调用

    javascript - S3 替代方案,允许在不缓冲的情况下上传流文件

    sql - 为什么在 RedShift 中的事务结束之前释放隐式表锁?

    apache-spark - 如何在 Amazon EMR 集群上使用 Spark 连接到 redshift 数据