skip to Main Content

I am trying to split the item name if the item name contains ‘_’ and if those item name starts with a specific schema names

item = ['test_tabl','Schema1__mytable1', 'Schema2__mytable2']

@concat('SELECT *FROM ',
    if(contains(item(), '_'), and(startswith(item(), 'Schema1_'),item()), or(startswith(item(), 'Schema2_'),item()),
        concat(split(item(), '_')[0], '.', replace(item(),concat(split(item(), '_')[0],'_'),''))),
        concat(pipeline().globalParameters.my_schema,'.',item())
    )
)

in the above case, the condition check for item name list if it has ‘‘ value or start with ‘Schema1‘ or ‘Schema2_’, then it should split or else it should go with the default schema(globalParameters).table name.

ie: here – ‘Schema1__mytable1’, ‘Schema2__mytable2’ – split should happen only for this items and not ‘test_tabl’.

But i am getting below error

function 'if' does not accept 4 argument(s)

Is there any resolution to this?

2

Answers


  1. Chosen as BEST ANSWER

    I got the issue and and solution from @Aswin code

    
    select * from 
    @{if(and(or(startswith(item(),'Schema1_'),startswith(item(),'Schema2_')),contains(item(), '_'))
    ,concat(split(item(),'_')[0],'.',split(item(), '__')[0],'.', replace(item(),concat(split(item(), '_')[0],'_'),'')))
    ,concat(pipeline().globalParameters.my_schema,'.',item()))}
    

  2. The error message you are seeing is because the if function in ADF expression only accepts three arguments. The expression you are having seems to have few errors. Based on the requirement, you can use the below expression.

    select * from 
    @{if(and(or(startswith(item(),'Schema1_'),startswith(item(),'Schema2_')),contains(item(), '_'))
    ,concat(split(item(),'_')[0],'.',split(item(), '__')[1])
    ,concat(pipeline().globalParameters.my_schema,'.',item()))}
    

    This expression uses the string interpolation instead of concat. This will result the same expected SQL query.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search