gpt4 book ai didi

hadoop - 为流作业指定自己的输入格式

转载 作者:可可西里 更新时间:2023-11-01 14:21:16 25 4
gpt4 key购买 nike

我定义了我自己的输入格式如下,以防止文件拆分:

import org.apache.hadoop.fs.*;
import org.apache.hadoop.mapred.TextInputFormat;

public class NSTextInputFormat extends TextInputFormat {
@Override
protected boolean isSplitable(FileSystem fs, Path file) {
return false;
}
}

我使用 Eclipse 将其编译成类 NSTextInputFormat.class。我将此类复制到启 Action 业的客户端。我使用以下命令启 Action 业并将上面的类作为输入格式传递。

hadoop jar $HADOOP_HOME/hadoop-streaming.jar -Dmapred.job.queue.name=unfunded -input 24222910/framefile -input 24225109/framefile -output 输出 -inputformat NSTextInputFormat -mapper ExtractHSV -file ExtractHSV -file NSTextInputFormat.class -numReduceTasks 0

这没有说明:-输入格式:找不到类:NSTextInputFormat流媒体作业失败!

我将 PATH 和 CLASSPATH 变量设置为包含 NSTextInputFormat.class 的目录,但仍然不起作用。对此的任何指示都会有所帮助。

最佳答案

如果您不熟悉 Java,这里有一些陷阱可以帮助您。

-inputformat(以及其他需要类名的命令行选项)需要一个完全限定的类名,否则它希望在某些 org.apache.hadoop...命名空间。所以你必须在你的 .java 文件中包含一个包名

package org.example.hadoop;

import org.apache.hadoop.fs.*;
import org.apache.hadoop.mapred.TextInputFormat;

public class NSTextInputFormat extends TextInputFormat {
@Override
protected boolean isSplitable(FileSystem fs, Path file) {
return false;
}
}

并在命令行中指定全名:

-inputformat org.example.hadoop.NSTextInputFormat

构建 jar 文件时,.class 文件也必须位于反射(reflect)包名称的目录结构中。我确定这是 Java Packaging 101,但如果您使用的是 Hadoop Streaming,那么您可能一开始就不太熟悉 Java。将 -d 选项传递给 javac 将告诉它将输入文件编译为与包名称匹配的目录中的 .class 文件。

javac -classpath `hadoop classpath` -d ./output NSTextInputFormat.java

编译后的.class文件会写入./output/org/example/hadoop/NSTextInputFormat.class。您将需要创建 output 目录,但将为您创建其他子目录。然后可以像这样创建 jar 文件:

jar cvf myjar.jar -C ./output/ .

你应该会看到类似这样的输出:

added manifest
adding: org/(in = 0) (out= 0)(stored 0%)
adding: org/example/(in = 0) (out= 0)(stored 0%)
adding: org/example/hadoop/(in = 0) (out= 0)(stored 0%)
adding: org/example/hadoop/NSTextInputFormat.class(in = 372) (out= 252)(deflated 32%)

关于hadoop - 为流作业指定自己的输入格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9205943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com