Azure Cosmos DBAzure Cosmos DB

重要

此功能目前以公共预览版提供。This feature is in Public Preview.

Azure Cosmos DB 是由 Microsoft 提供的全球分布式多模型数据库。Azure Cosmos DB is Microsoft’s globally distributed, multi-model database. 使用 Azure Cosmos DB 可跨任意数量的 Azure 地理区域弹性且独立地缩放吞吐量和存储。Azure Cosmos DB enables you to elastically and independently scale throughput and storage across any number of Azure’s geographic regions. 它通过综合服务级别协议 (SLA) 提供吞吐量、延迟、可用性和一致性保证。It offers throughput, latency, availability, and consistency guarantees with comprehensive service level agreements (SLAs). Azure Cosmos DB 为以下数据模型提供 API,并提供多种语言的 SDK:Azure Cosmos DB provides APIs for the following data models, with SDKs available in multiple languages:

  • SQL APISQL API
  • MongoDB APIMongoDB API
  • Cassandra APICassandra API
  • 图形 (Gremlin) APIGraph (Gremlin) API
  • 表 APITable API

本文介绍如何从 Azure Cosmos DB 读取数据或将数据写入 Azure Cosmos DB。This article explains how to read data from and write data to Azure Cosmos DB.

备注

无法从运行 Databricks Runtime 7.0 或更高版本的群集访问此数据源,因为支持 Apache Spark 3.0 的 Azure Cosmos DB 连接器不可用。You cannot access this data source from a cluster running Databricks Runtime 7.0 or above because an Azure Cosmos DB connector that supports Apache Spark 3.0 is not available.

创建并附加所需的库Create and attach required libraries

  1. 下载最新版 azure-cosmosdb-spark 库以获取你正在运行的 Apache Spark 版本:Download the latest azure-cosmosdb-spark library for the version of Apache Spark you are running:
  2. 按照上传 Jar、Python Egg 或 Python Wheel 中的说明,将下载的 JAR 文件上传到 Databricks。Upload the downloaded JAR files to Databricks following the instructions in Upload a Jar, Python Egg, or Python Wheel.
  3. 安装上传的库,将其安装到 Databricks 群集中。Install the uploaded libraries into your Databricks cluster.

使用 Azure Cosmos DB Spark 连接器Use the Azure Cosmos DB Spark connector

下面的 Scala 笔记本提供了一个简单的示例,说明如何将数据写入 Cosmos DB 以及如何从 Cosmos DB 读取数据。The following Scala notebook provides a simple example of how to write data to Cosmos DB and read data from Cosmos DB. 有关详细文档,请参阅 Azure Cosmos DB Spark 连接器项目。See the Azure Cosmos DB Spark Connector project for detailed documentation. 由 Microsoft 开发的 Azure Cosmos DB Spark 连接器用户指南也介绍了如何在 Python 中使用此连接器。The Azure Cosmos DB Spark Connector User Guide, developed by Microsoft, also shows how to use this connector in Python.

Azure Cosmos DB 笔记本Azure Cosmos DB notebook

获取笔记本Get notebook