は、あなたがこの方法で何が起こっているのかを理解することができますので、私はSystem.out
ステートメントを追加した、cleanup()
メソッドを使用する必要があります。入力あなたがMapper class here.
public static class StackMapper extends Mapper<Object, Text, Text, Text> {
private Map<Text, ArrayList<Text>> products = new HashMap<Text, ArrayList<Text>>();
private ArrayList<Text> p = new ArrayList<Text>();
@Override
public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
String line = value.toString();
String[] arrLine = line.split(",");
Text strDate = new Text(arrLine[0].substring(0, arrLine[0].indexOf(" ")));
Text strProductName = new Text(arrLine[1]);
if(products.containsKey(strDate))
{
if(!products.get(strDate).contains(strProductName)) {
System.out.println("has date: " + strDate + " " + strProductName + " not exist, added to list: " + p.toString());
p.add(strProductName);
}
System.out.println("has date: " + strDate + ", " + strProductName + " added to list: " + p.toString());
}else
{
p = new ArrayList<Text>();
p.add(strProductName);
System.out.println("new date: " + strDate + ", " + strProductName + " added to list: " + p.toString());
}
products.put(new Text(strDate), p);
}
@Override
protected void cleanup(Context context)
throws IOException, InterruptedException {
for (Text date : products.keySet()){
context.write(date, new Text(products.get(date).toString()));
}
}
}
に使用できる利用可能な方法を参照してください。
1/2/09 6:17,product1,f3,f4,f5
1/2/09 6:17,product2,f3,f4,f5
1/2/09 6:17,product3,f3,f4,f5
1/2/09 6:17,product4,f3,f4,f5
1/2/09 6:17,product4,f3,f4,f5
1/2/10 6:17,product1,f3,f4,f5u
1/2/10 6:17,product2,f3,f4,f5u
1/2/10 6:17,product3,f3,f4,f5u
1/2/11 6:17,product2,f3,f4,f5u
1/2/12 6:17,product2,f3,f4,f5u
1/2/12 6:17,product3,f3,f4,f5u
出力:
1/2/09 [product1, product2, product3, product4]
1/2/10 [product1, product2, product3]
1/2/12 [product2, product3]
1/2/11 [product2]
MRジョブのSTD出力:エフォート@BigDataLearnerため
new date: 1/2/09, product1 added to list: [product1]
has date: 1/2/09 product2 not exist, added to list: [product1]
has date: 1/2/09, product2 added to list: [product1, product2]
has date: 1/2/09 product3 not exist, added to list: [product1, product2]
has date: 1/2/09, product3 added to list: [product1, product2, product3]
has date: 1/2/09 product4 not exist, added to list: [product1, product2, product3]
has date: 1/2/09, product4 added to list: [product1, product2, product3, product4]
has date: 1/2/09, product4 added to list: [product1, product2, product3, product4]
new date: 1/2/10, product1 added to list: [product1]
has date: 1/2/10 product2 not exist, added to list: [product1]
has date: 1/2/10, product2 added to list: [product1, product2]
has date: 1/2/10 product3 not exist, added to list: [product1, product2]
has date: 1/2/10, product3 added to list: [product1, product2, product3]
new date: 1/2/11, product2 added to list: [product2]
new date: 1/2/12, product2 added to list: [product2]
has date: 1/2/12 product3 not exist, added to list: [product2]
has date: 1/2/12, product3 added to list: [product2, product3]
感謝。あなたのソリューションは私の要件に近づきました – Mugil