dave111
dave111

Reputation: 305

ADF - HTTP API - Pipelines query, sorting/orderby syntax?

I am doing some ADF scheduling between multiple pipelines to make sure 2 pipelines aren't running a certain operation at the same time. I'm using the following Azure API call to get a list of all the running ADF pipelines: https://learn.microsoft.com/en-us/rest/api/datafactory/pipeline-runs/query-by-factory?tabs=HTTP#pipelineruns_querybyfactory

I have the following which works and filters down to the specific pipelines I'm interested in for my HTTP body:

{
  "lastUpdatedAfter": "@{subtractFromTime(utcNow(), pipeline().globalParameters.InProgressPipelinesLimitHours,'Hour')}",
  "lastUpdatedBefore": "@{addToTime(utcNow(), 6, 'Hour')}",
  "filters": [
    {
      "operand": "PipelineName",
      "operator": "Equals",
      "values": [
        "ETL_Main"
      ]
    }
  ]
}

I now want to sort this output to have the oldest pipeline (RunStart) at the top of the result set (ascending). There isn't an explicit syntax example on the help docs. Does this look correct based upon this: https://learn.microsoft.com/en-us/rest/api/datafactory/pipeline-runs/query-by-factory?tabs=HTTP#runfilterparameters

{
  "lastUpdatedAfter": "@{subtractFromTime(utcNow(), pipeline().globalParameters.InProgressPipelinesLimitHours,'Hour')}",
  "lastUpdatedBefore": "@{addToTime(utcNow(), 6, 'Hour')}",
  "filters": [
    {
      "operand": "PipelineName",
      "operator": "Equals",
      "values": [
        "ETL_Main"
      ]
    }
  ],
  "orderBy": [ 
  { 
    "order" : "ASC",
    "orderBy" : "RunStart" 
  } 
  ]
}

Upvotes: 0

Views: 330

Answers (1)

Rakesh Govindula
Rakesh Govindula

Reputation: 11454

Yes, the above syntax is correct. I have checked it from my end with the below body in web activity.

{
    lastUpdatedAfter: "2023-09-08T00:36:44.3345758Z",
    lastUpdatedBefore: "2023-09-10T00:36:44.3345758Z",
        "filters": [
    {
      "operand": "PipelineName",
      "operator": "Equals",
      "values": [
        "pipeline1"
      ]
    }
  ],
  "orderBy": [ 
  { 
    "order": "ASC",
    "orderBy": "RunStart" 
  } 
  ]        
}

And you can see, it gave me the pipeline runs in ascending order.

enter image description here

Also, I have checked with order "DESC" of RunStart and it is working as expected for this as well.

enter image description here

Upvotes: 1

Related Questions