标签: mapreduce

我试图将所有数字加在一个文件中,该文件包含由空格分隔的数字,并使用MapReduce包含在多行中

我的输出出错了.输入文件是:

1 2 3 4
5 4 3 2

输出应该是关键:总和值:24

MapReduce产生的输出:key:总和值:34

我在Ubuntu 14.04中使用OpenJDK 7来运行jar文件,而jar文件是在Eclipse Juna中创建的,使用的java版本是Oracle JDK 7来编译它.NumberDriver.java

包装数量;

import java.io.*;
//import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
//import org.apache.hadoop.mapreduce.Mapper;
//import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;
public class NumberDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        // TODO Auto-generated method stub
            Configuration conf=new Configuration();
            String[] otherArgs=new GenericOptionsParser(conf,args).getRemainingArgs();
            if(otherArgs.length!=2)
            {
                System.err.println("Error");
                System.exit(2);
            }
            Job job=new Job(conf, "number sum");
            job.setJarByClass(NumberDriver.class);
            job.setMapperClass(NumberMapper.class);
            job.setReducerClass(NumberReducer.class); …
Run Code Online (Sandbox Code Playgroud)

hadoop mapreduce

1
推荐指数
1
解决办法
2503
查看次数

hadoop中的自定义可写类,用于多个double值

我试图发出4个数值作为键.我为同一个写了自定义可写Comparable类,但我遇到了compare()方法,stackoverflow站点中提到了几个解决方案.但这并没有解决我的问题.

我的writableCoparable类是

public class DimensionWritable implements WritableComparable {
    private double keyRow;
    private double keyCol;

    private double valRow;
    private double valCol;


    public  DimensionWritable(double keyRow, double keyCol,double valRow, double valCol) {
        set(keyRow, keyCol,valRow,valCol);
    }
    public void set(double keyRow, double keyCol,double valRow, double valCol) {
        //row dimension
        this.keyRow = keyRow;
        this.keyCol = keyCol;
        //column dimension
        this.valRow = valRow;
        this.valCol = valCol;
    }

    @Override
    public void write(DataOutput out) throws IOException {
        out.writeDouble(keyRow);
        out.writeDouble(keyCol);

        out.writeDouble(valRow);
        out.writeDouble(valCol);
    }
    @Override
    public void readFields(DataInput in) throws IOException { …
Run Code Online (Sandbox Code Playgroud)

java hadoop mapreduce class

1
推荐指数
1
解决办法
694
查看次数

mapreduce类中的奇怪错误

这个错误似乎微不足道,但它不会消失.我定义了以下类:

import java.io.IOException;
import java.util.Iterator;
import java.util.StringTokenizer;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapred.TextInputFormat;
import org.apache.hadoop.mapred.TextOutputFormat;
import org.apache.hadoop.mapreduce.Mapper;

public class Anagram_Mapper extends Mapper<LongWritable, Text, Text, Text> {
Run Code Online (Sandbox Code Playgroud)

在'main'函数中我试图使用JobConf来启动一个简单的mapreduce:

public static void main(String args[]){
     JobConf conf = new JobConf(Anagram_Mapper.class);
       conf.setJobName("anagram_mapper");

       conf.setOutputKeyClass(Text.class);
       conf.setOutputValueClass(IntWritable.class);

       conf.setMapperClass(Anagram_Mapper.class);
       conf.setCombinerClass(Reduce.class);
       conf.setReducerClass(Reduce.class);

       conf.setInputFormat(TextInputFormat.class);
       conf.setOutputFormat(TextOutputFormat.class);

       FileInputFormat.setInputPaths(conf, new Path(args[0]));
       FileOutputFormat.setOutputPath(conf, new Path(args[1]));

       try {
        JobClient.runJob(conf);
    } catch (IOException e) {
        // …
Run Code Online (Sandbox Code Playgroud)

java hadoop mapreduce

1
推荐指数
1
解决办法
4932
查看次数

Hadoop Mapreduce:自定义输入格式

我有一个文件,其中包含文本和"^"之间的数据:

一些文字^在这里走了^
并且很少^在
这里

我正在编写一个自定义输入格式来使用"^"字符分隔行.即映射器的输出应该是:

有些文字在
这里
,还有
更多的东西在这里

我编写了一个自定义输入格式,它扩展了FileInputFormat,还编写了一个扩展RecordReader的自定义记录阅读器.我的自定义记录阅读器的代码如下.我不知道如何继续这个代码.在WHILE循环部分中遇到了nextKeyValue()方法的问题.我应该如何从拆分中读取数据并生成自定义键值?我正在使用所有新的mapreduce包而不是旧的mapred包.

public class MyRecordReader extends RecordReader<LongWritable, Text>
    {
        long start, current, end;
        Text value;
        LongWritable key;
        LineReader reader;
        FileSplit split;
        Path path;
        FileSystem fs;
        FSDataInputStream in;
        Configuration conf;

        @Override
        public void initialize(InputSplit inputSplit, TaskAttemptContext cont) throws IOException, InterruptedException
        {
            conf = cont.getConfiguration();
            split = (FileSplit)inputSplit;
            path = split.getPath();
            fs = path.getFileSystem(conf);
            in = fs.open(path);
            reader = new LineReader(in, conf);
            start = split.getStart();
            current = start;
            end = split.getLength() + start;
        } …
Run Code Online (Sandbox Code Playgroud)

hadoop mapreduce

1
推荐指数
1
解决办法
4182
查看次数

Couch DB - 将输入参数传递给视图

我正在从我的Web应用程序中将SQL从Cou​​ch DB转移到我的第一个应用程序.

虽然我不能说为什么我不喜欢SQL查询,但不确定我不喜欢,让CURL请求访问我的数据库声音的想法必须比使用PHP PDO更好.

我花了一天半的时间试图熟悉沙发DB HTTP API.我无法声称我已经彻底阅读了API,但是在开始编码之前谁彻底阅读了API.所以我的,可能是愚蠢的问题是 - how do I pass an variable other than doc to a map function while making a http request to the view.API清楚地说地图函数只接受一个"doc"参数,在这种情况下,下面的函数本身是错误的,但我找不到API中允许的任何部分我使用最终用户提供的输入查询数据库.

我的地图功能是

function(doc, pid2){

      if (doc.pid === pid2)
    {
        emit(doc._id, doc) ;

    }
}
Run Code Online (Sandbox Code Playgroud)

pid2是由前端用户提供的号码.

    <?php
    $pid2 = file_get_contents(facebook graphi api call_returns a Profile ID) ;
    $user_exists = HTTP request to couch DB view to return 
in JSON format the list of JSON documents with pid = $pid2
?>
Run Code Online (Sandbox Code Playgroud)

couchdb mapreduce

1
推荐指数
1
解决办法
1109
查看次数

Sqoop用--schema参数导出到postgres

使用Sqoop将数据导出到postgresql时有没有办法提到不同的模式?基于URL http://sqoop.apache.org/docs/1.4.4/SqoopUserGuide.html,我需要使用"--schema"这很奇怪,它不起作用.我也尝试使用"--schema",但结果仍然相同."--schema"与list-tables命令一起使用,但不与"export"命令一起使用.任何帮助将受到高度赞赏.

postgresql hadoop export mapreduce sqoop

1
推荐指数
1
解决办法
5853
查看次数

hadoop中KeyValueTextInputFormat和TextInputFormat之间的主要区别是什么?

有人可以给我一个实际情况,我们必须使用KeyValueTextInputFormatTextInputFormat??

hadoop mapreduce

1
推荐指数
1
解决办法
2733
查看次数

在Oozie中将参数从一个动作传递到另一个动作

我有一个以下shell脚本:

DATE= date +"%d%b%y" -d "-1 days"
Run Code Online (Sandbox Code Playgroud)

我如何传递DATE给Java动作?

java shell hadoop mapreduce oozie

1
推荐指数
1
解决办法
6029
查看次数

在Hadoop分布式缓存中创建和放置文件

我正在尝试动态创建资源并将其放置在Hadoop分布式缓存中,然后再运行我的工作-aka这将是一项自动化的工作,需要在映射器执行之前(通过HTTP)将几件事收集在一起。

我面临的问题是,由于我正在运行的映射器数量众多,我无法将其置于设置阶段-这将导致被调用服务器的负载过高。我希望能够检索我的资源,将它们写入文件,然后将其放在“分布式缓存”中,以便以后访问。

大节点:我希望将文件写入Hadoop的,我宁愿它本地的节点上。

    // The whitelist cache file
    File resourceFile = new File("resources.json");

    // Create an output stream
    FileOutputStream outputStream = new FileOutputStream(resourceFile.getAbsoluteFile());

    // Write the whitelist to the local file
    // (this is using Jackson JSON, FYI)
    mapper.writeValue(outputStream, myResources);

    // Add the file to the job
    job.addCacheFile(new URI("file://" + resourceFile.getAbsolutePath()));
Run Code Online (Sandbox Code Playgroud)

这在run()我的工作方法中运行,即在映射器开始之前-但是每当我尝试new File("resources.json")在映射器中进行访问时,它都会给我FileNotFoundException 。

创建这些临时文件的正确方法是什么,以及在作业中访问它们的最佳方法是什么?

java caching hadoop mapreduce

1
推荐指数
1
解决办法
1991
查看次数

mapreduce hadoop中输入分割数与映射器数之间的关系

我是hadoop的新手和地图缩小模型并试图让这些概念正确.

我首先想要得到输入拆分的概念和映射器的数量是正确的.

我正在运行mapreduce wordcount程序,以下是我的问题.

1)如何确定输入分割?我在同一个集群上运行相同的程序,有两个不同大小的输入

file 1 : size 48mb. => i got number of splits:1 in log.
file 2: size 126mb => number of splits : 1 
file 2 : size 126mb ( executed in eclipse IDE) => number of splits: 4
Run Code Online (Sandbox Code Playgroud)

不应该是126 MB文件的分割数等于2?因为我已经读过块大小为64 MB.所以它必须创建2个分裂.

2)如何确定地图制作者的数量?我试图通过以下方式获得映射器的数量来理解mapreduce的工作流程.

conf.get("mapred.map.tasks")
Run Code Online (Sandbox Code Playgroud)

它每次返回2.

3)分割数和映射器数之间是否有任何关系?

4)做上面的事情取决于集群?对于伪分布式模式和其他集群是否相同或不同?

谢谢.

hadoop mapreduce

1
推荐指数
1
解决办法
5256
查看次数

标签 统计

mapreduce ×10

hadoop ×9

java ×4

caching ×1

class ×1

couchdb ×1

export ×1

oozie ×1

postgresql ×1

shell ×1

sqoop ×1