azure - 如何从Azure数据工厂中的上一行获取数据

标签 azure azure-functions azure-data-factory

我正在致力于在 Azure 数据工厂中转换数据 我有一个包含如下数据的源文件:

ABC 代码-01
防御
GHI
JKL代码-02
移动网络运营商

我需要使数据在接收器文件中看起来像这样:

ABC 代码-01
DEF 代码-01
GHI 代码-01
JKL代码-02
MNO代码-02

最佳答案

您可以使用 Azure 数据工厂中提供的填充概念来实现此目的。代码片段可用 here .

Note: The code snippet assumes that you have already added source transformation in data flow.

步骤:

  1. 添加并将其与源文件链接(我已使用您的示例数据生成了文件)。

enter image description here

  • 编辑右上角的数据流脚本以添加代码。
  • enter image description here

  • 在源代码后面添加代码代码段,如图所示。
  • enter image description here

    source1 derive(dummy = 1) ~> DerivedColumn DerivedColumn keyGenerate(output(sk as long), startAt: 1L) ~> SurrogateKey SurrogateKey window(over(dummy), asc(sk, true), Rating2 = coalesce(Rating, last(Rating, true()))) ~> Window1

  • 在脚本中添加代码后,数据流生成了 3 个转换

    a.使用常量“1”的新虚拟列进行派生列转换

    b. SurrogateKey 转换,为从值 1 开始的每行生成键值。

    c. 窗口转换以执行基于窗口的聚合。这里的代码添加了预定义子句last(),如果当前行值为NULL,则前一行不为空值。

  • 有关窗口转换的更多信息,请参阅 - https://learn.microsoft.com/en-us/azure/data-factory/data-flow-window

    enter image description here

  • 当我在源中将值作为单列获取时,在派生列中添加了其他列,以将单个源列拆分并存储为 2 列。
  • enter image description here

  • 如果列值为空,则替换 NULL 值。如果为空,last() 子句将不会识别为 NULL 来替换以前的值。

    case(length(dropLeft(Column_1,4)) >1, dropLeft(Column_1,4), toString(null()))

  • enter image description here

    派生列预览:Column_1是源原始数据,dummy是从添加常量1的代码片段生成的列,Column1Left和Column1Right用于存储拆分后的值(Column_1)原始数据数据。

    注意:Column1Right 空白值将替换为 NULL。

    enter image description here

  • 在 Windows 中转换:
  • a. Over – 根据提供的列对源数据进行分区。由于没有其他列可用作分区列,因此添加使用派生列生成的虚拟列。

    enter image description here

    b. Sort – 根据排序列对源数据进行排序。添加代理键列以对传入的源数据进行排序。

    enter image description here

    c. Window Column – 此处提供表达式,仅当当前值为 Null 时才从前一行复制非 Null 值

    合并(Column1Right,last(Column1Right,true()))

    enter image description here

    d.窗口转换数据预览:这里,Column1Right数据的Null值根据Window Columns中添加的表达式被替换为之前的非Null值。

    enter image description here

  • 第二个派生列作为单列添加到 concat Column1Left 和 Column1Right 中。
  • enter image description here

    第二个派生列预览:

    enter image description here

  • 添加选择转换以仅选择接收器中所需的列并删除不需要的列(这是可选的)。
  • enter image description here

    enter image description here

  • 填充过程后sink数据输出。
  • enter image description here

    关于azure - 如何从Azure数据工厂中的上一行获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68673052/

    相关文章:

    azure - 扫描简单 key 时,找不到预期的 ':' 。 azure-pipeline.yaml 中的语法错误

    node.js - [NODEJS][AZURE] 如何获取文件的 sastoken url 并能够访问它。 [签名不匹配。]

    azure - Azure 应用服务 Web 应用的基于路径的路由

    Azure DevOps Wiql API 将字段添加到响应工作项

    azure - 如何使用 API 测试 Azure 数据工厂链接服务

    azure - 从 ZIP 文件中解压缩文件并将其用作 ADF 复制事件中的源

    azure - 在 Azure 数据工厂中,我可以将数据集中的数据作为输入传递到 Azure 函数吗?

    node.js - Azure Functions : Nodejs, 使用文件系统时有哪些限制/限制?

    azure - 无法使用Azure Function App使用内存缓存

    python - 更改 Azure 存储 API 的 API 版本