Azure数据工厂:使用Azure数据工厂活动展平/标准化CSV文件中的Cloumn

时间:2020-07-03 11:48:13

标签: azure-data-factory

我已经使用ADF从我们的一个来源中提取了一个csv文件,其中有一列称为“属性”,其中包含多个字段(以键值对的形式)。现在,我想将该列扩展为不同的字段(列)。下面是该示例:

leadId  activityDate    activityTypeId  campaignId  primaryAttributeValue   attributes
1234    2020-06-22T00:00:44Z    46  33686   Mail    {"Description":"Clicked: https://stepuptostepout.com/","Source":"Lead action","Date":"2020-06-21 19:00:44"}
5678    2020-06-22T00:01:54Z    13  33128   SMS {"Reason":"Changed","New Value":110,"Old Value":null,"Source":"Marketo Flow Action"}

在这里,属性列具有不同的键值对,我希望它们在不同的列中,以便将它们存储在Azure SQL数据库中:

属性 {“原因”:“已更改”,“新值”:110,“旧值”:空,“来源”:“ Marketo”}

我希望它们为:

Reason     New Value    Old Value   Source
Changed    110          null        Marketo

我正在使用Azure数据工厂。请帮忙!

更新此: 我在数据中注意到的另一件事是密钥不统一,而且如果一个潜在客户ID存在一个密钥(例如“源”),则另一个LeadId中可能不存在/缺少该密钥,这使操作更加复杂。因此,对于每个属性键都有单独的列可能不是一个好主意。 因此,我们可以为“属性”字段创建一个单独的表,并以潜在客户ID,AttributeKey,AttributeValue作为列(我们可以使用LeadID将其与主表连接起来)。属性表如下所示:

LeadID AttributeKey AttributeValue
5678 Reason Changed
5678 New Value 110
5678 Old Value null
5678 Source Marketo

您能帮我我可以使用ADF做到吗?

1 个答案:

答案 0 :(得分:0)

您可以使用数据流执行此操作。下面是我的测试示例。

enter image description here

  • 设置source1 enter image description here
  • 过滤器1的设置

instr(attributes,'Reason')!= 0

  • DerivedColumn1的设置

    enter image description here

这是我的表情,很复杂。

@(原因=翻译(split(split(attributes,',')[1],':')[2],'“',''), NewValue = translate(split(split(attributes,',')[2],':')[2],'“',''), OldValue = translate(split(split(attributes,',')[3],':')[2],'“',''), Source = translate(translate(split(split(attributes,',')[4],':')[2],'“',''),'}',''))

  • Select1的设置 enter image description here

结果如下: enter image description here

顺便说一句,如果您的文件是json,则比csv更容易做到这一点。 希望能为您提供帮助:)。