【问题标题】:Azure Data factory expressionAzure 数据工厂表达式
【发布时间】:2022-11-18 03:04:14
【问题描述】:

我在过滤器活动条件下的一个 Pipeine 中看到了这个表达式。任何人都可以帮助我理解这个使用的表达式(你可以重新表达以使其易于理解)。看起来很难理解。

@if(equals(pipeline().parameters.FileName,'default'),endswith(toUpper(item().name),'.PDF'),
and(startswith(item().name,replace(string(pipeline().parameters.Filemane),'*.txt','')),
endswith(toUpper(item().name),'.PGP')))

谢谢

我没有拦截器,但我无法理解表达式。只是想弄清楚该代码的目的是什么,他们试图在 ADF 的特定过滤条件下实现什么

【问题讨论】:

  • 提供示例输入和预期结果以及您面临的任何错误/障碍。
  • 我没有拦截器,但我无法理解表达式。只是想弄清楚该代码的目的是什么,他们在 ADF @RakeshGovindula 的特定过滤条件下试图实现什么
  • 在我看来,如果文件名是默认的并且项目是 pdf 文件,它会返回 true。或者如果项目是 pgp 文件并且参数中的文件名不是 txt 文件。为什么?我想我们需要更多关于 ADF 中这个管道是关于什么的信息

标签: azure-data-factory etl common-expression-language


【解决方案1】:

好吧,我不确定 ' 之前的第一个代码之间是否有区别谢谢' 和它后面的代码。

但似乎代码会返回 true 或 false。 我可以用类似 c# 的格式重新表述:


if(pipeline().parameters.FileName == 'default')
{
    // if the name of item ends with .pdf then return true, else return false
    return endswith(toUpper(item().name),'.PDF'), 
}
else
{
   // replace the *.txt with an empty string. 
   // I think it means if the file ends with .txt then replace it with an empty string
   string replacedText = replace(pipeline().parameters.Filemane,'*.txt','')
   // check if the itemName is ends with .txt (in this case this condition will fail)
   boolean cond1 = startswith(item().name, replacedText)
   
   // if the name of item ends with .PGP then cond2 = true
   boolean cond2 = endswith(toUpper(item().name),'.PGP')
   
   return cond1 && cond2 
}

【讨论】:

    【解决方案2】:

    如果您在过滤器活动中使用上述表达式。它将根据FileName 参数过滤数组的值。

    这是我的文件名示例数组:

    ['rakesh.pdf','correct1.pgp','wrong1.pgp','laddu.pdf','correct2.pgp','wrong2.pgp','virat.pdf','wrong3.pgp','correct3.txt']
    

    对你来说,数组将是一个对象数组。这就是为什么在上面的表达式中它是 item().name 的原因。对我来说,它只是item()

    根据条件过滤活动过滤器。如果特定的数组项满足条件(真/假),那么它会过滤它。

     @if(equals(pipeline().parameters.FileName,'default'),endswith(toUpper(item().name),'.PDF'), and(startswith(item().name,replace(string(pipeline().parameters.Filemane),'*.txt','')), endswith(toUpper(item().name),'.PGP')))
    

    上述表达式中,如果FileName参数值为'default',则过滤掉以.PDF结尾的项。 if(condition,True case,else case)所以在真实案例我们正在检查endswith().PDF。如果为真,则过滤条件为真,该特定数组值将被过滤。

    否则情况

    and(startswith(item().name,replace(string(pipeline().parameters.Filemane),'*.txt','')), endswith(toUpper(item().name),'.PGP'))
    

    如果参数值为correct*.txt(非默认值)。 在这种情况下,它将 '*.txt' 替换为空字符串 ('') 并返回 'correct'。然后它检查(第一个条件) 数组值是否以'correct'开头并以.PGP结尾(第二个条件).如果两个条件都为真,则过滤条件为真,数组值被过滤。

    这是一个示例演示:

    大批:

    相同条件过滤:

    对我来说,它只是item()而不是item().name

    如果我把参数值取为'default'

    过滤输出数组(all .PDF files):

    如果我把参数值取为'correct*.txt'

    过滤输出数组(.PGP files starts with 'correct'):

    笔记:如果您的参数值仅类似于 'correct.txt',则在表达式中使用 '.txt'

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-09-30
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 2021-09-16
      • 2019-11-20
      • 2022-10-04
      • 2020-11-13
      相关资源
      最近更新 更多