dimanche 6 février 2022

ADF Pipeline Beginner series : Remove first item of an Array

  This is a series of tiny articles about some features that are lacking in the Azure data factory and how to overcome them :



As of today ( January 2022 ), ADF pipelines don't have a native function to remove one item of an array. This prevents us from using an array as a stack; however, it's possible to overcome this limitation with a bit of code. The key is to convert the array to a string and modify the line manually. Then two cases occur; first, the Array has only one item; therefore doesn't need to deal with the separator between items as there will be none. Second, there is more than one item in the second case, and we need to deal with the separator.

In this example, we use the _tmpQueue variable as registry variable ( explanation on my article "ADF Pipeline beginner series: Add a list of items to an array variable".



@if(greater(length(variables('_tmpQueue')),1),
json(
        replace( 
            string(variables('_tmpQueue')),
            concat(string(first(variables('_tmpQueue'))),','),
            ''
            )
        ),
        json(
        replace( 
            string(variables('_tmpQueue')),
            string(first(variables('_tmpQueue'))),
            ''
            )
        )
        )
    

First we extract the JSON code of the first item of the array using first(variables('_tmpQueue'))
then we transform this code into a string to remove this part from the global Array ( which will be converted as a string to achieve a text replacement )

The first line of the code @if(greater(length(variables('_tmpQueue')),1) test if the Array has one more than one item and uses this information to deal with the comma separator


Aucun commentaire:

Enregistrer un commentaire