首页 文章

Azure数据工厂:将数据从CosmosDB复制到SQL数据库失败,并出现“范围索引”错误

提问于
浏览
0

我需要将Azure CosmosDB(以前称为DocumentDB)中的数据移动到Azure SQL数据库中 .

我正在使用“复制数据”资源,我已经设置了源和目标以及映射 .

时间表已经设置为每小时一次 . 问题 :

  • 我注意到没有 . 实例或"runs"每小时不止一次 . 这是因为它失败并且它会在一定时间内重试吗?

  • 它失败的主要错误似乎是这样的:

活动Copy_dbo_SubscriptionLocator失败:“源”端发生故障 . ErrorCode = UserErrorDocumentDBReadError,'Type = Microsoft.DataTransfer.Common.Shared.HybridDeliveryException,Message = DocumentDb操作失败:消息:{“错误”:[“指定了一个无效的查询,其中包含针对不是范围的路径的过滤器 - 索引 . 考虑在请求中添加允许扫描标头 . “]}

我需要对CosmosDB进行哪些更改以避免错误?

以下是我目前的索引政策:

{
    "indexingMode": "consistent",
    "automatic": true,
    "includedPaths": [
        {
            "path": "/*",
            "indexes": [
                {
                    "kind": "Range",
                    "dataType": "Number",
                    "precision": -1
                },
                {
                    "kind": "Hash",
                    "dataType": "String",
                    "precision": 3
                }
            ]
        }
    ],
    "excludedPaths": [
        {
            "path": "/OneOfTheColumns/*"
        }
    ]
}

看起来问题在于datetime字段,需要将其作为字符串进行范围索引 . 我可以在文档中使用_ts字段 . 但是,如何更改“复制”作业以将查询的日期时间转换为纪元时间,并将其值用于_ts字段 .

2 回答

  • 2

    我不确定您使用的是哪种语言,所以我将您的问题转发给我,请参阅我的步骤 .

    我的样本文件:

    [
        {
            "id": "1",
            "name": "Jay",
            "course": "A",
            "score": 50
        },
        {
            "id": "2",
            "name": "Peter",
            "course": "B",
            "score": 20
        }
    ]
    

    指数政策:

    {
        "indexingMode": "consistent",
        "automatic": true,
        "includedPaths": [
            {
                "path": "/name/?",
                "indexes": [
                    {
                        "kind": "Hash",
                        "dataType": "String",
                        "precision": 3
                    },
                    {
                        "kind": "Range",
                        "dataType": "Number",
                        "precision": -1
                    }
                ]
            }
        ],
        "excludedPaths": [
            {
                "path": "/*"
            }
        ]
    }
    

    在源中查询: (SELECT c.id,c.name,c.course,c.score FROM c where c.score>30)

    enter image description here

    重现您的问题:

    enter image description here

    Range支持高效的相等查询,范围查询(使用>,<,=,<=,!=)和ORDER BY查询 . ORDER默认情况下,查询还需要最大索引精度(-1) . 数据类型可以是String或Number .

    如果您有范围查询,则需要在字段上定义范围索引 . 请参考官方doc .

    所以,我修改了上面的索引策略并成功复制了数据:

    {
        "indexingMode": "consistent",
        "automatic": true,
        "includedPaths": [
            {
                "path": "/*",
                "indexes": [
                    {
                        "kind": "Range",
                        "dataType": "Number",
                        "precision": -1
                    },
                    {
                        "kind": "Range",
                        "dataType": "String",
                        "precision": -1
                    },
                    {
                        "kind": "Spatial",
                        "dataType": "Point"
                    }
                ]
            }
        ],
        "excludedPaths": []
    }
    

    enter image description here

    enter image description here

    希望它能帮到你 .

  • 2

    您需要更新文档集合的索引策略以允许此查询 .

    假设您有一个查询,例如“select * from c where c.property>”something“,这个c.property必须有一个范围索引 .

    您可以了解有关索引策略的更多信息here:和here

相关问题