Azure Data Factory ForEach 解析 QueueMessageList

huangapple go评论68阅读模式
英文:

Azure Data Factory ForEach Parsing QueueMessageList

问题

我正在使用以下动态表达式在ForEach项目中将QueueMessageList中的QueueMessageText提供给后续的管道过程:

@json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage

当QueueMessageList中有多个QueueMessageText时,这个方法运行良好,但当只有一个QueueMessageText时,会出现以下错误信息:

函数'length'期望其参数为数组或字符串。提供的值为'Object'类型

这是单个QuoteMessageText的XML示例:

"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<QueueMessagesList>
	<QueueMessage>
		<MessageId>test1</MessageId>
		<InsertionTime>Thu, 15 Jun 2023 04:21:06 GMT</InsertionTime>
		<ExpirationTime>Thu, 22 Jun 2023 04:21:06 GMT</ExpirationTime>
		<PopReceipt>popreceipt1</PopReceipt>
		<TimeNextVisible>Thu, 15 Jun 2023 04:22:41 GMT</TimeNextVisible>
		<DequeueCount>2</DequeueCount>
		<MessageText>{"sample":"test.txt"}</MessageText>
	</QueueMessage>
</QueueMessagesList>"

而这是包含多个QuoteMessageText的XML示例:

"<?xml version=\"1.0\" encoding=\"utf-8\"?>
<QueueMessagesList>
	<QueueMessage>
		<MessageId>test1</MessageId>
		<InsertionTime>Thu, 15 Jun 2023 04:21:06 GMT</InsertionTime>
		<ExpirationTime>Thu, 22 Jun 2023 04:21:06 GMT</ExpirationTime>
		<PopReceipt>pop1</PopReceipt>
		<TimeNextVisible>Thu, 15 Jun 2023 06:14:57 GMT</TimeNextVisible>
		<DequeueCount>5</DequeueCount>
		<MessageText>{"sample":"test.txt"}</MessageText>
	</QueueMessage>
	<QueueMessage>
		<MessageId>ctest2</MessageId>
		<InsertionTime>Thu, 15 Jun 2023 06:13:39 GMT</InsertionTime>
		<ExpirationTime>Thu, 22 Jun 2023 06:13:39 GMT</ExpirationTime>
		<pop2</PopReceipt>
		<TimeNextVisible>Thu, 15 Jun 2023 06:14:57 GMT</TimeNextVisible>
		<DequeueCount>1</DequeueCount>
		<MessageText>{"sample":"test2.txt"}</MessageText>
	</QueueMessage>
</QueueMessagesList>"

我理解当将XML转换为JSON时,具有多个QueueMessageText的XML会创建一个QueueMessage列表,而只有一个QueueMessageText的XML会创建一个QueueMessageText字典。请告诉我如何修改ForEach Activity的表达式,因为我无法更改QueueMessageList的输出。谢谢!

英文:

I am using the dynamic expression below in ForEach Items to feed QueueMessageText from a QueueMessageList into subsequent pipeline process

@json(xml(activity(&#39;get_queue_message&#39;).output.Response)).QueueMessagesList.QueueMessage

This works well when there are more than 1 QueueMessageText within the QueueMessageList but fails when there is only 1 QueueMessageText with the following error message:

> The function 'length' expects its parameter to be an array or a string. The provided value is of type 'Object'

These is the xml for single QuoteMessageText:

&quot;
&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot;?&gt;
&lt;QueueMessagesList&gt;
	&lt;QueueMessage&gt;
		&lt;MessageId&gt;test1&lt;/MessageId&gt;
		&lt;InsertionTime&gt;Thu, 15 Jun 2023 04:21:06 GMT&lt;/InsertionTime&gt;
		&lt;ExpirationTime&gt;Thu, 22 Jun 2023 04:21:06 GMT&lt;/ExpirationTime&gt;
		&lt;PopReceipt&gt;popreceipt1&lt;/PopReceipt&gt;
		&lt;TimeNextVisible&gt;Thu, 15 Jun 2023 04:22:41 GMT&lt;/TimeNextVisible&gt;
		&lt;DequeueCount&gt;2&lt;/DequeueCount&gt;
		&lt;MessageText&gt;{\&quot;sample\&quot;:\&quot;test.txt\&quot;}&lt;/MessageText&gt;
	&lt;/QueueMessage&gt;
&lt;/QueueMessagesList&gt;&quot;

And this is the xml for multiple QuoteMessageText within 1 list:

&quot;
&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot;?&gt;
&lt;QueueMessagesList&gt;
	&lt;QueueMessage&gt;
		&lt;MessageId&gt;test1&lt;/MessageId&gt;
		&lt;InsertionTime&gt;Thu, 15 Jun 2023 04:21:06 GMT&lt;/InsertionTime&gt;
		&lt;ExpirationTime&gt;Thu, 22 Jun 2023 04:21:06 GMT&lt;/ExpirationTime&gt;
		&lt;PopReceipt&gt;pop1&lt;/PopReceipt&gt;
		&lt;TimeNextVisible&gt;Thu, 15 Jun 2023 06:14:57 GMT&lt;/TimeNextVisible&gt;
		&lt;DequeueCount&gt;5&lt;/DequeueCount&gt;
		&lt;MessageText&gt;{\&quot;sample\&quot;:\&quot;test.txt\&quot;}&lt;/MessageText&gt;
	&lt;/QueueMessage&gt;
	&lt;QueueMessage&gt;
		&lt;MessageId&gt;ctest2&lt;/MessageId&gt;
		&lt;InsertionTime&gt;Thu, 15 Jun 2023 06:13:39 GMT&lt;/InsertionTime&gt;
		&lt;ExpirationTime&gt;Thu, 22 Jun 2023 06:13:39 GMT&lt;/ExpirationTime&gt;
		&lt;pop2&lt;/PopReceipt&gt;
		&lt;TimeNextVisible&gt;Thu, 15 Jun 2023 06:14:57 GMT&lt;/TimeNextVisible&gt;
		&lt;DequeueCount&gt;1&lt;/DequeueCount&gt;
		&lt;MessageText&gt;{\&quot;sample\&quot;:\&quot;test2.txt\&quot;}&lt;/MessageText&gt;
	&lt;/QueueMessage&gt;
&lt;/QueueMessagesList&gt;&quot;

I understand that when i convert the XML to JSON, XML with Multiple QueueMessageText will create a QueueMessage list while XML with single QueueMessageText will create a QueueMessageText dictionary.
Please help me with a suggestion on how to modify the expression for the ForEach Activity as i cannot change the QueueMessageList output.
Thank you

答案1

得分: 0

我已将我的表达修改如下:

@array(json(xml(activity('get_queue_message').output.Response)).QueueMessagesList.QueueMessage)

现在似乎可以工作。

英文:

I have modified my expression as follows:

@array(json(xml(activity(&#39;get_queue_message&#39;).output.Response)).QueueMessagesList.QueueMessage)

It seems to work now.

huangapple
  • 本文由 发表于 2023年6月15日 14:28:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479696.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定