@Override public void write(Writable w) throws IOException { MapWritable map = (MapWritable) w; BasicDBObject dbo = new BasicDBObject(); for (final Map.Entry<Writable, Writable> entry : map.entrySet()) { // System.err.println("Write: key=" + entry.getKey().toString() // + ", val=" + entry.getValue().toString()); String key = entry.getKey().toString(); // if ("id".equals(key)) { // key = "_id"; // } dbo.put(key, getObjectFromWritable(entry.getValue())); } table.save(dbo); }
public MongoReader( String dbHost, String dbPort, String dbName, String dbUser, String dbPasswd, String colName, MongoSplit split, String[] readColumns) { this.table = new MongoTable(dbHost, dbPort, dbName, dbUser, dbPasswd, colName); this.split = split; this.readColumns = readColumns; this.cursor = table.findAll(readColumns).batchSize(BATCH_SIZE).skip((int) split.getStart()); if (!split.isLastSplit()) this.cursor.limit((int) split.getLength()); // if it's the last // split,it will read // all records since // $start }
@Override public void close() throws IOException { if (table != null) table.close(); }