使用 Azure 数据工厂或 Synapse Analytics 从 OData 源复制数据

适用于: Azure 数据工厂 Azure Synapse Analytics

提示

试用 Microsoft Fabric 中的数据工厂,这是一种适用于企业的一站式分析解决方案。 Microsoft Fabric 涵盖从数据移动到数据科学、实时分析、商业智能和报告的所有内容。 了解如何免费开始新的试用

本文概述如何在 Azure 数据工厂或 Synapse Analytics 管道中使用复制活动从 OData 源复制数据。 本文是基于概括性介绍复制活动的复制活动一文编写的。

支持的功能

此 OData 连接器支持以下功能:

支持的功能 IR
复制活动(源/-) ① ②
Lookup 活动 ① ②

① Azure 集成运行时 ② 自承载集成运行时

如需可以用作源/接收器的数据存储的列表,请参阅支持的数据存储

具体而言,此 OData 连接器支持:

  • OData 2.0、3.0 和 4.0 版本。
  • 使用以下某种身份验证复制数据:匿名基本WindowsMicrosoft Entra 服务主体

先决条件

如果数据存储位于本地网络、Azure 虚拟网络或 Amazon Virtual Private Cloud 内部,则需要配置自承载集成运行时才能连接到该数据存储。

如果数据存储是托管的云数据服务,则可以使用 Azure Integration Runtime。 如果访问范围限制为防火墙规则中允许的 IP,你可以选择将 Azure Integration Runtime IP 添加到允许列表。

此外,还可以使用 Azure 数据工厂中的托管虚拟网络集成运行时功能访问本地网络,而无需安装和配置自承载集成运行时。

要详细了解网络安全机制和数据工厂支持的选项,请参阅数据访问策略

入门

若要使用管道执行复制活动,可以使用以下工具或 SDK 之一:

使用 UI 创建到 OData 存储的链接服务

使用以下步骤在 Azure 门户 UI 中创建一个到 OData 存储的链接服务。

  1. 浏览到 Azure 数据工厂或 Synapse 工作区中的“管理”选项卡,并选择“链接服务”,然后单击“新建”:

  2. 搜索“OData”,然后选择“OData”连接器。

    Screenshot of the OData connector.

  3. 配置服务详细信息、测试连接并创建新的链接服务。

    Screenshot of linked service configuration for an OData store.

连接器配置详细信息

对于特定于 OData 连接器的数据工厂实体,以下部分提供有关用于定义这些实体的属性的详细信息。

链接服务属性

OData 链接的服务支持以下属性:

属性 描述 必需
type type 属性必须设置为 OData 。
url OData 服务的根 URL。
authenticationType 用于连接 OData 源的身份验证类型。 允许的值为“Anonymous” 、“Basic” 、“Windows” 和“AadServicePrincipal” 。 不支持基于用户的 OAuth。 此外,还可以在 authHeader 属性中配置身份验证标头。
authHeaders 附加的用于身份验证的 HTTP 请求标头。
例如,若要使用 API 密钥身份验证,可以将身份验证类型选为“匿名”,然后在标头中指定 API 密钥。
userName 如果使用 Basic 或 Windows 身份验证,请指定用户名 。
password 指定为 userName 指定的用户帐户的密码 。 将此字段标记为 SecureString 类型以将其安全存储。 此外,还可以引用 Azure Key Vault 中存储的机密
servicePrincipalId 指定 Microsoft Entra 应用程序的客户端 ID。
aadServicePrincipalCredentialType 指定要用于服务主体身份验证的凭据类型。 允许值为:ServicePrincipalKeyServicePrincipalCert
servicePrincipalKey 指定 Microsoft Entra 应用程序的密钥。 请将此字段标记为 SecureString 以安全地存储它,或引用存储在 Azure Key Vault 中的机密
servicePrincipalEmbeddedCert 指定在 Microsoft Entra ID 中注册的应用程序的 Base64 编码证书,并确保证书内容类型为 PKCS #12。 请将此字段标记为 SecureString 以安全地存储它,或引用存储在 Azure Key Vault 中的机密
servicePrincipalEmbeddedCertPassword 如果使用密码保护证书,请指定证书的密码。 请将此字段标记为 SecureString 以安全地存储它,或引用存储在 Azure Key Vault 中的机密
tenant 指定应用程序的租户信息(域名或租户 ID)。 将鼠标悬停在 Azure 门户右上角进行检索。
aadResourceId 指定要请求授权的 Microsoft Entra 资源。
azureCloudType 对于服务主体身份验证,请指定 Microsoft Entra 应用程序注册到的 Azure 云环境的类型。
允许的值为“AzureChina”。 默认情况下,使用服务的云环境。
connectVia 用于连接到数据存储的 Integration Runtime。 从先决条件部分了解更多信息。 如果未指定,则使用默认 Azure Integration Runtime。

示例 1:使用匿名身份验证

{
    "name": "ODataLinkedService",
    "properties": {
        "type": "OData",
        "typeProperties": {
            "url": "https://services.odata.org/OData/OData.svc",
            "authenticationType": "Anonymous"
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

示例 2:使用基本身份验证

{
    "name": "ODataLinkedService",
    "properties": {
        "type": "OData",
        "typeProperties": {
            "url": "<endpoint of OData source>",
            "authenticationType": "Basic",
            "userName": "<user name>",
            "password": {
                "type": "SecureString",
                "value": "<password>"
            }
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

示例 3:使用 Windows 身份验证

{
    "name": "ODataLinkedService",
    "properties": {
        "type": "OData",
        "typeProperties": {
            "url": "<endpoint of OData source>",
            "authenticationType": "Windows",
            "userName": "<domain>\\<user>",
            "password": {
                "type": "SecureString",
                "value": "<password>"
            }
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

示例 4:使用服务主体密钥身份验证

{
    "name": "ODataLinkedService",
    "properties": {
        "type": "OData",
        "typeProperties": {
            "url": "<endpoint of OData source>",
            "authenticationType": "AadServicePrincipal",
            "servicePrincipalId": "<service principal id>",
            "aadServicePrincipalCredentialType": "ServicePrincipalKey",
            "servicePrincipalKey": {
                "type": "SecureString",
                "value": "<service principal key>"
            },
            "tenant": "<tenant info, e.g. microsoft.partner.onmschina.cn>",
            "aadResourceId": "<AAD resource URL>"
        }
    },
    "connectVia": {
        "referenceName": "<name of Integration Runtime>",
        "type": "IntegrationRuntimeReference"
    }
}

示例 5:使用服务主体证书身份验证

{
    "name": "ODataLinkedService",
    "properties": {
        "type": "OData",
        "typeProperties": {
            "url": "<endpoint of OData source>",
            "authenticationType": "AadServicePrincipal",
            "servicePrincipalId": "<service principal id>",
            "aadServicePrincipalCredentialType": "ServicePrincipalCert",
            "servicePrincipalEmbeddedCert": { 
                "type": "SecureString", 
                "value": "<base64 encoded string of (.pfx) certificate data>"
            },
            "servicePrincipalEmbeddedCertPassword": { 
                "type": "SecureString", 
                "value": "<password of your certificate>"
            },
            "tenant": "<tenant info, e.g. microsoft.partner.onmschina.cn>",
            "aadResourceId": "<AAD resource e.g. https://tenant.sharepoint.com>"
        }
    },
    "connectVia": {
        "referenceName": "<name of Integration Runtime>",
        "type": "IntegrationRuntimeReference"
    }
}

示例 6:使用 API 密钥身份验证

{
    "name": "ODataLinkedService",
    "properties": {
        "type": "OData",
        "typeProperties": {
            "url": "<endpoint of OData source>",
            "authenticationType": "Anonymous",
            "authHeader": {
                "APIKey": {
                    "type": "SecureString",
                    "value": "<API key>"
                }
            }
        },
        "connectVia": {
            "referenceName": "<name of Integration Runtime>",
            "type": "IntegrationRuntimeReference"
        }
    }
}

数据集属性

本部分提供 OData 数据集支持的属性列表。

有关可用于定义数据集的各部分和属性的完整列表,请参阅数据集和链接服务

要从 OData 复制数据,请将数据集的 type 属性设置为“ODataResource” 。 支持以下属性:

属性 描述 必需
type 数据集的 type 属性必须设置为 ODataResource 。
path OData 资源的路径。

示例

{
    "name": "ODataDataset",
    "properties":
    {
        "type": "ODataResource",
        "schema": [],
        "linkedServiceName": {
            "referenceName": "<OData linked service name>",
            "type": "LinkedServiceReference"
        },
        "typeProperties":
        {
            "path": "Products"
        }
    }
}

复制活动属性

本部分提供 OData 源支持的属性列表。

有关可用于定义活动的各个部分和属性的完整列表,请参阅管道

以 OData 作为源

从 OData 复制数据时,复制活动的 source 节支持以下属性:

属性 描述 必需
type 复制活动源的 type 属性必须设置为 ODataSource 。
query 用于筛选数据的 OData 查询选项。 示例:"$select=Name,Description&$top=5"

注意:OData 连接器会从以下组合 URL 复制数据:[URL specified in linked service]/[path specified in dataset]?[query specified in copy activity source]。 有关详细信息,请参阅 OData URL 组件
httpRequestTimeout 用于获取响应的 HTTP 请求的超时 (TimeSpan 值) 。 该值是获取响应而不是读取响应数据的超时。 如果未指定,默认值为“00:30:00”(30 分钟)。

示例

"activities":[
    {
        "name": "CopyFromOData",
        "type": "Copy",
        "inputs": [
            {
                "referenceName": "<OData input dataset name>",
                "type": "DatasetReference"
            }
        ],
        "outputs": [
            {
                "referenceName": "<output dataset name>",
                "type": "DatasetReference"
            }
        ],
        "typeProperties": {
            "source": {
                "type": "ODataSource",
                "query": "$select=Name,Description&$top=5"
            },
            "sink": {
                "type": "<sink type>"
            }
        }
    }
]

如果使用 RelationalSource 类型源,该源仍按原样受支持,但我们建议今后使用新源。

OData 的数据类型映射

从 OData 复制数据时,会在 OData 数据类型和服务内部使用的临时数据类型之间使用以下映射。 要了解复制活动如何将源架构和数据类型映射到接收器,请参阅架构和数据类型映射

OData 数据类型 临时服务数据类型
Edm.Binary Byte[]
Edm.Boolean Bool
Edm.Byte Byte[]
Edm.DateTime DateTime
Edm.Decimal Decimal
Edm.Double Double
Edm.Single Single
Edm.Guid Guid
Edm.Int16 Int16
Edm.Int32 Int32
Edm.Int64 Int64
Edm.SByte Int16
Edm.String 字符串
Edm.Time TimeSpan
Edm.DateTimeOffset DateTimeOffset

注意

不支持 OData 复杂数据类型,例如对象。

从 Project Online 复制数据

Project Online 需要基于用户的 OAuth,而 Azure 数据工厂不支持后者。 若要从 Project Online 复制数据,可以使用 OData 连接器以及从 Postman 之类的工具获取的访问令牌。

注意

默认情况下,访问令牌将在 1 小时后过期,需要在过期后获取新的访问令牌。

  1. 使用 Postman 获取访问令牌:

    1. 导航到 Postman 网站上的“授权”选项卡。

    2. 在“类型”框中选择“OAuth 2.0”,并在“将授权数据添加到”框中选择“请求标头”。

    3. 在“配置新令牌”页中填写以下信息以获取新的访问令牌:

      • 授权类型:选择“授权代码”。
      • 回调 URL:输入 https://www.localhost.com/
      • 身份验证 URL:输入 https://login.partner.microsoftonline.cn/common/oauth2/authorize?resource=https://<your tenant name>.sharepoint.com。 将 <your tenant name> 替换为自己的租户名称。
      • 访问令牌 URL:输入 https://login.partner.microsoftonline.cn/common/oauth2/token
      • 客户端 ID:输入你的 Microsoft Entra 服务主体 ID。
      • 客户端密码:输入服务主体机密。
      • 客户端身份验证:选择“作为‘基本身份验证标头’发送”。
    4. 系统将要求你使用用户名和密码登录。

    5. 获取访问令牌后,请复制并保存它以供下一步使用。

    Screenshot of using Postman to get the access token.

  2. 创建 OData 链接服务:

    • 服务 URL:输入 https://<your tenant name>.sharepoint.com/sites/pwa/_api/Projectdata。 将 <your tenant name> 替换为自己的租户名称。
    • 身份验证类型:选择“匿名”。
    • 身份验证标头:
      • 属性名称:选择“授权”。
      • :输入 Bearer <access token from step 1>
    • 测试链接服务。

    Create OData linked service

  3. 创建 OData 数据集:

    1. 使用步骤 2 中创建的 OData 链接服务来创建数据集。
    2. 预览数据。

    Preview data

查找活动属性

若要了解有关属性的详细信息,请查看 Lookup 活动

有关复制活动支持作为源和接收器的数据存储的列表,请参阅支持的数据存储和格式