您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

快速入门:连接到 Azure Synapse Link for Azure Cosmos DBQuickstart: Connect to Azure Synapse Link for Azure Cosmos DB

本文介绍如何使用 Synapse Link 从 Azure Synapse Analytics Studio 访问 Azure Cosmos DB 数据库。This article describes how to access an Azure Cosmos DB database from Azure Synapse Analytics studio with Synapse Link.

先决条件Prerequisites

将 Azure Cosmos DB 帐户连接到工作区之前,需要具有以下各项。Before you connect an Azure Cosmos DB account to your workspace, there are a few things that you need.

  • 现有的 Azure Cosmos DB 帐户或按照此快速入门创建一个新帐户Existing Azure Cosmos DB account or create a new account following this quickstart
  • 现有的 Synapse 工作区或按照此快速入门创建一个新工作区Existing Synapse workspace or create a new workspace following this quickstart

启用 Azure Cosmos DB 分析存储Enable Azure Cosmos DB analytical store

若要在不影响操作性能的情况下对 Azure Cosmos DB 运行大规模分析,建议启用 Synapse Link for Azure Cosmos DB。To run large-scale analytics into Azure Cosmos DB without impacting your operational performance, we recommend enabling Synapse Link for Azure Cosmos DB. 此功能将 HTAP 功能引入容器中,并在 Azure Synapse 中提供内置支持。This function brings HTAP capability to a container and built-in support in Azure Synapse. 按照此快速入门,为 Cosmos DB 容器启用 Synapse Link。Follow this quickstart to enable Synapse Link for Cosmos DB containers.

在 Synapse 工作区中,选择“启动 Synapse Studio”。From your Synapse workspace, select Launch Synapse Studio. 在 Synapse Studio 主页上,选择“**数据”,这会将你转到“数据对象资源管理器”。On the Synapse Studio home page, select **Data, which will take you to the Data Object Explorer.

将 Azure Cosmos DB 数据库连接到 Synapse 工作区Connect an Azure Cosmos DB database to a Synapse workspace

连接 Azure Cosmos DB 数据库作为链接服务完成。Connecting an Azure Cosmos DB database is done as linked service. Cosmos DB 链接服务使用户能够浏览和探索数据,并从 Apache Spark for Azure Synapse Analytics 或 SQL 读取或者写入到 Azure Cosmos DB。A Cosmos DB linked service enables users to browse and explore data, read, and write from Apache Spark for Azure Synapse Analytics or SQL into Azure Cosmos DB.

可以在数据对象资源管理器中通过执行以下步骤直接连接 Azure Cosmos DB 数据库:From the Data Object Explorer, you can directly connect an Azure Cosmos DB database by doing the following steps:

  1. 选择数据旁边的 + 图标Select + icon near Data
  2. 选择“连接到外部数据”Select Connect to external data
  3. 选择要连接到的 API:SQL 或 MongoDBSelect the API that you want to connect to: SQL or MongoDB
  4. 选择“继续”Select Continue
  5. 命名链接服务。Name the linked service. 该名称将显示在对象资源管理器中,并由 Synapse 运行时用于连接到数据库和容器。The name will be displayed in the Object Explorer and used by Synapse run-times to connect to the database and containers. 建议使用友好名称。We recommend using a friendly name.
  6. 选择“Cosmos DB 帐户名称”和“数据库名称”Select the Cosmos DB account name and database name
  7. (可选)如果没有指定区域,Synapse 运行时操作将被路由到启用分析存储的最近的区域。(Optional) If no region is specified, Synapse run-time operations will be routed toward the nearest region where the analytical store is enabled. 但可以手动设置希望用户访问 Cosmos DB 分析存储的区域。However, you can set manually which region you want your users to access Cosmos DB analytical store. 选择“其他连接属性”,然后选择“新建”。Select Additional connection properties and then New. 在“属性名称”下,写入“PreferredRegions”,并将“值”设置为所需区域(例如 :WestUS2,单词和数字之间没有空格)Under Property Name, write **PreferredRegions_ and set the _* Value* to the region you want (example: WestUS2, there is no space between words and numbers)
  8. 选择“创建”Select Create

Azure Cosmos DB 数据库会显示在 Azure Cosmos DB 部分中的“链接”选项卡下。Azure Cosmos DB databases are visible under the tab Linked in the Azure Cosmos DB section. 可以通过以下图标区分启用 HTAP 的 Azure Cosmos DB 容器和仅 OLTP 容器:You can differentiate an HTAP enabled Azure Cosmos DB container from an OLTP only container with the following icons:

Synapse 容器:Synapse container:

HTAP 容器

仅 OLTP 容器:OLTP only container:

OLTP 容器

与代码生成的操作快速交互Quickly interact with code-generated actions

右键单击容器时,会获得一个用于触发 Spark 或 SQL 运行时的手势列表。When you right-click into a container, you'll have a list of gestures that will trigger a Spark or SQL run-time. 写入容器将通过 Azure Cosmos DB 的事务存储进行,并将消耗请求单位。Writing into a container will happen through the Transactional Store of Azure Cosmos DB and will consume Request Units.

后续步骤Next steps