gpt4 book ai didi

hadoop - 从 txt 文件读取并写入 HBase

转载 作者:行者123 更新时间:2023-12-02 21:57:31 25 4
gpt4 key购买 nike

我正在尝试从 txt 文件中读取并写入 HBase。

Job Class
Job job = new Job(conf, "HWriterJob");
job.setJarByClass(HWriterJob.class);
FileInputFormat.setInputPaths(job, new Path(otherArgs[0]));

job.setMapperClass(TokenizerMapper.class);
job.setOutputKeyClass(ImmutableBytesWritable.class);
job.setOutputValueClass(Put.class);

TableMapReduceUtil.initTableReducerJob(table,null,job);

Mapper Class
@Override
public void map(Text key, Text value, Context context)
throws IOException, InterruptedException {

String line = value.toString();

StringTokenizer st = new StringTokenizer(line, "|");
String result[] = new String[st.countTokens()];
int i = 0;
while (st.hasMoreTokens()) {
result[i] = st.nextToken();
i++;
}

Map<ImmutableBytesWritable,Put> resultSet = writeToHBase(result);

for (Map.Entry<ImmutableBytesWritable,Put> entry : resultSet.entrySet()) {
context.write(new Text(entry.getValue().getRow()), entry.getValue());
}
}

Reducer Class

public void reduce(Text key, Iterable<Put> values, Context context)
throws IOException, InterruptedException {

for (Put val : values) {
context.write(key, val);
}
}

但我做同样的事情没有成功。

我收到以下错误 java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.io.Text

最佳答案

显然 MR 默认将 LongWritable 作为 MapOutputKeyClass,在您的情况下应该是 Text,因此是错误。

尝试设置 job.setMapOutputKeyClass(Text.class)
还要适本地设置 job.setMapOutputValueClass。

关于hadoop - 从 txt 文件读取并写入 HBase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10228583/

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