Package com.mongodb

Examples of com.mongodb.MongoClientURI


        transferData(HDFS_BACKED_TABLE, MONGO_BACKED_TABLE);
    }

    public void createMongoBackedTable(final boolean withSerDeProps) {
        dropTable(MONGO_BACKED_TABLE);
        MongoClientURI uri = authCheck(new MongoClientURIBuilder()
                                           .collection("mongo_hadoop", MONGO_COLLECTION)
                                      ).build();
        execute(format("CREATE TABLE %s %s\n"
                       + "STORED BY '%s'\n"
                       + (withSerDeProps ? format("WITH SERDEPROPERTIES(%s)\n", SERDE_PROPERTIES) : "")
View Full Code Here


        collection.insert(user(1, "Jim", "Beam", "Clermont", "KY"));
        collection.insert(user(2, "Don", "Draper", "New York", "NY"));
        collection.insert(user(3, "John", "Elway", "Denver", "CO"));

        MongoClientURI uri = authCheck(new MongoClientURIBuilder()
                                           .collection("mongo_hadoop", collection.getName())
                                      ).build();

        ColumnMapping map = new ColumnMapping()
                                .map("id", "_id", "INT")
View Full Code Here

                                  .append("intField", i % 10)
                                  .append("booleanField", i % 2 == 0)
                                  .append("stringField", "" + (i % 2 == 0)));
        }

        MongoClientURI uri = authCheck(new MongoClientURIBuilder()
                                           .collection("mongo_hadoop", collection.getName())
                                      ).build();

        ColumnMapping map = new ColumnMapping()
                                .map("id", "_id", "INT")
View Full Code Here

        loadIntoHDFS(new File(EXAMPLE_DATA_HOME, "dump/enron_mail/messages.bson").getAbsolutePath(), "/user/hive/warehouse/enron");

        ColumnMapping map = new ColumnMapping()
                                .map("id", "_id", "INT")
                                .map("subFolder", "subFolder", "STRING");
        MongoClientURI uri = authCheck(new MongoClientURIBuilder()
                                           .collection("mongo_hadoop", collection.getName())
                                      ).build();
        execute(format("CREATE EXTERNAL TABLE %s (body STRING, subFolder STRING, mailbox STRING, filename STRING)\n"
                       + "ROW FORMAT SERDE '%s'\n"
                       + "WITH SERDEPROPERTIES('%s'='%s')\n"
View Full Code Here

        final String raw = conf.get(key);
        if (raw != null && !raw.trim().isEmpty()) {
            List<MongoClientURI> result = new LinkedList<MongoClientURI>();
            String[] split = StringUtils.split(raw, ", ");
            for (String mongoURI : split) {
                result.add(new MongoClientURI(mongoURI));
            }
            return result;
        } else {
            return Collections.emptyList();
        }
View Full Code Here

        }
    }
   
    public static MongoClientURI getMongoClientURI(final Configuration conf, final String key) {
        final String raw = conf.get(key);
        return raw != null && !raw.trim().isEmpty() ? new MongoClientURI(raw) : null;
    }
View Full Code Here

    /**
     * @deprecated use {@link #getCollection(MongoClientURI)}
     */
    @Deprecated
    public static DBCollection getCollection(final MongoURI uri) {
        return getCollection(new MongoClientURI(uri.toString()));
    }
View Full Code Here

    /**
     * @deprecated use {@link #getCollectionWithAuth(MongoClientURI, MongoClientURI)} instead
     */
    @Deprecated
    public static DBCollection getCollectionWithAuth(final MongoURI uri, final MongoURI authURI) {
        return getCollectionWithAuth(new MongoClientURI(uri.toString()), new MongoClientURI(authURI.toString()));
    }
View Full Code Here

        conf.set(key, value.toString()); // todo - verify you can toString a
        // URI object
    }

    public static void setMongoURIString(final Configuration conf, final String key, final String value) {
        setMongoURI(conf, key, new MongoClientURI(value));
    }
View Full Code Here

        final int splitSize = MongoConfigUtil.getSplitSize(getConfiguration());

        final ArrayList<InputSplit> returnVal = new ArrayList<InputSplit>();
        final String ns = inputCollection.getFullName();

        MongoClientURI inputURI = MongoConfigUtil.getInputURI(getConfiguration());

        LOG.info("Running splitvector to check splits against " + inputURI);
        final DBObject cmd = BasicDBObjectBuilder.start("splitVector", ns)
                                 .add("keyPattern", splitKey)
                                      // force:True is misbehaving it seems
                                 .add("force", false)
                                 .add("maxChunkSize", splitSize)
                                 .get();

        CommandResult data;
        boolean ok = true;
        if (authDB == null) {
            try {
                data = inputCollection.getDB().getSisterDB("admin").command(cmd);
            } catch (MongoException e) {  // 2.0 servers throw exceptions rather than info in a CommandResult
                data = null;
                LOG.info(e.getMessage(), e);
                if (e.getMessage().contains("unrecognized command: splitVector")) {
                    ok = false;
                } else {
                    throw e;
                }
            }
        } else {
            data = authDB.command(cmd);
        }

        if (data != null) {
            if (data.containsField("$err")) {
                throw new SplitFailedException("Error calculating splits: " + data);
            } else if (!data.get("ok").equals(1.0)) {
                ok = false;
            }
        }

        if (!ok) {
            CommandResult stats = inputCollection.getStats();
            if (stats.containsField("primary")) {
                DBCursor shards = inputCollection.getDB().getSisterDB("config")
                                                 .getCollection("shards")
                                                 .find(new BasicDBObject("_id", stats.getString("primary")));
                try {
                    if (shards.hasNext()) {
                        DBObject shard = shards.next();
                        String host = ((String) shard.get("host")).replace(shard.get("_id") + "/", "");
                        MongoClientURI shardHost = new MongoClientURIBuilder(inputURI)
                                                       .host(host)
                                                       .build();
                        MongoClient shardClient = null;
                        try {
                            shardClient = new MongoClient(shardHost);
View Full Code Here

TOP

Related Classes of com.mongodb.MongoClientURI

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.