コード例 #1
0
 /**
  * Helper for providing a JSON string as a value for a setting.
  *
  * @param conf the Configuration
  * @param key the key for the setting
  * @param value the JSON string value
  */
 public static void setJSON(final Configuration conf, final String key, final String value) {
   try {
     final Object dbObj = JSON.parse(value);
     setDBObject(conf, key, (DBObject) dbObj);
   } catch (final Exception e) {
     LOG.error("Cannot parse JSON...", e);
     throw new IllegalArgumentException(
         "Provided JSON String is not representable/parseable as a DBObject.", e);
   }
 }
コード例 #2
0
 public static Configuration buildConfiguration(final Map<String, Object> data) {
   Configuration newConf = new Configuration();
   for (Entry<String, Object> entry : data.entrySet()) {
     String key = entry.getKey();
     Object val = entry.getValue();
     if (val instanceof String) {
       newConf.set(key, (String) val);
     } else if (val instanceof Boolean) {
       newConf.setBoolean(key, (Boolean) val);
     } else if (val instanceof Integer) {
       newConf.setInt(key, (Integer) val);
     } else if (val instanceof Float) {
       newConf.setFloat(key, (Float) val);
     } else if (val instanceof DBObject) {
       setDBObject(newConf, key, (DBObject) val);
     } else {
       throw new RuntimeException(
           "can't convert " + val.getClass() + " into any type for Configuration");
     }
   }
   return newConf;
 }
コード例 #3
0
 public static void setInputSplitKey(final Configuration conf, final DBObject key) {
   setDBObject(conf, INPUT_SPLIT_KEY_PATTERN, key);
 }
コード例 #4
0
 /**
  * Specify the sort order as a DBObject.
  *
  * @param conf the Configuration
  * @param sort the sort document
  */
 public static void setSort(final Configuration conf, final DBObject sort) {
   setDBObject(conf, INPUT_SORT, sort);
 }
コード例 #5
0
 /**
  * Specify a projection document for documents retrieved from MongoDB.
  *
  * @param conf the Configuration
  * @param fields a projection document
  */
 public static void setFields(final Configuration conf, final DBObject fields) {
   setDBObject(conf, INPUT_FIELDS, fields);
 }
コード例 #6
0
 /**
  * Set the query set for the Job using a DBObject.
  *
  * @param conf the Configuration
  * @param query the query
  */
 public static void setQuery(final Configuration conf, final DBObject query) {
   setDBObject(conf, INPUT_QUERY, query);
 }