gpt4 book ai didi

amazon-web-services - AWS Step 函数和 Athena : can I configure query string from inputpath?

转载 作者:行者123 更新时间:2023-12-05 01:54:22 25 4
gpt4 key购买 nike

在我的步骤函数中,我想执行一个 Athena 查询。我能够定义一个步骤并成功执行查询。但是,我想将一些参数作为输入传递并在查询字符串中使用它们。例如。

比方说,我的查询字符串是:

select * from <Data Source>.<database>.<tablename> where partition_0 = '2021';

我希望能够将年份作为输入 json 传递给步骤函数,例如:

{
"YYYY": 2021
}

是否可以在查询字符串中插入输入“YYYY”?如果是,怎么办?

示例步骤功能配置:

{
"Comment": "Start athena exececution",
"StartAt": "athena",
"States": {
"athena": {
"Type": "Task",
"InputPath": "$",
"Resource": "arn:aws:states:::athena:startQueryExecution.sync",
"Parameters": {
"QueryString": "select * from mycatalog.mydatabase.mytable where partition_0 = '2021'",
"WorkGroup": "primary",
"ResultConfiguration": {
"OutputLocation": "s3://mys3bucket"
}
},
"Next": "Pass"
},
"Pass": {
"Comment": "A Pass state passes its input to its output, without performing work. Pass states are useful when constructing and debugging state machines.",
"Type": "Pass",
"End": true
}
}
}

最佳答案

使用 Pass State用查询字符串插入输入 YYYY:

"QueryPassTask": {
"Type": "Pass",
"ResultPath": "$.athena",
"Parameters": {
"query.$": "States.Format('select * from mycatalog.mydatabase.mytable where partition_0 = \\'{}\\'', $.YYYY)"
},

Pass任务输出为:

{
"YYYY": 2021,
"athena": {
"query": "select * from mycatalog.mydatabase.mytable where partition_0 = '2021'"
}
}

接下来,向 Athena 任务提供查询字符串。不要忘记 key 上的“.$”后缀。这会告诉 Step Functions 键的值包含替换。

 "Parameters": {
"QueryString.$": "$.athena.query",

关于amazon-web-services - AWS Step 函数和 Athena : can I configure query string from inputpath?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70691293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com