Skip to content

Commit f840b22

Browse files
committed
minor
1 parent a5071d2 commit f840b22

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

articles/synapse-analytics/synapse-link/concept-synapse-link-cosmos-db-support.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Azure Synapse Link for Cosmos DB supported features
2+
title: Azure Synapse Link for Azure Cosmos DB supported features
33
description: Understand the current list of actions supported by Azure Synapse Link for Cosmos DB
44
services: synapse-analytics
55
author: ArnoMicrosoft
@@ -26,7 +26,7 @@ You can connect to Cosmos DB container without enabling Synapse Link, in which c
2626
Here is list of the currently supported features within Synapse Link for Cosmos DB.
2727

2828
| Category | Description |[Spark](https://docs.microsoft.com/azure/synapse-analytics/sql/on-demand-workspace-overview) | [SQL serverless](https://docs.microsoft.com/azure/synapse-analytics/sql/on-demand-workspace-overview) |
29-
| :-------------------- | :----------------------------------------------------------- |:----------------------------------------------------------- | :----------------------------------------------------------- | :----------------------------------------------------------- |
29+
| -------------------- | ----------------------------------------------------------- |----------------------------------------------------------- | ----------------------------------------------------------- | ----------------------------------------------------------- |
3030
| **Run-time Support** |Support for read or write by Azure Synapse run-time|| [Contact Us](mailto:[email protected]?subject=[Enable%20Preview%20Feature]%20SQL%20serverless%20for%20Cosmos%20DB)|
3131
| **Cosmos DB API support** |API support as a Synapse Link| SQL / Mongo DB | SQL / Mongo DB |
3232
| **Object** |Objects such as table that can be created, pointing directly to Azure Cosmos DB container| View, Table | View |

articles/synapse-analytics/synapse-link/how-to-query-analytical-store-spark.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Query Cosmos DB analytical with Synapse Spark
2+
title: Query Azure Cosmos DB analytical store with Synapse Spark
33
description: How to query Cosmos DB analytical with Synapse Spark
44
services: synapse-analytics
55
author: ArnoMicrosoft
@@ -11,7 +11,7 @@ ms.author: acomet
1111
ms.reviewer: jrasnick
1212
---
1313

14-
# Query Cosmos DB analytical with Synapse Spark
14+
# Query Azure Cosmos DB analytical store with Synapse Spark
1515

1616
This article gives some examples on how you can interact with the analytical store from Synapse gestures. Those gestures are visible when you right-click on a container. With gestures, you can quickly generate code and tweak it to your needs. They are also perfect for discovering data with a single click.
1717

@@ -30,6 +30,16 @@ df = spark.read.format("cosmos.olap")\
3030
​df.show(10)
3131
```
3232

33+
The equivalent code gesture in **Scala** would be the following code:
34+
```java
35+
// To select a preferred list of regions in a multi-region Cosmos DB account, add option("spark.cosmos.preferredRegions", "<Region1>,<Region2>")
36+
37+
val df_olap = spark.read.format("cosmos.olap").
38+
option("spark.synapse.linkedService", "pySparkSamplesDb").
39+
option("spark.cosmos.container", "trafficSourceColl").
40+
load()
41+
```
42+
3343
## Create Spark table
3444

3545
In this gesture, you will create a Spark table pointing to the container you selected. That operation does not incur any data movement. If you decide to delete that table, the underlying container (and corresponding analytical store) won't be impacted. This scenario is convenient to reuse tables through third-party tools and provide accessibility to the data for the run-time.
@@ -60,6 +70,20 @@ YOURDATAFRAME.write.format("cosmos.oltp")\
6070
.save()
6171
```
6272

73+
The equivalent code gesture in **Scala** would be the following code:
74+
```java
75+
// To select a preferred list of regions in a multi-region Cosmos DB account, add option("spark.cosmos.preferredRegions", "<Region1>,<Region2>")
76+
77+
import org.apache.spark.sql.SaveMode
78+
79+
df.write.format("cosmos.oltp").
80+
option("spark.synapse.linkedService", "pySparkSamplesDb").
81+
option("spark.cosmos.container", "trafficSourceColl").
82+
option("spark.cosmos.write.upsertEnabled", "true").
83+
mode(SaveMode.Overwrite).
84+
save()
85+
```
86+
6387
## Load streaming DataFrame from container
6488
In this gesture, you will use Spark Streaming capability to load data from a container into a dataframe. The data will be stored into the primary data lake account (and file system) that you connected to the workspace. If the folder /localReadCheckpointFolder is not created, it will be automatically created. This operation will impact the transactional performance of Cosmos DB.
6589

@@ -77,6 +101,21 @@ dfStream = spark.readStream\
77101
.load()
78102
```
79103

104+
The equivalent code gesture in **Scala** would be the following code:
105+
```java
106+
// To select a preferred list of regions in a multi-region Cosmos DB account, add .option("spark.cosmos.preferredRegions", "<Region1>,<Region2>")
107+
108+
val dfStream = spark.readStream.
109+
format("cosmos.oltp").
110+
option("spark.synapse.linkedService", "pySparkSamplesDb").
111+
option("spark.cosmos.container", "trafficSourceColl").
112+
option("spark.cosmos.changeFeed.readEnabled", "true").
113+
option("spark.cosmos.changeFeed.startFromTheBeginning", "true").
114+
option("spark.cosmos.changeFeed.checkpointLocation", "/localReadCheckpointFolder").
115+
option("spark.cosmos.changeFeed.queryName", "streamTestRevin2").
116+
load()
117+
```
118+
80119
## Write streaming DataFrame to container
81120
In this gesture, you will write a streaming dataframe into the Cosmos DB container you selected. If the folder /localReadCheckpointFolder is not created, it will be automatically created. This operation will impact the transactional performance of Cosmos DB.
82121

@@ -94,4 +133,21 @@ streamQuery = dfStream\
94133
.start()
95134

96135
streamQuery.awaitTermination()
136+
```
137+
138+
The equivalent code gesture in **Scala** would be the following code:
139+
```java
140+
// To select a preferred list of regions in a multi-region Cosmos DB account, add .option("spark.cosmos.preferredRegions", "<Region1>,<Region2>")
141+
142+
val query = dfStream.
143+
writeStream.
144+
format("cosmos.oltp").
145+
outputMode("append").
146+
option("checkpointLocation", "/localWriteCheckpointFolder").
147+
option("spark.synapse.linkedService", "pySparkSamplesDb").
148+
option("spark.cosmos.container", "test2").
149+
option("spark.cosmos.connection.mode", "gateway").
150+
start()
151+
152+
query.awaitTermination()
97153
```

0 commit comments

Comments
 (0)