简体   繁体   English

使用Java在MongoDB上使用Hadoop Mapreduce

[英]Hadoop mapreduce on MongoDB using java

I'm working on a MongoDB structure that has a tree structure.. as given in this link ( see docs ) 我正在一个具有树结构的MongoDB结构上工作..如本链接所示( 请参阅docs

I would like to know what will be passed in the key in the map method. 我想知道map方法中的键将传递什么。 Is it the topmost parent in the tree ans should i iterate to get my value list. 它是否是树中最顶层的父项,我应该迭代来获取我的值列表。

I have a tree structure that has company as parent and company name, website,product etc as children. 我有一个树形结构,其中以公司为父级,公司名称,网站,产品等为子级。 The product will in turn have product name as its child. 该产品将依次使用产品名称作为其子代。

So, if i need the company name to be the key, how should i get it using java? 因此,如果我需要公司名称作为密钥,那么我应该如何使用Java获得它?

What will be the key here - company ? 公司的关键是什么?

If there is any sample program or documentation for doing mapreduce over mongoDB in java, can anyone please provide me asap? 如果有任何示例程序或文档可用于在Java中通过mongoDB进行mapreduce,请有人尽快提供给我吗?

Thanks 谢谢

Thanks Trisha. 感谢Trisha。 The above link is doing the in-built map reduce thats available in MongoDB. 上面的链接正在执行内置地图,以减少MongoDB中可用的地图。 I wanted an example for a Map Reduce using Hadoop and MongoDB. 我想要一个使用Hadoop和MongoDB的Map Reduce的示例。 I have finally figured it out. 我终于想通了。

public static class MongoMapper extends
        Mapper<Object, BasicDBObject, Text, BSONWritable> {


    public void map(Object key, BasicDBObject value, Context context)
            throws IOException, InterruptedException {


        //This gives all the documents of the company
        BasicDBObject company = (BasicDBObject) value.get("company");

        // This gets the company name
        name = (String) company.get("name");

        //This gives the phone number 
        phone = (String) company.get("phone");

If we need to access the product list in company we can retrieve using a BasicDBList 如果需要访问公司中的产品列表,可以使用BasicDBList进行检索

// This will give the list of products and we can use product.get()
// to get the product name and other details. 
BasicDBList product = (BasicDBList) company.get("products");

I referred to this slideshare link. 我提到了此幻灯片共享链接。

http://www.slideshare.net/spf13/introduction-to-mongodb-and-hadoop http://www.slideshare.net/spf13/introduction-to-mongodb-and-hadoop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM