当我在Azure数据工厂上使用复制数据活动时,我正在尝试创建动态映射。 我想创建一个包含与从源中读取的数据相同的数据的镶木地板文件,但是我想修改一些列名称以删除其上的空白(It's a bug of Parquet format),并且我想自动执行。 / p>
I have seen that this is possible in mapping data flow,但我在复制活动上看不到任何此类功能(映射数据流仅限于几个连接器作为源,因此我无法使用它)。
如您在图像上看到的,看来我只能修改单个列,而不能修改满足某些条件的少数列
我该怎么做?
预先感谢
答案 0 :(得分:0)
“复制”活动可以从一种文件类型更改为另一种文件类型,例如从csv更改为json,从镶木地板更改为数据库,但是它本质上不允许进行任何转换,例如更改任何列的内容,甚至添加其他列。
或者考虑将ADF to call a Databricks notebook用于这些复杂的基于规则的转换。
答案 1 :(得分:0)
这里有一个使用 ADF 应用动态列名映射的解决方案,以便您仍然可以使用 parquet 格式的复制数据活动,即使源列名具有不受支持的讨厌的空白字符。
解决方案包括三个部分:
;with cols as (
select
REPLACE(column_name, (' ', '__wspc__') as new_name,
column_name as old_name
from INFORMATION_SCHEMA.columns
where table_name = '@{pipeline().parameters.SOURCE_TABLE}'
and table_schema = '@{pipeline().parameters.SOURCE_SCHEMA}'
)
select ' |||'+old_name+'||'+new_name+'|' as mapping
from cols;
@json(
concat(
'[ ',
join(
split(
join(
split(
join(
split(
join(
xpath(
xml(
json(
concat(
'{\"root_xml_node\": ',
string(activity('lookup column mapping').output),
'}'
)
)
),
'/root_xml_node/value/mapping/text()',
)
','
),
'|||'
),
'{\"source\": { \"name\": \"'
),
'||'
),
'\" },\"sink\": { \"name\": \"'
),
'|'
),
'\" }}'
),
' ]'
)
)
不幸的是,该表达式比我们想要的更复杂,因为 xpath 函数需要查找活动输出未提供的单个根节点,并且 ADF json 模板的字符串转义为简化此操作带来了一些挑战。
>@json(
concat(
'{ \"type\": \"TabularTranslator\", \"mappings\":',
string(variables('column_mapping_list')),
'}'
)
)
预期结果:
第 1 步。
'我的 wspccol' -> '|||我的 wspccol||my__wspc__wspcol|'
第 2 步。
'|||我的 wspccol||my__wspc__wspccol|' -> ['{ "source": { "name": "my wspccol" }, "sink": { "name": "my__wspc__wspccol" } }']
{
"type": "TabularTranslator",
"mappings": [
{
"source": { "name": "my wspccol" },
"sink": { "name": "my__wspc__wspccol" }
}
]
}
另外: