java - Hadoop:不支持的名称:具有方案但相对路径部分错误

标签 java hadoop java-8 yarn hadoop2

我正在尝试在Java中运行一个简单的 mapreduce ,但出现此错误:

Unsupported name: has scheme but relative path-part



如何更正自己的代码或我的 Hadoop 使其正常运行?

让我知道是否需要提供更多信息。

我将文件复制到/ in文件夹中,如下所示:
hadoop fs -copyFromLocal c:\hwork\recipeitems-latest.json /in

我已经更改了 / in 文件夹的权限:
hadoop fs -chmod -R 777 /in

我基本上是在提示符下执行此命令(是的,我现在正在使用Windows):
hadoop jar c:\hwork\Recipe.jar Recipe /in /out

JAVA代码:
import java.io.IOException;

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;

import com.google.gson.Gson;
public class Recipe {

    public static class TokenizerMapper
            extends Mapper<Object, Text, Text, IntWritable>{

        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();
        Gson gson = new Gson();
        public void map(Object key, Text value, Context context
        ) throws IOException, InterruptedException {
           /* StringTokenizer itr = new StringTokenizer(value.toString());
            while (itr.hasMoreTokens()) {
                word.set(itr.nextToken());
                context.write(word, one);
            } */


            Roo roo=gson.fromJson(value.toString(),Roo.class);
            if(roo.cookTime!=null)
            {
            word.set(roo.cookTime);
            }
            else
            {
                word.set("none");
            }
            context.write(word, one);
        }
    }

    public static class IntSumReducer
            extends Reducer<Text,IntWritable,Text,IntWritable> {
        private IntWritable result = new IntWritable();

        public void reduce(Text key, Iterable<IntWritable> values,
                           Context context
        ) throws IOException, InterruptedException {
            int sum = 0;
            for (IntWritable val : values) {
                sum += val.get();
            }
            result.set(sum);
            context.write(key, result);
        }
    }

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
       String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
       /* for ( String string : otherArgs) {
            System.out.println(string);
        }*/
        if (otherArgs.length != 2) {
            System.err.println("Usage: recipe <in> <out>");
            System.exit(2);
        }
        @SuppressWarnings("deprecation")
        Job job = new Job(conf, "Recipe");

        job.setJarByClass(Recipe.class);
        job.setMapperClass(TokenizerMapper.class);
        job.setCombinerClass(IntSumReducer.class);
        job.setReducerClass(IntSumReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        FileInputFormat.addInputPath(job, new Path(otherArgs[0]));
        FileOutputFormat.setOutputPath(job, new Path(otherArgs[1]));
       // FileInputFormat.addInputPath(job, new Path("hdfs://127.0.0.1:9000/in"));
       // FileOutputFormat.setOutputPath(job, new Path("hdfs://127.0.0.1:9000/out"));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
       // job.submit();
    }
}

 class Id
{

    public String oid;
}


 class Ts
{

    public long date ;
}

class Roo
{

    public Id _id ;

    public String name ;

    public String ingredients ;

    public String url ;

    public String image ;

    public Ts ts ;

    public String cookTime;

    public String source ;

    public String recipeYield ;
    public String datePublished;

    public String prepTime ;

    public String description;
}

最佳答案

如何使用Roo初始化roo的值roo = gson.fromJson(value.toString(),Roo.class)。

另外,能否请您提供驱动程序代码中传递的输入文件的示例列表。

关于java - Hadoop:不支持的名称:具有方案但相对路径部分错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36819404/

相关文章:

java - GWT,修改使用InputStreamReader和java.net.URL类通过Post发送HashMap或其他对象的代码?

hadoop - Apache pig : How to load a sequence file which is stored in hdfs?

Java collect 函数给出循环推理错误

java - 从 HashMap 获取值并填充 Java 对象

java - 在 Java 8 中没有获得正确的时区?

java - 在 Ubuntu 上安装 Oracle 8 JDK

java - 事务需要异常 : no transaction is in progress with Spring Data JPA

java - MySQL JDBC over SSL 问题

hadoop - Mahout - 朴素贝叶斯模型非常慢

java - 创建外部表hive,location里面包含多个文件