【发布时间】:2020-02-02 14:44:50
【问题描述】:
我在 Databricks Notebook 上编写了以下 PySpark 代码,该代码成功地将结果从 sparkSQL 保存到 Azure Cosmos DB,并使用以下代码行:
df.write.format("com.microsoft.azure.cosmosdb.spark").mode("overwrite").options(**writeConfig3).save()
完整代码如下:
test = spark.sql("""SELECT
Sales.CustomerID AS pattersonID1
,Sales.InvoiceNumber AS myinvoicenr1
FROM Sales
limit 4""")
## my personal cosmos DB
writeConfig3 = {
"Endpoint": "https://<cosmosdb-account>.documents.azure.com:443/",
"Masterkey": "<key>==",
"Database": "mydatabase",
"Collection": "mycontainer",
"Upsert": "true"
}
df = test.coalesce(1)
df.write.format("com.microsoft.azure.cosmosdb.spark").mode("overwrite").options(**writeConfig3).save()
使用上面的代码,我已成功写入我的 Cosmos DB 数据库 (mydatabase) 和集合 (mycontainer)
当我尝试通过更改 SparkSQL 来覆盖容器时(只需将 patersonID1 更改为 patersonID2,并将 myinvoicenr1 更改为 myinvoicenr2
test = spark.sql("""SELECT
Sales.CustomerID AS pattersonID2
,Sales.InvoiceNumber AS myinvoicenr2
FROM Sales
limit 4""")
使用新查询覆盖/更新集合,Cosmos DB 会按如下方式附加容器:
并且仍然将原始查询留在集合中:
有没有办法完全覆盖或更新 cosmos DB?
【问题讨论】:
-
哎呀——你刚刚嵌入了你的 Cosmos DB 密钥并将它分享给了全世界。请尽快重新生成您的密钥。我编辑了帐户名称和他们的问题,但任何有足够代表的人都可以看到修订历史记录。
-
感谢大卫,密钥已重新生成。谢谢
标签: pyspark azure-cosmosdb pyspark-sql azure-databricks