Azure Data Factory: For each item() value does not exist for a particular attribute

扶醉桌前 提交于 2019-12-13 04:04:00

问题


I have a for each activity which has a stored procedure (SP) wherein I am inputing values using item() evidently.

Now suppose SP's input values are item().a, item().b and item().c

Question: For some of the iteration of foreach, item().b does not exist which is expected. So how should i deal with it in the Stored procedure? Because at this point of time it is giving me an error when it executed SP by saying:

"The template language expression 'item().b' cannot be evaluated because property 'b' doesn't exist, available properties are 'a, c'

or how should I overcome this failure in the data factory?

Apparently, data factory has the check for empty() but it does not have the check for exist().


回答1:


You could use “?”. I.e., item()?.b

Please reference question mark and a related post.




回答2:


I don't think you can solve this in the Data Factory. You could use the String(Item()) to convert it to a Json string in the format:

{
    'a':'value',
    'b':'value',
    'c':'value'
}

Then you can handle that in your stored procedure with some creative SQL:

DECLARE @jsonParams NVARCHAR(255) = '
    {
        "a":"a value",
        "c":"b value"
    }' 


DECLARE @paramA VARCHAR(10) = (SELECT JSON_VALUE(@jsonParams,'$.a'))
DECLARE @paramB VARCHAR(10) = (SELECT JSON_VALUE(@jsonParams,'$.b'))
DECLARE @paramC VARCHAR(10) = (SELECT JSON_VALUE(@jsonParams,'$.c'))


来源:https://stackoverflow.com/questions/51222698/azure-data-factory-for-each-item-value-does-not-exist-for-a-particular-attrib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!