首页 > 解决方案 > Azure Synapse 映射数据流 - 派生列中列名的动态映射

问题描述

在映射数据流活动中,我有一堆来自存储帐户未处理区域的表,我的目标是仅选择其中一些列用于下一个更多处理区域。在选择列时,我需要将列名转换为更直观的名称和/或小写名称。我打算使用参数来做到这一点,所以如果我需要进行调整,我只需要在一个地方更改它。

我管理了“简单”部分 - 将相关列名列入白名单并将这些名称设为小写。但是假设我想根据字典重命名列,其中列“abc”变为“def”,“ghi”变为“jkl”。我正在尝试使用列模式在派生列转换中执行此操作。我制作了一个地图参数(我不确定它的语法是否正确):

['abc'->'def', 'ghi' -> 'jkl']

我想我需要在翻译映射中找到匹配键的索引,然后用 values 数组中的正确索引替换它,但似乎没有一种简单的方法可以从https上可用的函数中提取索引://docs.microsoft.com/en-us/azure/data-factory/data-flow-expression-functions。这是我到目前为止的部分伪代码(index):

replace($$,find(keys($translation),#item == $$),values($translation)[*index*(keys($translation),#item == $$)])

我已经被困在这个问题上太久了,所以我希望有人能给我一些关于如何继续的想法。

任何帮助将不胜感激。

标签: azure-synapseazure-data-flowderived-columnexpressionbuilder

解决方案


我创建了一个简单的数据流来测试。

源数据预览: 在此处输入图像描述

范围: 在此处输入图像描述

然后我在DerivedColumn转换中测试了serval表达式:</p>

1.在列模式中,使用以下表达式replace($$,find(keys($translation),toString(#item) == $$),values($translation)[mapIf(keys($translation),toString(#item) == $$,#index)[1]]),这是行不通的。通过这个表达式,mapIf(keys($translation), 1 == 1, concat($$, $$))我发现函数不能工作(它返回 abc 和 ghi,期望值为 abcabc 和 ghighi)。我不确定这是一个错误还是 ADF 团队是这样设计的。$$mapIf()

2.然后我没有使用列模式只是添加列尝试:replace(col1,find(keys($translation),toString(#item) == col1),values($translation)[mapIf(keys($translation),toString(#item) == col1,#index)[1]])replace(col2,find(keys($translation),toString(#item) == col2),values($translation)[mapIf(keys($translation),toString(#item) == col2,#index)[1]])

它可以得到正确的值: 在此处输入图像描述

结论:

不要使用列模式,只添加列,然后使用这个表达式:replace(columnName,find(keys($translation),toString(#item) == columnName),values($translation)[mapIf(keys($translation),toString(#item) == columnName,#index)[1]])

在此处输入图像描述


推荐阅读