首页 > 解决方案 > 错误:写入非空集合

问题描述

我在将 json 写入我的 Cosmos DB 时遇到了问题。我可以在编写相同的数据时读取数据并遇到问题

应用了以下版本的 Cosmos db 连接器 https://docs.azuredatabricks.net/spark/latest/data-sources/azure/cosmosdb-connector.html 并尝试了不同的版本。这个问题仍然存在。

RawFilePath="/mnt/ADLS/Users/test/CosmosDB/testfile.json"
DFRead=spark.read.json(RawFilePath)
DFNew = DFRead.selectExpr("activity", "partition AS xfactor","response", "source", "type")

writeConfig  = {
 "Endpoint" : "{End Point}",
 "Masterkey" : "{MasterKey}",
 "Database" : "{DB Name}",
 "Collection" : "{Connection name}",
 "Upsert" : "true"   
}

DFNew.write.format("com.microsoft.azure.cosmosdb.spark").options(**writeConfig).save()

收到以下错误。

Error : java.lang.UnsupportedOperationException: Writing in a non-empty collection.

期望将 json 写入 cosmos DB 集合。但是,无法解决 Databricks 中的非空集合错误。非常感谢您的帮助。

谢谢你..

标签: python-3.xapache-sparkazure-cosmosdbdatabricksazure-databricks

解决方案


通过指定模式尝试

DFNew.write.format("com.microsoft.azure.cosmosdb.spark").mode("append").options(**writeConfig).save()

推荐阅读