- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在从映射器发出 TwoDArrayWritable。我已经实现了扩展 TwoDArrayWritable 的类,以便创建默认构造函数。但是当我尝试发出它时,它给了我以下异常:
Error: java.lang.RuntimeException: java.lang.InstantiationException: org.apache.hadoop.io.TwoDArrayWritable
at org.apache.hadoop.io.TwoDArrayWritable.readFields(TwoDArrayWritable.java:75)
at org.apache.hadoop.io.serializer.WritableSerialization$WritableDeserializer.deserialize(WritableSerialization.java:71)
我如何发射 TwoDArrayWritable?我需要一些帮助。
这是扩展 TwoDArrayWritable 的类:
public class TwoDArrayWritables extends TwoDArrayWritable
{
public TwoDArrayWritables() {
super(TwoDArrayWritable.class);
}
public TwoDArrayWritables(Class valueClass) {
super(valueClass);
// TODO Auto-generated constructor stub
}
这是映射器:
public class JaccardMapper extends Mapper<LongWritable, Text, IntTextPair, TwoDArrayWritables> {
Hashtable movieInfo = new Hashtable<String, String>();
String[] genres, actors, entities;
String[] attributes = new String[] {"genre", "actors", "directors", "country", "year", "ratings"};
double p,q,r,s;
double result = 0.0;
String input[] = null;
Set<String> keys;
TwoDArrayWritables array2d = new TwoDArrayWritables();
//TwoDArrayWritable array2d = new TwoDArrayWritable(IntWritable.class);
IntWritable[][] jaccard = new IntWritable[2][];
//int[][] jaccard = new int[2][];
public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException
{
p = 0;
q = 0;
r = 0;
s = 0;
input = value.toString().toLowerCase().split(",");
keys = movieInfo.keySet();
//the jaccards 2d array column length depends on the user input best case is 6 but the worst case depends on the sub attributes count like more than one actor/director/genre/country.
int columnlength = input[1].split("\\|").length + input[2].split("\\|").length + input[3].split("\\|").length + input[4].split("\\|").length + 2;
jaccard = new IntWritable[2][columnlength];
for (int i = 0; i < jaccard.length; i++)
{
for (int j = 0; j < jaccard[i].length; j++)
{
jaccard[i][j] = new IntWritable(0);
}
}
if (input.length > 0)
{
//iterate through the dataset in cache
for(String keyy : keys)
{
//iterate to user's input attributes
for (int attribute = 1; attribute < attributes.length; attribute++)
{
if (!input[attribute].equals("-"))
{
entities = input[attribute].toLowerCase().split("\\|");
int subattributecount = 0;
for(String entity : entities)
{
subattributecount += 1;
}
}
}
IntTextPair pair = new IntTextPair(Integer.parseInt(input[0].toString()), movieInfo.get(keyy).toString());
array2d.set(jaccard);
context.write(pair, array2d);
}
}
}
}
这是 reducer :公共(public)类 JaccardReducer 扩展 Reducer {
double p,q,r,s;
double result = 0.0;
//IntWritable[][] jaccard = null;
IntWritable[][] jaccard;
int temp1 = 0, temp2 = 0;
//Jaccard distance 1.0 emplies that the user's criteria doesn't meet at all
public static final double nonacceptvalue = 1.0;
public void reduce(IntTextPair key, Iterable<TwoDArrayWritables> values, Context context) throws IOException, InterruptedException
{
IntDoublePair pair = new IntDoublePair(key.getFirst().get(), Double.parseDouble("110.00"));
for (TwoDArrayWritable value : values)
{
if (value != null)
{
context.write(pair, new Text("Is not null"));
}
else
{
context.write(pair, new Text("Is null"));
}
}
}
}
最佳答案
您在默认构造函数(在 super 中)中指定的类应该是值的类,而不是整个类本身。所以你可能想要:
public TwoDArrayWritables() {
super(IntWritable.class);
}
关于java - Hadoop - 如何发射 TwoDArrayWritable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27703609/
我从映射器发出二维 double 组作为值,并尝试在 reducer 中访问它。转换回 double 以获得所有二维数组的总和。 public static class DoubleTwoDArray
我想使用 TwoDArrayWritable 作为值发出一个二维 double 组。 如何编写 context.write(key , ) 编辑 并且在 Reducer 中如何在二维 double 组
我正在从映射器发出 TwoDArrayWritable。我已经实现了扩展 TwoDArrayWritable 的类,以便创建默认构造函数。但是当我尝试发出它时,它给了我以下异常: Error: jav
为了发出 2 个矩阵作为键值对: Key - Matrix A 值 - 矩阵 B。 我应该创建一个自定义数据类型还是可以直接使用TwoDArrayWritable?那么自定义类中的 compareT
尝试从映射器发出 2 个双维数组作为值。在 hadoop 中,我们有 TwoDArrayWritable,它将 1 - 2D array 作为输入。为了实现我的用例,我尝试编辑 TwoDArrayWr
我是一名优秀的程序员,十分优秀!