2017-04-24 28 views
1

我想使用DocumentDB,但PySpark没有连接器。看起来像DocumentDB也支持MongoDB Protocol as mentioned here,这意味着所有现有的MongoDB驱动程序应该工作。由于有PySpark connector for MongoDB,我想尝试一下。带有MongoDB协议的Azure DocumentDB Spark集成

df = spark.read.format("com.mongodb.spark.sql.DefaultSource").load() 

这会引发错误。

com.mongodb.MongoCommandException: Command failed with error 115: ''$sample' is not supported' on server example.documents.azure.com:10250. The full response is { "_t" : "OKMongoResponse", "ok" : 0, "code" : 115, "errmsg" : "'$sample' is not supported", "$err" : "'$sample' is not supported" } 

它看起来像DocumentDB MongoDB的API不支持MongoDB的所有功能,但我找不到任何文档。还是我错过了别的?

回答

3

我想使用DocumentDB,但PySpark没有连接器。

一个Spark to DocumentDB connector(包括pyDocumentDB package)的预览是在四月初提供2017

貌似DocumentDB还支持MongoDB Protocol as mentioned here,这意味着所有现存的MongoDB驱动程序应该工作

DocumentDB支持用于通信的MongoDB有线协议,并将其版本报告为MongoDB 3.2.0,但这并不意味着它是全面支持所有MongoDB功能的直接替代品(或DocumentDB实现具有相同行为和限制的功能)。目前一个值得注意的缺失是对MongoDB的聚合管道的任何支持,其中包括$sample运算符,PySpark连接器预计可用于连接到声称为MongoDB 3.2的服务器。

您可以在您的问题中引用的DocumentDB API for MongoDB文档的注释中找到潜在兼容性问题的更多示例。

+0

感谢您的回答。这就是我的想法。 – chhantyal

+0

与'PyDocumentDB'一起使用是不够的。因为根据文档中给出的示例,在创建DataFrame之前,您必须在内存中显式转换为Python数据类型,但它不适用于大量数据。 – chhantyal

+0

@chhantyal对于大量数据,解决方法是按切片查询多个数据帧并使用['union'](http://spark.apache.org/docs/latest/api/python/pyspark.sql.html #pyspark.sql.DataFrame.union)方法来生成包含所有小尺寸数据框的新数据框。 –