skip to Main Content

I am trying to select the last string after splitting it in Azure Data Factory.

My file name looks like this:

s = "cloudboxacademy/covid19/main/ecdc_data/hospital_admissions.csv"

With Python I would use s.split('/')[-1] to get the last element, according to Microsoft documentation I can use last to achieve this, so I’ve tried this in the sink database Pipeline expression builder:

@last(split(dataset().fileName, '/'))

Which gives me a red underline stating:

Cannot fit string list item into the function parameter string

However, after running the pipeline I get what I desire, the file named hospital_admissions.csv placed in the folder I want it to go, so my question is if I am chaining the functions correctly & why am I having the error with a working code?

2

Answers


  1. you can do the following:
    Create 2 Variables:
    Variable 1 (Array):

    @split('cloudboxacademy/covid19/main/ecdc_data/hospital_admissions.csv', '/')
    

    Variable 2 (String):

    @last(variables('test'))
    

    OutputVariable1

    OutputVariable2

    VariableDeclaration

    Login or Signup to reply.
  2. The pipeline expression builder might be recognizing the value generated by split(dataset().fileName,'/') as an array. Hence the message Cannot fit string list item into the function parameter string.

    enter image description here

    • However, while executing, it is giving the expected output.
    • To make it so that the warning Cannot fit string list item into the function parameter string is not shown, you can use the result of split along with array function. You can still chain the function using the following dynamic content and get expected result:
    @last(array(split(dataset().filename,'/')))
    

    enter image description here

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