Example usage for org.apache.hadoop.typedbytes TypedBytesWritable toString

List of usage examples for org.apache.hadoop.typedbytes TypedBytesWritable toString

Introduction

In this page you can find the example usage for org.apache.hadoop.typedbytes TypedBytesWritable toString.

Prototype

public String toString() 

Source Link

Document

Generate a suitable string representation.

Usage

From source file:com.mongodb.hadoop.typedbytes.MongoRecordWriter.java

License:Apache License

public void write(TypedBytesWritable key, TypedBytesWritable value) throws IOException {
    //TODO: Use _fields to set the output properties of a MongoDocument
    if (key == null || value == null) {
        return;/*  w  ww .j  a  va2 s .c  o m*/
    }
    final DBObject o = new BasicDBObject();

    //log.info( "Writing out data {k: " + key + ", value:  " + value);
    if (key instanceof MongoOutput) {
        ((MongoOutput) key).appendAsKey(o);
    } else if (key instanceof BSONObject) {
        o.put("_id", key);
    } else {
        //log.info( "Writing out key: " + key );
        o.put("my_key", key.toString());
        //o.put("_id", toBSON(key));
    }

    if (value instanceof MongoOutput) {
        ((MongoOutput) value).appendAsValue(o);
    } else if (value instanceof BSONObject) {
        o.putAll((BSONObject) value);
    } else {
        //log.info( "Writing out value: " + value );
        o.put("my_val", value.toString());
        //o.put("value", toBSON(value));
    }

    try {
        _collection.save(o);
    } catch (final MongoException e) {
        throw new IOException("can't write to mongo", e);
    }
}