У меня есть база данных SQL, содержащая отношения между таблицами один ко многим.Я написал запрос так, чтобы он содержал строки с полями, содержащими json (для связанных строк таблицы).Вот запрос -
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
Ниже приведены результаты запроса -
![enter image description here](https://i.stack.imgur.com/CKQB7.png)
Здесь я получаю два поля с получателямисодержит массив объектов, а сообщения содержат набор объектов.
В 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"
}
Я получаю записи как это ->
![enter image description here](https://i.stack.imgur.com/zKSD8.png)
На изображении выше вы можете заметить, что в Recipients и MessageContent добавлен целый json.
В то время как я ожидаю этого -
![enter image description here](https://i.stack.imgur.com/BtsDL.png)