[英]Migrate JSON data from Azure SQL DB to Cosmos DB results in string values
I'm trying to migrate data from SQL DB using CosmosDB Data Migration Tool and I successfully migrated data from SQL DB but the result is all values are string我正在尝试使用 CosmosDB 数据迁移工具从 SQL DB 迁移数据,我成功地从 SQL DB 迁移了数据,但结果是所有值都是字符串
Wondering if there's a way to convert those JSON to Object during migration process?想知道是否有办法在迁移过程中将这些 JSON 转换为 Object?
Here's my sample Query这是我的示例查询
select
json_value(Data, '$.timestamp') as timestamp,
json_query(Data, '$.Product.detail') as [Product.detail],
json_value(Data, '$.Product.price') as [Product.price]
from myTable
nesting seperator: .嵌套分隔符:.
One option is to export your SQL data to a plain CSV file, do any reformatting with your favorite tool, and import the cleaned CSV or JSON file using the Cosmos migration tool.一种选择是将您的 SQL 数据导出为纯 CSV 文件,使用您喜欢的工具进行任何重新格式化,然后使用 Cosmos 迁移工具导入清理过的 CSV 或 JSON 文件。
With PowerShell, for example, the process could be:例如,使用 PowerShell,该过程可能是:
1.create a dataflow and use SQL DB as source. 1.创建数据流并使用 SQL DB 作为源。
2.In source option choose Query
: 2.在源选项中选择Query
:
SQL:查询语句:
select
json_value(Data, '$.timestamp') as timestamp,
json_query(Data, '$.Product.detail') as [Product.detail],
json_value(Data, '$.Product.price') as [Product.price]
from test3
3.create a DerivedColumn
,and change type of column.Expression of Product
: 3.创建一个DerivedColumn
,并改变列的类型。 Product
:
@(detail=split(replace(replace(replace(byName('Product.detail'),'[',''),']',''),'"',''),','),
price=toDouble(byName('Product.price')))
4.choose Cosmos DB as sink and mapping like this: 4. 选择 Cosmos DB 作为接收器并进行映射,如下所示:
5.create a pipeline and add the dataflow you created before,then click debug button or add trigger to execute it. 5.创建管道并添加之前创建的数据流,然后单击调试按钮或添加触发器以执行它。
6.result: 6.结果:
{
"Product": {
"price": 300.56,
"detail": [
"eee",
"fff"
]
},
"id": "d9c66062-63ce-4b64-8bbe-95dcbdcad16d",
"timestamp": 1600329425
}
Update:更新:
You can enable the Data flow debug button, and see the result of expression in Data preview.您可以启用数据流调试按钮,并在数据预览中查看表达式的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.