如果文件夹可能不存在,则Azure ADF GetMetadata子项 [英] Azure ADF GetMetadata childItems if folder might not exist

查看:161
本文介绍了如果文件夹可能不存在,则Azure ADF GetMetadata子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可能存在或可能不存在的DataLakeStorage路径.

I have a path to DataLakeStorage, which may or may not exist.

我想遍历该文件夹的内容(如果存在).

I want to iterate over the contents of that folder, if it exists.

在C#中,我将安排一个children集合,如果该文件夹不存在,则该集合为空,然后遍历该(可能为空)集合.

In C# I would arrange to have a children collection, that was empty if the folder didn't exist, and then iterate over that (possibly empty) collection.

我可以在ADF(v2)中做同样的事情吗?

如果我做一个Get Metadata活动,同时返回了existschildItems,那么它几乎可以工作:

If I do a Get Metadata activity returning both exists and childItems, then it nearly works:

  • 如果文件夹确实存在,则可以使用
  • 如果文件夹不存在,也不会出错.
  • 但是如果文件夹不存在,则不会定义childItems属性,因此我不会得到一个空数组来进行迭代.
  • It works if the folder does exist
  • It doesn't error if the folder does NOT exist.
  • But the childItems property is not defined if the folder doesn't exist, so I don't get an empty array to iterate over.

想到的第一个解决方案是尝试构建

The first solution that comes to mind is to try to build Azure ADF expression that returns either an existing array, or an empty array, based on a bool, which I've asked as a direct question. But if there's a nicer / more idiomatic approach, then I'm open to that too :)

推荐答案

请尝试以下操作:

1.创建一个变量,类型为数组,值为空,如下所示:

1.create a variable,type is array,value is empty,like this:

2.创建一个For Each活动,具体取决于您成功获取元数据.

2.create a For Each activity which depends on your Get Metadata success.

表达: @if( contains(activity('Get Metadata1').output,'childitems'), activity('Get Metadata1').output.childitems, variables('emptyArr'))

@if( activity('Get Metadata1').output.exists, activity('Get Metadata1').output.childitems, variables('emptyArr'))

以下是我的测试:

方案一:路径存在

方案二:路径不存在

希望这可以为您提供帮助:)

Hope this can help you:)

这篇关于如果文件夹可能不存在,则Azure ADF GetMetadata子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆