简体   繁体   English

如何将 JSON 传递到 Azure 数据工厂 V2 中嵌入动态内容的 Azure 函数

[英]How to pass JSON into an Azure Function with embedded dynamic content in Azure Data Factory V2

In ADFv2 I'm looking up a date and passing it to an Azure Function.在 ADFv2 中,我正在查找日期并将其传递给 Azure 函数。 I can pass just the data like so:我可以像这样传递数据:

@activity('GetLastDateProcessed').output.firstRow.LastDateProcessed

However if I embed this into a JSON string like this:但是,如果我将其嵌入到这样的 JSON 字符串中:

{"lastProcessDate":"@activity('GetLastDateProcessed').output.firstRow.LastDateProcessed"}

I get this {"lastProcessDate":"@activity('GetLastDateProcessed').output.firstRow.LastDateProcessed"} instead of {"lastProcessDate":"2019-11-13"} as input into function.我得到这个 {"lastProcessDate":"@activity('GetLastDateProcessed').output.firstRow.LastDateProcessed"} 而不是 {"lastProcessDate":"2019-11-13"} 作为函数的输入。

Last I've tried to use a parameter with no success also.最后我尝试使用一个参数也没有成功。

@concat('{"lastProcessDate":"', string(pipeline().parameters.lastProcessDate), '"}')

The problem here is the parameter was not set.这里的问题是没有设置参数。 I set the parameter like this:我这样设置参数:

@activity('GetLastDateProcessed').output.firstRow.LastDateProcessed

在此处输入图片说明 However this is a default value and is never dynamically updated.然而,这是一个默认值,永远不会动态更新。 If I can update this string then the @concat method will work, but haven't been able to figure out how to dynamically update a parameter for the pipeline.如果我可以更新此字符串,那么@concat 方法将起作用,但无法弄清楚如何动态更新管道的参数。

Another option could be a pipeline variable, but I don't know how to reference the variable.另一种选择可能是管道变量,但我不知道如何引用该变量。

How do I concat strings together with dynamic content?如何将字符串与动态内容连接在一起?

I was able to get this to work by creating a second pipeline.我能够通过创建第二条管道来实现这一点。 This is not optimal, but works for people running into this same issue.这不是最佳的,但适用于遇到同样问题的人。 Hopefully someone finds a better solution than this!希望有人能找到比这更好的解决方案!

From the first pipeline I set the second pipelines parameter with this:从第一个管道我设置了第二个管道参数:

@activity('GetLastDateProcessed').output.firstRow.LastDateProcessed

I named the parameter in the second pipeline lastProcessDate so then this worked:我将第二个管道中的参数命名为 lastProcessDate ,这样就可以了:

@concat('{"lastProcessDate":"', string(pipeline().parameters.lastProcessDate), '"}')

This is not straight forward and can't be how Microsoft is expecting us to solve this!这不是直截了当的,不可能是微软期望我们解决这个问题的方式!

I think what you are missing is that when you use the at-sign '@' in the json string you should follow it with a curly bracket '{'我认为您缺少的是,当您在 json 字符串中使用 at-sign '@' 时,您应该在它后面加上一个大括号 '{'

In your example it will look something like this:在您的示例中,它看起来像这样:

{"lastProcessDate":"@{activity('GetLastDateProcessed').output.firstRow.LastDateProcessed}"}

here is the source (found it in the comments): https://azure.microsoft.com/en-us/blog/azure-functions-now-supported-as-a-step-in-azure-data-factory-pipelines/#:~:text=Azure%20Data%20Factory%20(ADF)%20is,in%20your%20data%20factory%20pipelines .这是来源(在评论中找到): https : //azure.microsoft.com/en-us/blog/azure-functions-now-supported-as-a-step-in-azure-data-factory-管道/#:~:text=Azure%20Data%20Factory%20(ADF)%20is,in%20your%20data%20factory%20pipelines

I was able to achieve this with command.我能够通过命令实现这一点。

{
  "storedprocedure":"storedProcName",
  "params":"@{variables('currentDt')}"
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM