Skip to content

Commit def69c8

Browse files
authored
Merge pull request #114593 from ArnoMicrosoft/arnaud-synapse-582020
Arnaud synapse 582020
2 parents a5071d2 + 287dbc8 commit def69c8

File tree

3 files changed

+65
-12
lines changed

3 files changed

+65
-12
lines changed

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

Lines changed: 5 additions & 8 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 |
@@ -39,7 +39,7 @@ Here is list of the currently supported features within Synapse Link for Cosmos
3939
## Supported code-generated actions for Spark
4040

4141
| Gesture | Description |OLTP |HTAP |
42-
| :-------------------- | :----------------------------------------------------------- |:----------------------------------------------------------- |:----------------------------------------------------------- |
42+
| -------------------- | ----------------------------------------------------------- |----------------------------------------------------------- |----------------------------------------------------------- |
4343
| **Load to DataFrame** |Load and read data into a Spark DataFrame |X||
4444
| **Create Spark table** |Create a table pointing to an Azure Cosmos DB container|X||
4545
| **Write DataFrame to container** |Write data into a container|||
@@ -51,13 +51,10 @@ Here is list of the currently supported features within Synapse Link for Cosmos
5151
## Supported code-generated actions for SQL serverless
5252

5353
| Gesture | Description |OLTP |HTAP |
54-
=======
55-
| :-------------------- | :----------------------------------------------------------- |:----------------------------------------------------------- |:----------------------------------------------------------- |
54+
| -------------------- | ----------------------------------------------------------- |----------------------------------------------------------- |----------------------------------------------------------- |
5655
| **Select top 100** |Preview top 100 items from a container|X||
5756
| **Create view** |Create a view to directly have BI access in a container through Synapse SQL|X||
5857

5958
## Next steps
6059

61-
See how to [connect to Synapse Link for Azure Cosmos DB](./how-to-connect-synapse-link-cosmos-db.md)
62-
63-
60+
See how to [connect to Synapse Link for Azure Cosmos DB](./how-to-connect-synapse-link-cosmos-db.md)

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
```

articles/synapse-analytics/toc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,9 @@
414414
items:
415415
- name: Synapse Link
416416
items:
417-
- name: Connect to Synapse Link for Cosmos DB
417+
- name: Connect to Azure Synapse Link for Cosmos DB
418418
href: ./synapse-link/how-to-connect-synapse-link-cosmos-db.md
419-
- name: Query analytical store with Spark
419+
- name: Query Azure Cosmos DB analytical store with Synapse Spark
420420
href: ./synapse-link/how-to-query-analytical-store-spark.md
421421
- name: Synapse SQL
422422
items:

0 commit comments

Comments
 (0)