Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package edu.jhuapl.tinkerpop.mapreduce;
  
  import java.util.Iterator;
  
 import  org.apache.hadoop.io.Text;
 import  org.apache.hadoop.mapreduce.InputSplit;
 import  org.apache.hadoop.mapreduce.Job;
 import  org.apache.hadoop.mapreduce.RecordReader;
 import  org.apache.hadoop.mapreduce.TaskAttemptContext;
 
 
 
 public class EdgeInputFormat extends InputFormatBase<Text,Edge> {
 
   private static final String PREFIX = EdgeInputFormat.class.getSimpleName()+".";
   private static final String GRAPH_NAME = +"graph.name";
 
 
   @Override
   public RecordReader<Text,EdgecreateRecordReader(InputSplit split, TaskAttemptContext attemptthrows IOExceptionInterruptedException {
     return new EdgeRecordReader();
   }
 
   private class EdgeRecordReader extends RecordReaderBase<Text,Edge> {
 
 
     EdgeRecordReader() {}
 
     @Override
     public void initialize(InputSplit inSplit, TaskAttemptContext attemptthrows IOException {
 
       super.initialize(inSplitattempt);
        = new RowIterator();
 
        = new Text();
 
       try {
          = new AccumuloGraphConfiguration();
         .setZooKeeperHosts(EdgeInputFormat.getInstance(attempt).getZooKeepers());
         .setInstanceName(EdgeInputFormat.getInstance(attempt).getInstanceName());
         .setUser(EdgeInputFormat.getPrincipal(attempt));
         .setPassword(EdgeInputFormat.getToken(attempt));
         .setGraphName(attempt.getConfiguration().get());
         if (EdgeInputFormat.getInstance(attemptinstanceof MockInstance) {
           .setInstanceType(.);
         }
          = AccumuloGraph.open(.getConfiguration());
       } catch (AccumuloException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
 
     }
 
     @Override
     public boolean nextKeyValue() throws IOExceptionInterruptedException {
       if (.hasNext()) {
         Iterator<Entry<Key,Value>> it = .next();
 
         MapReduceEdge edge = new MapReduceEdge();
         while (it.hasNext()) {
           Entry<Key,Valueentry = it.next();
           ++;
 
            = entry.getKey();
           String eid = .getRow().toString();
           String colf = .getColumnFamily().toString();
           switch (colf) {
             case .:
               .set(eid);
               edge.prepareId(eid);
               String[] ids = .getColumnQualifier().toString().split(.);
               edge.setSourceId(ids[1]);
               edge.setDestId(ids[0]);
               edge.setLabel(AccumuloByteSerializer.deserialize(entry.getValue().get()).toString());
               break;
             default:
               String propertyKey = .getColumnFamily().toString();
               Object propertyValue = AccumuloByteSerializer.deserialize(entry.getValue().get());
               edge.prepareProperty(propertyKeypropertyValue);
          }
        }
         = edge;
        return true;
      }
      return false;
    }
  }
  public static void setAccumuloGraphConfiguration(Job jobAccumuloGraphConfiguration cfgthrows AccumuloSecurityException {
    EdgeInputFormat.setConnectorInfo(jobcfg.getUser(), new PasswordToken(cfg.getPassword()));
    EdgeInputFormat.setInputTableName(jobcfg.getEdgeTableName());
    if (cfg.getInstanceType().equals(.)) {
      EdgeInputFormat.setMockInstance(jobcfg.getInstanceName());
    } else {
      EdgeInputFormat.setZooKeeperInstance(jobcfg.getInstanceName(), cfg.getZooKeeperHosts());
    }
    job.getConfiguration().set(cfg.getGraphName());
  }
New to GrepCode? Check out our FAQ X