You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Improve Cosmos DB Live migration
* cosmos-db-parallel-container-migration
* applied suggestions & bug fix
* Fixed media to reflect new notebooks names
valcosmosEndpoint_cf=""//enter the Cosmos DB Account URI of the source account
3
-
valcosmosMasterKey_cf=""//enter the Cosmos DB Account PRIMARY KEY of the source account
4
-
valcosmosDatabaseName_cf="database-v4"//replace database-v4 with the name of your source database
5
-
valcosmosContainerName_cf="customer"//replace customer with the name of the container you want to migrate
6
-
valcosmosContainerName_throughputControl="0.95"//targetThroughputThreshold defines target percentage (here it is 95%) of available throughput you want the migration to use
7
-
8
-
valcosmosEndpoint_write=""//enter the Cosmos DB Account URI of the target account
9
-
valcosmosMasterKey_write=""//enter the Cosmos DB Account PRIMARY KEY of the target account
10
-
valcosmosDatabaseName_write="database-v4"//replace this with the name of your target database
11
-
valcosmosContainerName_write="customer_v2"//replace this with what you want to name your target container
dbutils.widgets.text("cosmosEndpoint", "") // enter the Cosmos DB Account URI of the source account
8
+
dbutils.widgets.text("cosmosMasterKey", "") // enter the Cosmos DB Account PRIMARY KEY of the source account
9
+
dbutils.widgets.text("cosmosRegion", "") // enter the Cosmos DB Region
10
+
11
+
// source config
12
+
dbutils.widgets.text("cosmosSourceDatabaseName", "") // enter the name of your source database
13
+
dbutils.widgets.text("cosmosSourceContainerName", "") // enter the name of the container you want to migrate
14
+
dbutils.widgets.text("cosmosSourceContainerThroughputControl", "") // targetThroughputThreshold defines target percentage of available throughput you want the migration to use
15
+
16
+
// target config
17
+
dbutils.widgets.text("cosmosTargetDatabaseName", "") // enter the name of your target database
18
+
dbutils.widgets.text("cosmosTargetContainerName", "") // enter the name of the target container
19
+
dbutils.widgets.text("cosmosTargetContainerPartitionKey", "") // enter the partition key for how data is stored in the target container
20
+
dbutils.widgets.text("cosmosTargetContainerProvisionedThroughput", "") // enter the partition key for how data is stored in the target container
18
21
19
22
// COMMAND ----------
20
23
21
-
// MAGIC %sql
22
-
// MAGIC /* NOTE: It is important to enable TTL (can be off/-1 by default) on the throughput control container */
23
-
// MAGIC CREATE TABLE IF NOT EXISTS cosmosCatalog.`database-v4`.ThroughputControl -- replace database-v4 with source database name - ThroughputControl table will be created there
24
-
// MAGIC USING cosmos.oltp
25
-
// MAGIC OPTIONS(spark.cosmos.database = 'database-v4') -- replace database-v4 with the name of your source database
// MAGIC CREATE TABLE IF NOT EXISTS cosmosCatalog.`database-v4`.customer_v2 -- replace database-v4 with the name of your source database, and customer_v2 with what you want to name your target container - it will be created here
29
-
// MAGIC USING cosmos.oltp
30
-
// MAGIC -- replace /customerId with the name of the field that you want to be used as the partition key in the new version of the container
valquery=s"CREATE DATABASE IF NOT EXISTS cosmosCatalog.`$cosmosDatabaseName` $cosmosDatabaseOptions;"
59
+
println("Executing create database...")
60
+
println(query.trim())
61
+
try {
62
+
spark.sql(query)
63
+
} catch {
64
+
case e:Exception=> println(e)
65
+
}
66
+
}
67
+
68
+
defcreateThroughtputControlTable(cosmosDatabaseName: String){/* NOTE: It is important to enable TTL (can be off/-1 by default) on the throughput control container */
69
+
valquery=s"""
70
+
CREATE TABLE IF NOT EXISTS cosmosCatalog.`$cosmosDatabaseName`.`ThroughputControl` USING cosmos.oltp
/*this will preserve the source document fields and retain the "_etag" and "_ts" property values as "_origin_etag" and "_origin_ts" in the sink documnet*/
/*this will preserve the source document fields and retain the "_etag" and "_ts" property values as "_origin_etag" and "_origin_ts" in the sink documnet*/
0 commit comments