java类org.apache.hadoop.mapreduce.lib.input.MultipleInputs的实例源码

Multiplication.java 文件源码 项目:mapreduce-samples 阅读 35 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();

    Job job = Job.getInstance(conf);
    job.setJarByClass(Multiplication.class);

    ChainMapper.addMapper(job, CooccurrenceMapper.class, LongWritable.class, Text.class, Text.class, Text.class, conf);
    ChainMapper.addMapper(job, RatingMapper.class, Text.class, Text.class, Text.class, Text.class, conf);

    job.setMapperClass(CooccurrenceMapper.class);
    job.setMapperClass(RatingMapper.class);

    job.setReducerClass(MultiplicationReducer.class);

    job.setMapOutputKeyClass(Text.class);
    job.setMapOutputValueClass(Text.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(DoubleWritable.class);

    MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class, CooccurrenceMapper.class);
    MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, RatingMapper.class);

    TextOutputFormat.setOutputPath(job, new Path(args[2]));

    job.waitForCompletion(true);
}
UnitMultiplication.java 文件源码 项目:mapreduce-samples 阅读 32 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {

        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);
        job.setJarByClass(UnitMultiplication.class);

        ChainMapper.addMapper(job, TransitionMapper.class, Object.class, Text.class, Text.class, Text.class, conf);
        ChainMapper.addMapper(job, PRMapper.class, Object.class, Text.class, Text.class, Text.class, conf);

        job.setReducerClass(MultiplicationReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class, TransitionMapper.class);
        MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, PRMapper.class);

        FileOutputFormat.setOutputPath(job, new Path(args[2]));
        job.waitForCompletion(true);
    }
UnitMultiplication.java 文件源码 项目:mapreduce-samples 阅读 47 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {

        Configuration conf = new Configuration();
        conf.setFloat("beta", Float.parseFloat(args[3]));
        Job job = Job.getInstance(conf);
        job.setJarByClass(UnitMultiplication.class);

        ChainMapper.addMapper(job, TransitionMapper.class, Object.class, Text.class, Text.class, Text.class, conf);
        ChainMapper.addMapper(job, PRMapper.class, Object.class, Text.class, Text.class, Text.class, conf);

        job.setReducerClass(MultiplicationReducer.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(Text.class);

        MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class, TransitionMapper.class);
        MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, PRMapper.class);

        FileOutputFormat.setOutputPath(job, new Path(args[2]));
        job.waitForCompletion(true);
    }
UnitSum.java 文件源码 项目:mapreduce-samples 阅读 42 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {

        Configuration conf = new Configuration();
        conf.setFloat("beta", Float.parseFloat(args[3]));
        Job job = Job.getInstance(conf);
        job.setJarByClass(UnitSum.class);

        ChainMapper.addMapper(job, PassMapper.class, Object.class, Text.class, Text.class, DoubleWritable.class, conf);
        ChainMapper.addMapper(job, BetaMapper.class, Text.class, DoubleWritable.class, Text.class, DoubleWritable.class, conf);

        job.setReducerClass(SumReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(DoubleWritable.class);

        MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class, PassMapper.class);
        MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, BetaMapper.class);

        FileOutputFormat.setOutputPath(job, new Path(args[2]));
        job.waitForCompletion(true);
    }
ReduceJoin.java 文件源码 项目:Data-Science-with-Hadoop 阅读 33 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = new Job(conf, "Reduce-side join");
    job.setJarByClass(ReduceJoin.class);
    job.setReducerClass(ReduceJoinReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);
    MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class, SalesRecordMapper.class) ;
    MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, AccountRecordMapper.class) ;
    //        FileOutputFormat.setOutputPath(job, new Path(args[2]));
    Path outputPath = new Path(args[2]);
    FileOutputFormat.setOutputPath(job, outputPath);
    outputPath.getFileSystem(conf).delete(outputPath);

    System.exit(job.waitForCompletion(true) ? 0 : 1);
}
BookMerger.java 文件源码 项目:book-merger 阅读 34 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = Job.getInstance(conf, "book merger");

    job.setJarByClass(BookMerger.class);
    job.setCombinerClass(BookDataReducer.class);
    job.setReducerClass(BookDataReducer.class);
    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(BookMapWritable.class);

    FileOutputFormat.setOutputPath(job, new Path(args[0]));
    MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class, CanonicalMapper.class);
    MultipleInputs.addInputPath(job, new Path(args[2]), TextInputFormat.class, LibraryThingMapper.class);
    MultipleInputs.addInputPath(job, new Path(args[3]), TextInputFormat.class, LTScrapedMapper.class);

    job.waitForCompletion(true);
}
MultiInputAnnotationHandler.java 文件源码 项目:mara 阅读 43 收藏 0 点赞 0 评论 0
@Override
public void process(Annotation annotation, Job job, Object target)
        throws ToolException {
    for (Input input : ((MultiInput)annotation).value()) {
        Path path = getInputAsPath(input.path());
        if (input.mapper() == Mapper.class) {
            MultipleInputs.addInputPath(job, path, input.format());
        }
        else {
            MultipleInputs.addInputPath(job, path, input.format(), input.mapper());
            // Need to call again here so the call is captured by our aspect which
            // will replace it with the annotated delegating mapper class for resource
            // injection if required.
            job.setMapperClass(DelegatingMapper.class);
        }
    }
}
JobAnnotationUtilTest.java 文件源码 项目:mara 阅读 36 收藏 0 点赞 0 评论 0
@Test @Ignore // NOT WORKING
public void testConfigureJobFromClass() {
    Class<?> clazz = TestMapper.class;

    try {
        PowerMockito.mockStatic(MultipleInputs.class);

        // Now configure
        PowerMockito.verifyStatic(Mockito.times(6));
        annotationUtil.configureJobFromClass(clazz, job);

    } catch (ToolException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
TestReduceSideJoin.java 文件源码 项目:book-hadoop-hacks 阅读 34 收藏 0 点赞 0 评论 0
public int run(String[] args) throws Exception {
    Job job=Job.getInstance(getConf(), "reduce side join");
    job.setJarByClass(getClass());

    MultipleInputs.addInputPath(job, new Path(args[0]), TextInputFormat.class,ReduceSideJoinMasterMap.class);
    MultipleInputs.addInputPath(job, new Path(args[1]), TextInputFormat.class,ReduceSideJoinMasterMap.class);

    job.setMapOutputKeyClass(IntPair.class);
    job.setMapOutputValueClass(Text.class);
    job.setPartitionerClass(ReducesidejoinPartitioner.class);
    job.setGroupingComparatorClass(ReduceSideJoinGroupingComparator.class);

    job.setReducerClass(ReduceSideJoinReduce.class);
    job.setOutputKeyClass(IntWritable.class);
    job.setOutputValueClass(Text.class);

    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, new Path(args[2]));

    return job.waitForCompletion(true)?0:1; 
}
TestRun.java 文件源码 项目:hadoop-fieldformat 阅读 42 收藏 0 点赞 0 评论 0
@Override
public int run(String[] args) throws Exception {
  Configuration conf = getConf();
  //conf.set("mapreduce.fieldoutput.header", "ct_audit,ct_action");
  Job job = new Job(conf);
  job.setJobName("test fieldInput");
  job.setJarByClass(TestRun.class);
  MultipleInputs.addInputPath(job, new Path(args[0]), FieldInputFormat.class, CTMapper.class);
  job.setNumReduceTasks(0);
  //FileOutputFormat.setOutputPath(job, new Path(args[1]));
  FieldOutputFormat.setOutputPath(job, new Path(args[1]));
  job.setOutputFormatClass(FieldOutputFormat.class);
  job.submit();
  job.waitForCompletion(true);
  return 0;
}
PostCommentHierarchy.java 文件源码 项目:hadoop-map-reduce-patterns 阅读 43 收藏 0 点赞 0 评论 0
@Override
public int run(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = new Job(conf, "PostCommentHeirarchy");
    job.setJarByClass(PostCommentHierarchy.class);

    MultipleInputs.addInputPath(job, new Path(args[0]),
            TextInputFormat.class, PostMapper.class);
    MultipleInputs.addInputPath(job, new Path(args[1]),
            TextInputFormat.class, CommentMapper.class);

    job.setReducerClass(PostCommentHierarchyReducer.class);

    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, new Path(args[2]));

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);

    return job.waitForCompletion(true) ? 0 : 2;
}
InsDriver.java 文件源码 项目:InsAdjustment 阅读 32 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    Job job = new Job(conf);
    job.setJarByClass(InsDriver.class);
    // job.setMapperClass(PFMapper.class);
    job.setReducerClass(InsReducer.class);
    // job.setNumReduceTasks(0);
    job.setJobName("Participant Adjustment PoC");

    String busDate = args[3].toString();
    job.getConfiguration().set("BUS_DATE", busDate);

    // map-reduce job.
    Path inputPath1 = new Path(args[0]);
    Path inputPath2 = new Path(args[1]);
    Path outputPath = new Path(args[2]);

    MultipleInputs.addInputPath(job, inputPath1, TextInputFormat.class, PFMapper.class);
    MultipleInputs.addInputPath(job, inputPath2, TextInputFormat.class, BRMapper.class);
    FileOutputFormat.setOutputPath(job, outputPath);
    // TODO: Update the output path for the output directory of the
    // map-reduce job.
    // configuration should contain reference to your namenode

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);

    // Submit the job and wait for it to finish.
    job.waitForCompletion(true);
}
Question3.java 文件源码 项目:Bigdata 阅读 37 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
    if (otherArgs.length != 3) {
        System.err.println("Usage: Question3 <in> <out>");
        System.exit(3);
    }

    @SuppressWarnings("deprecation")
    Job job1 = new Job(conf, "averageRating");
    @SuppressWarnings("deprecation")
    Job job2 = new Job(conf,"reduceSideJoin");
    job1.setJarByClass(Question3.class); 
    job1.setMapperClass(TopTenMap.class);
    job1.setReducerClass(TopTenReduce.class);

    job1.setOutputKeyClass(Text.class);
    job1.setOutputValueClass(FloatWritable.class);

    FileInputFormat.addInputPath(job1, new Path(otherArgs[0]));    
    FileOutputFormat.setOutputPath(job1, new Path("/bxr140530/Asgn/temp"));

    if(job1.waitForCompletion(true))
    {
        job2.setOutputKeyClass(Text.class);
        job2.setOutputValueClass(Text.class);
        job2.setJarByClass(Question3.class);
        job2.setMapperClass(TopTenJoinMap.class);
        job2.setReducerClass(TopTenJoinReduce.class);

        MultipleInputs.addInputPath(job2,new Path("/bxr140530/Asgn/temp"),TextInputFormat.class,TopTenJoinMap.class);
        MultipleInputs.addInputPath(job2,new Path(otherArgs[1]),TextInputFormat.class,BusinessMap.class);
        FileOutputFormat.setOutputPath(job2, new Path(otherArgs[2]));

        job2.waitForCompletion(true);


    }
}
JoinSelectStatsUtil.java 文件源码 项目:incubator-rya 阅读 30 收藏 0 点赞 0 评论 0
public static void initJoinMRJob(Job job, String prospectsPath, String spoPath, Class<? extends Mapper<CompositeType,TripleCard,?,?>> mapperClass,
    String outPath, String auths) throws AccumuloSecurityException {

  MultipleInputs.addInputPath(job, new Path(prospectsPath), SequenceFileInputFormat.class, mapperClass);
  MultipleInputs.addInputPath(job, new Path(spoPath), SequenceFileInputFormat.class, mapperClass);
  job.setMapOutputKeyClass(CompositeType.class);
  job.setMapOutputValueClass(TripleCard.class);

  SequenceFileOutputFormat.setOutputPath(job, new Path(outPath));
  job.setOutputFormatClass(SequenceFileOutputFormat.class);
  job.setOutputKeyClass(TripleEntry.class);
  job.setOutputValueClass(CardList.class);

}
JoinSelectStatisticsTest.java 文件源码 项目:incubator-rya 阅读 38 收藏 0 点赞 0 评论 0
@Override
public int run(String[] args) throws Exception {

    Configuration conf = getConf();
    String outpath = conf.get(OUTPUTPATH);

    Job job = new Job(conf, this.getClass().getSimpleName() + "_" + System.currentTimeMillis());
    job.setJarByClass(this.getClass());
    conf.setBoolean(MRJobConfig.MAPREDUCE_JOB_USER_CLASSPATH_FIRST, true);

    MultipleInputs.addInputPath(job, new Path(PROSPECTSOUT.getAbsolutePath()), 
            SequenceFileInputFormat.class, JoinSelectAggregateMapper.class);
    MultipleInputs.addInputPath(job,new Path(SPOOUT.getAbsolutePath()) , 
            SequenceFileInputFormat.class, JoinSelectAggregateMapper.class);
    job.setMapOutputKeyClass(CompositeType.class);
    job.setMapOutputValueClass(TripleCard.class);

    tempDir = new File(File.createTempFile(outpath, "txt").getParentFile(), System.currentTimeMillis() + "");
    SequenceFileOutputFormat.setOutputPath(job, new Path(tempDir.getAbsolutePath()));
    job.setOutputFormatClass(SequenceFileOutputFormat.class);
    job.setOutputKeyClass(TripleEntry.class);
    job.setOutputValueClass(CardList.class);


    job.setSortComparatorClass(JoinSelectSortComparator.class);
    job.setGroupingComparatorClass(JoinSelectGroupComparator.class);
    job.setPartitionerClass(JoinSelectPartitioner.class);
    job.setReducerClass(JoinReducer.class);
    job.setNumReduceTasks(32);
    job.waitForCompletion(true);

    return job.isSuccessful() ? 0 : 1;          
}
AbstractReasoningTool.java 文件源码 项目:incubator-rya 阅读 46 收藏 0 点赞 0 评论 0
/**
 * Set up the MapReduce job to use Accumulo as an input.
 * @param tableMapper Mapper class to use
 */
protected void configureAccumuloInput(Class<? extends Mapper<Key,Value,?,?>> tableMapper)
        throws AccumuloSecurityException {
    MRReasoningUtils.configureAccumuloInput(job);
    MultipleInputs.addInputPath(job, new Path("/tmp/input"),
        AccumuloInputFormat.class, tableMapper);
}
AbstractReasoningTool.java 文件源码 项目:incubator-rya 阅读 39 收藏 0 点赞 0 评论 0
/**
 * Set up the MapReduce job to use an RDF file as an input.
 * @param rdfMapper class to use
 */
protected void configureRdfInput(Path inputPath,
        Class<? extends Mapper<LongWritable, RyaStatementWritable, ?, ?>> rdfMapper) {
    Configuration conf = job.getConfiguration();
    String format = conf.get(MRUtils.FORMAT_PROP, RDFFormat.RDFXML.getName());
    conf.set(MRUtils.FORMAT_PROP, format);
    MultipleInputs.addInputPath(job, inputPath,
        RdfFileInputFormat.class, rdfMapper);
}
StreamingRepartitionJoin.java 文件源码 项目:hiped2 阅读 24 收藏 0 点赞 0 评论 0
/**
 * The MapReduce driver - setup and launch the job.
 *
 * @param args the command-line arguments
 * @return the process exit code
 * @throws Exception if something goes wrong
 */
public int run(final String[] args) throws Exception {

  Cli cli = Cli.builder().setArgs(args).addOptions(Options.values()).build();
  int result = cli.runCmd();

  if (result != 0) {
    return result;
  }

  Path usersPath = new Path(cli.getArgValueAsString(Options.USERS));
  Path userLogsPath = new Path(cli.getArgValueAsString(Options.USER_LOGS));
  Path outputPath = new Path(cli.getArgValueAsString(Options.OUTPUT));

  Configuration conf = super.getConf();

  Job job = new Job(conf);
  job.setJarByClass(StreamingRepartitionJoin.class);

  MultipleInputs.addInputPath(job, usersPath, TextInputFormat.class, UserMap.class);
  MultipleInputs.addInputPath(job, userLogsPath, TextInputFormat.class, UserLogMap.class);

  ShuffleUtils.configBuilder()
      .useNewApi()
      .setSortIndices(KeyFields.USER, KeyFields.DATASET)
      .setPartitionerIndices(KeyFields.USER)
      .setGroupIndices(KeyFields.USER)
      .configure(job.getConfiguration());

  job.setReducerClass(Reduce.class);

  job.setMapOutputKeyClass(Tuple.class);
  job.setMapOutputValueClass(Tuple.class);

  FileOutputFormat.setOutputPath(job, outputPath);

  return job.waitForCompletion(true) ? 0 : 1;
}
BloomJoin.java 文件源码 项目:hiped2 阅读 42 收藏 0 点赞 0 评论 0
/**
 * The MapReduce driver - setup and launch the job.
 *
 * @param args the command-line arguments
 * @return the process exit code
 * @throws Exception if something goes wrong
 */
public int run(final String[] args) throws Exception {

  Cli cli = Cli.builder().setArgs(args).addOptions(Options.values()).build();
  int result = cli.runCmd();

  if (result != 0) {
    return result;
  }

  Path usersPath = new Path(cli.getArgValueAsString(Options.USERS));
  Path userLogsPath = new Path(cli.getArgValueAsString(Options.USER_LOGS));
  Path bloomPath = new Path(cli.getArgValueAsString(Options.BLOOM_FILE));
  Path outputPath = new Path(cli.getArgValueAsString(Options.OUTPUT));

  Configuration conf = super.getConf();

  Job job = new Job(conf);

  job.setJarByClass(BloomJoin.class);
  MultipleInputs.addInputPath(job, usersPath, TextInputFormat.class, UserMap.class);
  MultipleInputs.addInputPath(job, userLogsPath, TextInputFormat.class, UserLogMap.class);

  job.setMapOutputKeyClass(Text.class);
  job.setMapOutputValueClass(Tuple.class);

  job.setReducerClass(Reduce.class);

  job.addCacheFile(bloomPath.toUri());
  job.getConfiguration().set(AbstractFilterMap.DISTCACHE_FILENAME_CONFIG, bloomPath.getName());

  FileInputFormat.setInputPaths(job, userLogsPath);
  FileOutputFormat.setOutputPath(job, outputPath);

  return job.waitForCompletion(true) ? 0 : 1;
}
MapOperation.java 文件源码 项目:incubator-mrql 阅读 33 收藏 0 点赞 0 评论 0
/** The cMap physical operator
 * @param map_fnc       mapper function
 * @param acc_fnc       optional accumulator function
 * @param zero          optional the zero value for the accumulator
 * @param source        input data source
 * @param stop_counter  optional counter used in repeat operation
 * @return a new data source that contains the result
 */
public final static DataSet cMap ( Tree map_fnc,         // mapper function
                                   Tree acc_fnc,         // optional accumulator function
                                   Tree zero,            // optional the zero value for the accumulator
                                   DataSet source,       // input data source
                                   String stop_counter ) // optional counter used in repeat operation
                            throws Exception {
    conf = MapReduceEvaluator.clear_configuration(conf);
    String newpath = new_path(conf);
    conf.set("mrql.mapper",map_fnc.toString());
    conf.set("mrql.counter",stop_counter);
    if (zero != null) {
        conf.set("mrql.accumulator",acc_fnc.toString());
        conf.set("mrql.zero",zero.toString());
    } else conf.set("mrql.zero","");
    setupSplits(source,conf);
    Job job = new Job(conf,newpath);
    distribute_compiled_arguments(job.getConfiguration());
    job.setJarByClass(MapReducePlan.class);
    job.setOutputKeyClass(MRContainer.class);
    job.setOutputValueClass(MRContainer.class);
    job.setOutputFormatClass(SequenceFileOutputFormat.class);
    for (DataSource p: source.source)
        MultipleInputs.addInputPath(job,new Path(p.path),(Class<? extends MapReduceMRQLFileInputFormat>)p.inputFormat,cMapMapper.class);
    FileOutputFormat.setOutputPath(job,new Path(newpath));
    job.setNumReduceTasks(0);
    job.waitForCompletion(true);
    long c = (stop_counter.equals("-")) ? 0
             : job.getCounters().findCounter("mrql",stop_counter).getValue();
    return new DataSet(new BinaryDataSource(newpath,conf),c,outputRecords(job));
}
JoinRecordWithStationName.java 文件源码 项目:hadoop-in-action 阅读 31 收藏 0 点赞 0 评论 0
@Override
public int run(String[] args) throws Exception {
    if (args.length != 3) {
        JobBuilder
                .printUsage(this, "<ncdc input> <station input> <output>");
        return -1;
    }

    Job job = Job.getInstance(getConf(), "Join weather records with station names");
    job.setJarByClass(getClass());

    Path ncdcInputPath = new Path(args[0]);
    Path stationInputPath = new Path(args[1]);
    Path outputPath = new Path(args[2]);

    MultipleInputs.addInputPath(job, ncdcInputPath, TextInputFormat.class,
            JoinRecordMapper.class);
    MultipleInputs.addInputPath(job, stationInputPath,
            TextInputFormat.class, JoinStationMapper.class);
    FileOutputFormat.setOutputPath(job, outputPath);

    job.setPartitionerClass(KeyPartitioner.class);
    job.setGroupingComparatorClass(TextPair.FirstComparator.class);

    job.setMapOutputKeyClass(TextPair.class);

    job.setReducerClass(JoinReducer.class);

    job.setOutputKeyClass(Text.class);

    return job.waitForCompletion(true) ? 0 : 1;
}
PathInputConfig.java 文件源码 项目:shaf 阅读 34 收藏 0 点赞 0 评论 0
/**
 * Configures the job input for the file-system data source.
 */
@Override
public void configure(
        final Class<? extends DistributedProcess<?, ?, ?, ?, ?, ?>> pcls,
        ProcessConfiguration config, Job job) throws JobConfigException {
    try {
        int index = 0;

        InputTokenizer it = config.getInputTokenizer();
        while (it.nextToken()) {
            LOG.debug("Configuring input number: " + (index++));

            Path path = new Path(config.getBase(), it.getPath());
            if (it.isMapperClassNameDefined()) {
                @SuppressWarnings("unchecked")
                Class<? extends MapProcess<?, ?, ?, ?>> mcls = (Class<? extends MapProcess<?, ?, ?, ?>>) DynamicClassLoader
                        .getClassByName(it.getMapperClassName());
                JobInput anno = mcls.getAnnotation(JobInput.class);

                MultipleInputs.addInputPath(job, path, anno.formatClass(),
                        HadoopMapProcessWrapper.class);
                HadoopMapProcessWrapper.addWrappingProcessClass(job, path,
                        mcls);
                LOG.debug("Adds input format: "
                        + anno.formatClass());
                LOG.debug("Adds mapper: " + mcls);

            }

            FileInputFormat.addInputPath(job, path);
            LOG.debug("Adds input path:   " + path);
        }
    } catch (PropertyNotFoundException | ClassNotFoundException
            | IOException exc) {
        throw new JobConfigException("Failed to configure job input.", exc);
    }
}
IndexerJobDriver.java 文件源码 项目:incubator-blur 阅读 37 收藏 0 点赞 0 评论 0
private boolean runMrWithLookup(String uuid, TableDescriptor descriptor, List<Path> inprogressPathList, String table,
    Path fileCache, Path outputPath, int reducerMultipler, Path tmpPath, TableStats tableStats, String snapshot)
    throws ClassNotFoundException, IOException, InterruptedException {
  PartitionedInputResult result = buildPartitionedInputData(uuid, tmpPath, descriptor, inprogressPathList, snapshot,
      fileCache);

  Job job = Job.getInstance(getConf(), "Blur Row Updater for table [" + table + "]");

  ExistingDataIndexLookupMapper.setSnapshot(job, MRUPDATE_SNAPSHOT);
  FileInputFormat.addInputPath(job, result._partitionedInputData);
  MultipleInputs.addInputPath(job, result._partitionedInputData, SequenceFileInputFormat.class,
      ExistingDataIndexLookupMapper.class);

  for (Path p : inprogressPathList) {
    FileInputFormat.addInputPath(job, p);
    MultipleInputs.addInputPath(job, p, SequenceFileInputFormat.class, NewDataMapper.class);
  }

  BlurOutputFormat.setOutputPath(job, outputPath);
  BlurOutputFormat.setupJob(job, descriptor);

  job.setReducerClass(UpdateReducer.class);
  job.setMapOutputKeyClass(IndexKey.class);
  job.setMapOutputValueClass(IndexValue.class);
  job.setPartitionerClass(IndexKeyPartitioner.class);
  job.setGroupingComparatorClass(IndexKeyWritableComparator.class);

  BlurOutputFormat.setReducerMultiplier(job, reducerMultipler);

  boolean success = job.waitForCompletion(true);
  Counters counters = job.getCounters();
  LOG.info("Counters [" + counters + "]");
  return success;
}
IndexerJobDriver.java 文件源码 项目:incubator-blur 阅读 40 收藏 0 点赞 0 评论 0
private boolean runMrOnly(TableDescriptor descriptor, List<Path> inprogressPathList, String table, Path fileCache,
    Path outputPath, int reducerMultipler) throws IOException, ClassNotFoundException, InterruptedException {
  Job job = Job.getInstance(getConf(), "Blur Row Updater for table [" + table + "]");
  Path tablePath = new Path(descriptor.getTableUri());
  BlurInputFormat.setLocalCachePath(job, fileCache);
  BlurInputFormat.addTable(job, descriptor, MRUPDATE_SNAPSHOT);
  MultipleInputs.addInputPath(job, tablePath, BlurInputFormat.class, ExistingDataMapper.class);

  for (Path p : inprogressPathList) {
    FileInputFormat.addInputPath(job, p);
    MultipleInputs.addInputPath(job, p, SequenceFileInputFormat.class, NewDataMapper.class);
  }

  BlurOutputFormat.setOutputPath(job, outputPath);
  BlurOutputFormat.setupJob(job, descriptor);

  job.setReducerClass(UpdateReducer.class);
  job.setMapOutputKeyClass(IndexKey.class);
  job.setMapOutputValueClass(IndexValue.class);
  job.setPartitionerClass(IndexKeyPartitioner.class);
  job.setGroupingComparatorClass(IndexKeyWritableComparator.class);

  BlurOutputFormat.setReducerMultiplier(job, reducerMultipler);

  boolean success = job.waitForCompletion(true);
  Counters counters = job.getCounters();
  LOG.info("Counters [" + counters + "]");
  return success;
}
PostCommentHierarchy.java 文件源码 项目:MapReduceSamplesJava 阅读 46 收藏 0 点赞 0 评论 0
public static void main(String[] args) throws Exception {
    Configuration conf = new Configuration();
    String[] otherArgs = new GenericOptionsParser(conf, args)
            .getRemainingArgs();
    if (otherArgs.length != 3) {
        System.err.println("Usage: PostCommentHierarchy <posts> <comments> <outdir>");
        System.exit(1);
    }

    Job job = new Job(conf, "PostCommentHierarchy");
    job.setJarByClass(PostCommentHierarchy.class);

    MultipleInputs.addInputPath(job, new Path(otherArgs[0]),
            TextInputFormat.class, PostMapper.class);

    MultipleInputs.addInputPath(job, new Path(otherArgs[1]),
            TextInputFormat.class, CommentMapper.class);

    job.setReducerClass(PostCommentHierarchyReducer.class);

    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, new Path(otherArgs[2]));

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);

    System.exit(job.waitForCompletion(true) ? 0 : 2);
}
ReplicatedUserJoin.java 文件源码 项目:hadoop-map-reduce-patterns 阅读 34 收藏 0 点赞 0 评论 0
@Override
public int run(String[] args) throws Exception {
    Configuration conf = new Configuration();
    GenericOptionsParser parser = new GenericOptionsParser(conf, args);
    String[] otherArgs = parser.getRemainingArgs();
    if (otherArgs.length != 4) {
        printUsage();
    }
    Job job = new Job(conf, "ReduceSideJoin");
    job.setJarByClass(ReplicatedUserJoin.class);

    // Use MultipleInputs to set which input uses what mapper
    // This will keep parsing of each data set separate from a logical
    // standpoint
    // The first two elements of the args array are the two inputs
    MultipleInputs.addInputPath(job, new Path(args[0]),
            TextInputFormat.class, UserJoinMapper.class);
    MultipleInputs.addInputPath(job, new Path(args[1]),
            TextInputFormat.class, CommentJoinMapper.class);
    job.getConfiguration().set("join.type", args[2]);

    job.setReducerClass(UserJoinReducer.class);

    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, new Path(args[3]));

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);

    return job.waitForCompletion(true) ? 0 : 2;
}
ReduceSideJoinBloomFilter.java 文件源码 项目:hadoop-map-reduce-patterns 阅读 39 收藏 0 点赞 0 评论 0
@Override
public int run(String[] args) throws Exception {
    Configuration conf = new Configuration();
    GenericOptionsParser parser = new GenericOptionsParser(conf, args);
    String[] otherArgs = parser.getRemainingArgs();
    if (otherArgs.length != 4) {
        printUsage();
    }
    Job job = new Job(conf, "ReduceSideJoinBloomFilter");
    job.setJarByClass(ReduceSideJoinBloomFilter.class);

    // Use MultipleInputs to set which input uses what mapper
    // This will keep parsing of each data set separate from a logical
    // standpoint
    // The first two elements of the args array are the two inputs
    MultipleInputs.addInputPath(job, new Path(args[0]),
            TextInputFormat.class, UserJoinMapper.class);
    MultipleInputs.addInputPath(job, new Path(args[1]),
            TextInputFormat.class, CommentJoinMapperWithBloom.class);
    job.getConfiguration().set("join.type", args[2]);

    job.setReducerClass(UserJoinReducer.class);

    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, new Path(args[3]));

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);

    return job.waitForCompletion(true) ? 0 : 2;
}
ReduceSideJoin.java 文件源码 项目:hadoop-map-reduce-patterns 阅读 35 收藏 0 点赞 0 评论 0
@Override
public int run(String[] args) throws Exception {
    Configuration conf = new Configuration();
    GenericOptionsParser parser = new GenericOptionsParser(conf, args);
    String[] otherArgs = parser.getRemainingArgs();
    if (otherArgs.length != 4) {
        printUsage();
    }
    Job job = new Job(conf, "ReduceSideJoin");
    job.setJarByClass(ReduceSideJoin.class);

    // Use MultipleInputs to set which input uses what mapper
    // This will keep parsing of each data set separate from a logical
    // standpoint
    // The first two elements of the args array are the two inputs
    MultipleInputs.addInputPath(job, new Path(args[0]),
            TextInputFormat.class, UserJoinMapper.class);
    MultipleInputs.addInputPath(job, new Path(args[1]),
            TextInputFormat.class, CommentJoinMapper.class);
    job.getConfiguration().set("join.type", args[2]);

    job.setReducerClass(UserJoinReducer.class);

    job.setOutputFormatClass(TextOutputFormat.class);
    TextOutputFormat.setOutputPath(job, new Path(args[3]));

    job.setOutputKeyClass(Text.class);
    job.setOutputValueClass(Text.class);

    return job.waitForCompletion(true) ? 0 : 2;
}
FScore.java 文件源码 项目:npc-recommender-imdb 阅读 32 收藏 0 点赞 0 评论 0
public static int run(String[] args, final int REDUCERS, final int T) 
            throws IOException, ClassNotFoundException, InterruptedException{
        //set config
        Configuration c = new Configuration();
        c.set("CPATH", args[2]+"/recommander");
        c.setInt("T", T);

        Job job = new Job(c, "FScore");
        //metrics
        job.setNumReduceTasks(REDUCERS);
        //Classes
        job.setJarByClass(FScore.class);
//      job.setMapperClass(FMapper.class);
        job.setReducerClass(FReducer.class);
        //mapOutput,reduceOutput
//      job.setInputFormatClass(TextInputFormat.class);
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(Text.class);
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(Text.class);  
        //IO
//      FileInputFormat.addInputPaths(job, args[1]+"/ratings");
        MultipleInputs.addInputPath(job, new Path(args[1]+"/ratings"), 
                TextInputFormat.class, FMapperRatings.class);
        MultipleInputs.addInputPath(job, new Path(args[2]+"/recommander"), 
                TextInputFormat.class, FMapperResults.class);
        FileOutputFormat.setOutputPath(job, new Path(args[2]+"/fscore"));

        return (job.waitForCompletion(true) ? 0 : -1);
    }
Union.java 文件源码 项目:hadoop-relational 阅读 38 收藏 0 点赞 0 评论 0
@Override
public int run(String[] args) throws Exception {
  System.out.println(Arrays.asList(args).toString());
  // Parse arguments
  Path oneRelationPath = new Path(args[0]),
      twoRelationPath = new Path(args[1]),
      outputRelationPath = new Path(args[2]);

  // Setup job
  Job job = Job.getInstance(conf);
  job.setJarByClass(Union.class);

  MultipleInputs.addInputPath(job, oneRelationPath, TextInputFormat.class, UnionMapper.class);
  MultipleInputs.addInputPath(job, twoRelationPath, TextInputFormat.class, UnionMapper.class);

  job.setMapOutputKeyClass(NullWritable.class);
  job.setMapOutputValueClass(Text.class);

  // This is a map-only job
  job.setNumReduceTasks(0);

  job.setOutputKeyClass(NullWritable.class);
  job.setOutputValueClass(Text.class);
  job.setOutputFormatClass(TextOutputFormat.class);
  TextOutputFormat.setOutputPath(job, outputRelationPath);

  // Run job
  job.submit();
  return job.waitForCompletion(true) ? 0 : 1;
}


问题


面经


文章

微信
公众号

扫码关注公众号