azure-synapse - 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 == $$)])
我已经被困在这个问题上太久了,所以我希望有人能给我一些关于如何继续的想法。
任何帮助将不胜感激。
解决方案
我创建了一个简单的数据流来测试。
然后我在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]])
推荐阅读
- java - PHONE_STATE 接收器不与基于上下文的接收器一起使用
- python-3.x - 没有使用 python boto3 获取所有 aws 实例 - 保留问题
- swift - 在 SwiftUI 中动态添加元素到 VStack
- bash - 估计大文本文件的大小
- performance - webgl 不能在集成显卡上的一次 drawcall 中绘制太多图元
- ios - IOS 在应用程序拒绝问题 - 指南 2.1 - 性能 - 应用程序完整性
- node.js - 在猫鼬中删除文档时出现UnhandledPromiseRejectionWarning
- amazon-web-services - 如何通过 CloudFormation YAML 将堆栈导出的现有 S3 存储桶导入另一个堆栈
- python - 在 Log N 时间内设计一个算法
- mysql - 为什么将 MySQL 代码添加到基于 epoll 的网络爬虫中会大大降低它的速度?