可以cat但不能在Hadoop DFS中使用ls文件

时间:2010-07-15 01:44:14

标签: java hadoop

这是有史以来最奇怪的事情。所以我可以看到这些文件并将其捕获:

[jchen@host hadoop-0.20.2]$ bin/hadoop fs -ls /users/jchen/                         
Found 3 items
-rw-r--r--   1 jchen supergroup   26553445 2010-07-14 21:10 /users/jchen/20100714T192827^AS17.data
-rw-r--r--   1 jchen supergroup  461957962 2010-07-14 21:10 /users/jchen/20100714T192857^AS1.data
-rw-r--r--   1 jchen supergroup   14026972 2010-07-14 21:10 /users/jchen/20100714T192949^AS311.data

[jchen@q01-ba-sas01 hadoop-0.20.2]$ bin/hadoop fs -cat /users/jchen/20100714T192949^AS311.data | head
SOME DATA

当我特意提到文件时:

[jchen@q01-ba-sas01 hadoop-0.20.2]$ bin/hadoop fs -ls /users/jchen/20100714T192949^AS311.data | head
ls: Cannot access /users/jchen/20100714T192949^AS311.data: No such file or directory

这里的frack是什么?我唯一能想到的是我在org.apache.hadoop.fs.FileSystem中使用了一个自定义方法来发布这些文件:

public boolean writeStreamToFile(boolean overwrite, 
                  InputStream src, Path dst)
    throws IOException {
    Configuration conf = getConf();
    return FileUtil.writeStream(src, this, dst, overwrite, conf);
}
//which calls this static method in org.apache.hadoop.fs.FileUtil:
public static boolean writeStream(InputStream src, 
                       FileSystem dstFS, Path dst,
                       boolean overwrite,
                       Configuration conf) throws IOException {

    dst = checkDest(dst.getName(), dstFS, dst, overwrite);

    OutputStream out=null;
    try{
        System.out.println("Started file creation");
        out = dstFS.create(dst, overwrite);
        System.out.println("completed file creation. starting stream copy");
        IOUtils.copyBytes(src, out, conf, true);
        System.out.println("completed stream copy.");
    } catch (IOException e) {
        IOUtils.closeStream(out);
        IOUtils.closeStream(src);
        throw e;
    }

    return true;
}

我在这里完全失去了。

1 个答案:

答案 0 :(得分:0)

根据this page,cat命令采用URI,ls命令采用路径。

确保您输入ls命令的路径正确无误。正如matt b所建议的那样,确保尽可能转义所有可能无效的字符。

您可以尝试使用hadoop支持通配符,如下所示:

/bin/hadoop rs -ls '/users/jchen/*AS311.data'

我假设您能够执行的cat命令允许您验证数据是否正确写入,因此writeStreamToFile是否正常?