Demo entry 2842834

Java code

   

Submitted by alim on Oct 16, 2015 at 08:31
Language: Java. Code size: 1.2 kB.

	


package com.aug.maxiq.extn.sample;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.sql.DataFrame;
import com.augmentiq.maxiq.extenation.MaxiqType1Job;
public class MongoLoader<T, M> implements MaxiqType1Job<T, M>, Serializable {

   String collectionName;
   Map<String, String> params_ = new HashMap<String, String>();

   public boolean init(Map<String, String> params) {
      collectionName = params.get("COLLECTION");
      params_ = params;
        return true;
    }

   public Map run(Map values) {

      try {
         Set<String> keys = values.keySet();
         for (String key : keys) {
            DataFrame df = (DataFrame) values.get(key);
            df.show();

            final String[] fieldNames = df.schema().fieldNames();

            MongoInsert insert = new MongoInsert(fieldNames, collectionName, params_);
            JavaRDD<String> map = df.javaRDD().map(insert);

            map.count();
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
      return null;
   }
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).