简体   繁体   English

Azure数据工厂-复制活动映射

[英]Azure Data Factory - Copy activity mappings

I am trying to copy data from a json file to a database. 我正在尝试将数据从json文件复制到数据库。 There are two columns on the database that need to be filled with the same json field. 数据库上有两列需要用相同的json字段填充。 However, if I do this mapping, I get an error when running the activity: An item with the same key has already been added . 但是,如果执行此映射,则在运行活动时会出错: An item with the same key has already been added Is it not possible to do this one to many mapping? 不可能进行一对多映射吗?

Map one column in source dataset schema to multiple columns in destination is not supported yet in ADF. ADF尚不支持将源数据集架构中的一列映射到目标中的多列。

But there are other ways to achive this, by altering the source dataset schema to let it have a duplicate column. 但是,还有其他方法可以实现,方法是更改​​源数据集架构以使其具有重复的列。 Then you can use these duplicate columns to map to difference destination columns. 然后,您可以使用这些重复的列来映射到不同的目标列。

Like for SQL dataset, you can use sql query like "select column1 as column1A, column1 as column1B from xxx" to get duplicate columns in source dataset. 与SQL数据集一样,您可以使用sql查询,例如“从xxx中选择column1作为column1A,从column1作为column1B选择”来获取源数据集中的重复列。 Then you can map column1A to destCol1, column1B to destCol2. 然后,您可以将column1A映射到destCol1,将column1B映射到destCol2。

As for JSON file in this case, you can use jsonPathDefinition to define duplicate columns. 对于这种情况下的JSON文件,可以使用jsonPathDefinition定义重复的列。 Reference https://docs.microsoft.com/en-us/azure/data-factory/supported-file-formats-and-compression-codecs#json-format 参考https://docs.microsoft.com/zh-cn/azure/data-factory/supported-file-formats-and-compression-codecs#json-format

For example you have a json with format like 例如,您有一个格式如下的json

{"a":1,"b":2}

Then you can set the dataset format property like 然后您可以设置数据集格式属性,例如

"format": {
    "type": "JsonFormat",
    "filePattern": "setOfObjects",
    "jsonPathDefinition": {
        "a1": "$.['a']",
        "b": "$.['b']",
        "a2": "$.['a']"
    }
},

It will create 3 columns a1, b, a2 in the source dataset schema with a1 and a2 refering to the same json field a. 它将在源数据集架构中创建3列a1,b,a2,其中a1和a2引用相同的json字段a。 Then you will be able to map these columns to different columns in destinations. 然后,您将能够将这些列映射到目标中的不同列。

Thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM