How can I check if my parameter consists of one or more attributes?

Poel van der, RE (Ron) 451 Reputation points
2020-10-26T11:52:26.533+00:00

Hi

see attachment

34996-knipsel.jpg

When the string of the incoming pipeline parameter contains one attribute I should use byName, otherwise byNames.
That that would presume I should build two different flows, which for the rest do the same.

How can I build an expression like:

IF the string contains one attribute
THEN inp1_logicalkey_hash = md5(byName($Logicalkey))
ELSE inp1_logicalkey_hash = md5(byNames($Logicalkey))
?
Should I then change something in (one of) my parameters?? Type String[] instead of String[]?

regards
Ron

@HarithaMaddi-MSFT

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
10,567 questions
0 comments No comments
{count} votes

Accepted answer
  1. MartinJaffer-MSFT 26,081 Reputation points
    2020-10-27T00:07:24.263+00:00

    Hello @Poel van der, RE (Ron) and thank you for your question.

    Yes there is an "IF" command you can use. It is spelled with two 'i'. iif(condition, do_if_true, do_if_false) .

    I notice that the examples you gave are words separated by comma (,). Since there is no comma when you have only one name, and one or more commas when you have two or more names, we can just do logic on whether or not a comma exists in $Logicalkey.

    There are multiple ways we can check for the comma.

    like, regexMatch, locate

    iif(like($Logicalkey,'%,%'),md5(byNames($Logicalkey)),md5(byName($Logicalkey)))  
    

    if you are confident your $Logicalkey will never be malformed ( "one," ",two" "," "inter,rupt,two") , then like is sufficient to use (see above).

    iif(2 < locate(',', $Logicalkey), md5(byNames($Logicalkey)),md5(byName($Logicalkey)))  
    

    if you want to be a little more careful, and preclude some malformed inputs, then use like (see above). This avoids starting with comma.

    For maximum protection, use regexMatch.

    regexMatch($Logicalkey, '((\w+),(\w+))+' )

    If I wrote this correctly, it means at least one repetition of ( 1 or more word characters, followed by a comma, followed by one or more word characters).


0 additional answers

Sort by: Most helpful

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.