本文介绍了Azure | ADF |如何使用String变量在Object类型的Parameter中查找键并检索其值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Azure数据工厂.我正在尝试使用String变量在JSON数组中查找Key并检索其Value.我似乎无法弄清楚如何在ADF中执行此操作.

I am using Azure Data Factory. I'm trying to use a String variable to lookup a Key in a JSON array and retrieve its Value. I can't seem to figure out how to do this in ADF.

详细信息:

我已经定义了一个名为"obj"的管道参数,键入"Object"和内容:{"values":{"key1":"value1","key2":"value2"}}

I have defined a Pipeline Parameter named "obj", type "Object" and content: {"values":{"key1":"value1","key2":"value2"}}

参数定义

我需要使用此管道来查找名为"key1"的值,并将其返回为"value1"; "key2"并将其返回为"value2" ...,依此类推.我打算将我的"obj"用作字典,以实现此目的.

I need to use this pipeline to find a value named "key1" and return it as "value1"; "key2" and return it as "value2"... and so on. I'm planning to use my "obj" as a dictionary, to accomplish this.

从技术上讲,如果我想找到key2的值,我可以使用下面的代码,它将返回"value2":

Technically speaking, If i want to find the value for key2, I can use the code below, and it will be returned "value2":

@pipeline().parameters.obj.values.key2

我不知道的是如何使用变量(而不是硬编码的"key2")来做到这一点.

What i can't figure out is how to do it using a variable (instead of hardcoded "key2").

要清除这些内容:我有一个for循环,并且在其中有一个复制活动:每个内容复制活动的目的是复制名为item().name的文件,但要根据

To clear things out: I have a for-loop and, inside it, i have just a copy activity: for-each contentsThe purpose of the copy activity is to copy the file named item().name, but save it in ADLS as whatever item().name translates to, according to "obj"

这是使用Python构建for循环的方式: python-for-loop

This is how the for-loop could be built, using Python: python-for-loop

在ADF中,我尝试了很多操作(使用concat,replace ...),但没有任何效果.最简单的是:

In ADF, I tried a lot of things (using concat, replace...), but none worked. The simpliest woult be this:

@pipeline().parameters.obj.values.item().name

但是会引发以下错误:

{"code":"BadRequest","message":"ErrorCode=InvalidTemplate, ErrorMessage=Unable to parse expression 'pipeline().parameters.obj.values.item().name'","target":"pipeline/name_of_the_pipeline/runid/run_id","details":null,"error":null}

那么,您能给我一些如何定义我的表情的想法吗?我觉得这一定很明显,但我没到那里.....谢谢.

So, can you please give any ideas how to define my expression? I feel this must be really obvious, but I'm not getting there..... Thanks.

推荐答案

Pythonista朋友们!

Hello fellow Pythonista!

ADF中的解决方案实际上就像在Python中一样,将方括号内的变量"括起来.

The solution in ADF is actually to reference just as you would in Python by enclosing the 'variable' in square brackets.

我创建了一个像您一样的参数obj的管道

I created a pipeline with a parameter obj like yours

作为演示,管道具有单个 Set Variable 活动,该活动将key2的值转换为变量.

and, as a demo, the pipeline has a single Set Variable activity that got the value for key2 into a variable.

已对此进行了记录,但是您需要X射线检查才能发现它此处.

This is documented but you need X-ray vision to spot it here.

这篇关于Azure | ADF |如何使用String变量在Object类型的Parameter中查找键并检索其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:06