简体   繁体   English

ADF(azure数据工厂)将数据从SQL Server复制到Cosmos DB,其中字段包含json对象

[英]ADF (azure data factory) copy data from SQL Server to Cosmos DB with field contain json object

I have SQL Database contain one to many relations between tables. 我有SQL数据库包含表之间的一对多关系。 I wrote a query so that it contains rows with fields contains json (for related table rows). 我编写了一个查询,以便它包含包含json(对于相关表行)的字段的行。 Here is the query - 这是查询 -

select msg.MessageId as id
      ,msg.CreatedDate as [CreatedDate]
      ,
      (select [RecipientTypeId] as [RecipientTypeId]
      ,[RecipientId] as [RecipientId]
      ,[mr.CreatedDate] as [CreatedDate]
      ,[IsRead] as [IsRead]
      ,[ReadDate] as [ReadDate]
       from [dbo].[MsgRecipients] mr
       where msg.messageid = mr.messageid  FOR JSON PATH, INCLUDE_NULL_VALUES) as Recipients
       ,
       (select 
       [Data] as [Data]
      ,[Value] as [Value]
      ,[mc.SomeId] as [SomeId]
       from [dbo].[MessageContent] mc
       where msg.messageid = mc.messageid  FOR JSON PATH, WITHOUT_ARRAY_WRAPPER, INCLUDE_NULL_VALUES) as MessageContent
       from [dbo].[Messages] msg

Following is the results of query - 以下是查询结果 -

在此输入图像描述

Here I am getting two fields with Recipients contains array of objects and Messages contains set of object. 这里我得到两个字段,Recipients包含对象数组,Messages包含对象集。

In ADF I wrote this - 在ADF我写了这个 -

{
    "name": "CopyPipeline_SQL_to_Cosmos",
    "properties": {
        "description": "CopyPipeline_SQL_to_Cosmos",
        "activities": [
            {
                "name": "Copy_lbp",
                "type": "Copy",
                "policy": {
                    "timeout": "7.00:00:00",
                    "retry": 0,
                    "retryIntervalInSeconds": 30,
                    "secureOutput": false,
                    "secureInput": false
                },
                "userProperties": [
                    {
                        "name": "Destination",
                        "value": "Messages1"
                    }
                ],
                "typeProperties": {
                    "source": {
                        "type": "AzureSqlSource",
                        "sqlReaderQuery": {
                            "value": "select msg.MessageId as id, msg.CreatedDate as [CreatedDate], (select [RecipientTypeId] as [RecipientTypeId], [RecipientId] as [RecipientId], [mr.CreatedDate] as [CreatedDate], [ReadDate] as [ReadDate] from [dbo].[MsgRecipients] mr where msg.messageid = mr.messageid  FOR JSON PATH, INCLUDE_NULL_VALUES) as Recipients, (select  [Data] as [Data], [Value] as [Value], [mc.SomeId] as [SomeId] from [dbo].[MessageContent] mc where msg.messageid = mc.messageid  FOR JSON PATH, WITHOUT_ARRAY_WRAPPER, INCLUDE_NULL_VALUES) as MessageContent from [dbo].[Messages] msg  where CreatedDate >= '@{formatDateTime(pipeline().parameters.windowStart, 'yyyy-MM-dd HH:mm' )}' AND CreatedDate < '@{formatDateTime(pipeline().parameters.windowEnd, 'yyyy-MM-dd HH:mm' )}'",
                            "type": "Expression"
                        }
                    },
                    "sink": {
                        "type": "DocumentDbCollectionSink",
                        "nestingSeparator": "",
                        "writeBatchSize": 10000,
                        "writeBehavior": "upsert"
                    },
                    "enableStaging": false
                },
                "inputs": [
                    {
                        "referenceName": "SourceDataset_lbp",
                        "type": "DatasetReference"
                    }
                ],
                "outputs": [
                    {
                        "referenceName": "DestinationDataset_lbp",
                        "type": "DatasetReference"
                    }
                ]
            },
            {
                "name": "Custom1",
                "type": "Custom",
                "policy": {
                    "timeout": "7.00:00:00",
                    "retry": 0,
                    "retryIntervalInSeconds": 30,
                    "secureOutput": false,
                    "secureInput": false
                }
            }
        ],
        "parameters": {
            "windowStart": {
                "type": "String"
            },
            "windowEnd": {
                "type": "String"
            }
        }
    },
    "type": "Microsoft.DataFactory/factories/pipelines"
}

I am getting records as this -> 我正在获取记录 - >

在此输入图像描述

In above image, You can notice that in Recipients and MessageContent it has added whole json. 在上面的图像中,您可以注意到在Recipients和MessageContent中它添加了整个json。

Whereas I am expecting this - 虽然我期待这个 -

在此输入图像描述

I don't have the data handy so I cannot test , but I am think that you will have to use the "Schema mapping" . 我没有方便的数据,所以我无法测试,但我认为你将不得不使用“架构映射”。

Please read about structure here https://docs.microsoft.com/en-us/azure/data-factory/copy-activity-schema-and-type-mapping#alternative-schema-mapping 请阅读这里的结构https://docs.microsoft.com/en-us/azure/data-factory/copy-activity-schema-and-type-mapping#alternative-schema-mapping

暂无
暂无

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

相关问题 使用Azure Data Factory将Azure cosmos db中的json数据复制到Azure sql - Copy json data from Azure cosmos db to Azure sql using Azure Data Factory Azure 数据工厂和 Cosmos DB - Azure Data Factory and Cosmos DB Azure 数据工厂:从 csv 读取并逐行复制到 cosmos db - Azure Data Factory: read from csv and copy row by row to a cosmos db 从cosmos db查询特定的时间范围数据,并通过azure数据工厂将其存储在sql数据库中 - Query a specific time range data from cosmos db and store it in sql database via azure data factory 如何将 map 我的 json 路径从 Azure 数据工厂进入 cosmos db - How to map my json path into cosmos db from Azure Data Factory Azure 数据工厂 - 将数据从 ADLS 复制到 Cosmos DB - 在创建 ADLS 作为源的连接时出错 - Azure Data Factory- Copy data from ADLS -to Cosmos DB - getting error while creating connection for ADLS as source JSON 的 Azure 数据工厂 ADF 架构验证 - Azure Data Factory ADF Schema validation for JSON Azure 数据工厂将数据 Blob 复制到 Cosmos db - 需要帮助跳过 2MB 文件 - Azure Data factory Copy data Blob to Cosmos db - need help skipping 2MB files 将 JSON 数据从 Azure SQL DB 迁移到 Cosmos DB 结果为字符串值 - Migrate JSON data from Azure SQL DB to Cosmos DB results in string values Migrating Data from a SQL Server Encrypted Table to SQL Azure using Azure Data Factory Copy data - Migrating Data from a SQL Server Encrypted Table to SQL Azure using Azure Data Factory Copy data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM