ADF Contain function with Arrays

Kengie Ho 1 Reputation point
2022-02-19T15:01:06.707+00:00

Hi there,

It seems that the Azure Expression documentation and the actual implmentation is incorrect for the contains expression.

Per documentation (https://learn.microsoft.com/en-us/azure/data-factory/control-flow-expression-language-functions#contains), the second parameter on the parameter lists specify that the type of data can be a 'String, Array or Dictionary, respectively'.

But when using the 'Set Variable' block as a test with the expression @contains(createArray(XXX), createArray(XXXX)), the expression would return false even thou both arrays are the same.

This code works:

{  
    "name": "Set variable1",  
    "type": "SetVariable",  
    "dependsOn": [],  
    "userProperties": [],  
    "typeProperties": {  
        "variableName": "TrueFalse",  
        "value": {  
            "value": "@contains('hello world','hello')",  
            "type": "Expression"  
        }  
    }  
}  

While this would fail:

{  
    "name": "Set variable1",  
    "type": "SetVariable",  
    "dependsOn": [],  
    "userProperties": [],  
    "typeProperties": {  
        "variableName": "TrueFalse",  
        "value": {  
            "value": "@contains(createArray('teammembership'),createArray('teammembership','fctg_user_spokenlanguage','processstage','fctg_fctg_destination_fctg_consultantprofile','fctg_fctg_consultantprofiles_fctg_productcat', 'fctg_fctg_consultantprofiles_fctg_spokenlang','activityparty','arb_incident_fctg_quote'))",  
            "type": "Expression"  
        }  
    }  
}  

This would also fail (flipping parameter A and parameter B):

{  
    "name": "Set variable1",  
    "type": "SetVariable",  
    "dependsOn": [],  
    "userProperties": [],  
    "typeProperties": {  
        "variableName": "TrueFalse",  
        "value": {  
            "value": "@contains(createArray('teammembership','fctg_user_spokenlanguage','processstage','fctg_fctg_destination_fctg_consultantprofile','fctg_fctg_consultantprofiles_fctg_productcat', 'fctg_fctg_consultantprofiles_fctg_spokenlang','activityparty','arb_incident_fctg_quote'), createArray('teammembership'))",  
            "type": "Expression"  
        }  
    }  
}  
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,681 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AnnuKumari-MSFT 32,906 Reputation points Microsoft Employee
    2022-02-22T12:06:02.227+00:00

    Hi @Kengie Ho ,
    Thankyou for using Microsoft Q&A platform and posting your query.
    As per my understanding about your query , contains function in ADF is not working as expected and as is mentioned in the Microsoft documentation.
    I tried to repro the same scenario as you did. I created a variable with the datatype as 'boolean' and when I use set variable and supply array in both 'collection' and 'value' ,it returns False for the expression:

    @contains(createArray('teammembership','fctg_user_spokenlanguage','processstage','fctg_fctg_destination_fctg_consultantprofile','fctg_fctg_consultantprofiles_fctg_productcat', 'fctg_fctg_consultantprofiles_fctg_spokenlang','activityparty','arb_incident_fctg_quote'), createArray('teammembership'))  
    

    whereas when I supply 'collection' as array and 'value' parameter as string , it returns True for the expression:

    @contains(createArray('teammembership','fctg_user_spokenlanguage','processstage','fctg_fctg_destination_fctg_consultantprofile','fctg_fctg_consultantprofiles_fctg_productcat', 'fctg_fctg_consultantprofiles_fctg_spokenlang','activityparty','arb_incident_fctg_quote'), 'teammembership')  
    

    However, in the first case the reason it gave false is because in example you are looking for an "array" inside the "array of strings". so in simple True is expected in the following case: [['teammembership'],'fctg_user_spokenlanguage','processstage'..] where it does not contain 'teammembership' but ['teammembership'].

    So this is the correct code you need to use:

    @contains(createArray(createArray('teammembership'),'fctg_user_spokenlanguage','processstage','fctg_fctg_destination_fctg_consultantprofile','fctg_fctg_consultantprofiles_fctg_productcat', 'fctg_fctg_consultantprofiles_fctg_spokenlang','activityparty','arb_incident_fctg_quote'), createArray('teammembership'))  
    

    Hope this will help. Please let us know if any further queries.

    ------------------------------

    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you.
      Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
    • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.