2017-08-03 30 views
2

我与Apache星火在斯卡拉在Azure CosmosDB连接器玩耍,并想知道如果任何人对我会怎么写我的数据帧回到集合在我CosmosDB例子或洞察力。目前,我能够连接到我的一个集合并返回数据并对其进行处理,但是我想将结果写回同一个数据库内的不同集合。阿帕奇星火斯卡拉CosmosDB连接器写作数据帧返回到数据库

我创造,我要写入包含我的终点MasterKey,数据库中的一个writeConfig,和收集。

然后我尝试使用以下行将其写入集合。

manipulatedData.toJSON.write.mode(SaveMode.Overwrite).cosmosDB(writeConfig) 

这运行正常,并且不显示任何错误,但没有什么是显示在我的收藏起来。

我通过文件去我能找到在https://github.com/Azure/azure-cosmosdb-spark,但没有多少运气找到写入数据的任何示例回数据库。

如果有写入documentDB/cosmosDB比我做的更简单的方法?我愿意接受任何选择。

感谢您的任何帮助。

回答

3

您可以直接保存到宇宙DB从星火数据帧就像你已经注意到。您可能不需要使用toJSON,例如:

// Import SaveMode so you can Overwrite, Append, ErrorIfExists, Ignore 
import org.apache.spark.sql.{Row, SaveMode, SparkSession} 

// Create new DataFrame `df` which has slightly flights information 
// i.e. change the delay value to -999 
val df = spark.sql("select -999 as delay, distance, origin, date, destination from c limit 5") 

// Save to Cosmos DB (using Append in this case) 
// Ensure the baseConfig contains a Read-Write Key 
// The key provided in our examples is a Read-Only Key 
df.write.mode(SaveMode.Append).cosmosDB(baseConfig) 

至于文档,你是在保存功能应该被更好地叫出正确的。我已经创建了Include in User Guide/sample scripts how to save to Cosmos DB #91来解决这个问题。

至于使用只读键而不是读写键保存,但看到没有错误,万一被你的配置?我刚刚创建了Saving to CosmosDB using read-only key has no error #92,呼叫了同样的问题。

相关问题