source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/mapred/lib/aggregate/AggregatorTests.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19package org.apache.hadoop.mapred.lib.aggregate;
20
21import org.apache.hadoop.io.Text;
22import java.util.ArrayList;
23import java.util.Map.Entry;
24
25public class AggregatorTests extends ValueAggregatorBaseDescriptor {
26 
27  public ArrayList<Entry<Text, Text>> generateKeyValPairs(Object key, Object val) {
28    ArrayList<Entry<Text, Text>> retv = new ArrayList<Entry<Text, Text>>();
29    String [] words = val.toString().split(" ");
30   
31    String countType;
32    String id;
33    Entry<Text, Text> e;
34   
35    for (String word: words) {
36      long numVal = Long.parseLong(word);
37      countType = LONG_VALUE_SUM;
38      id = "count_" + word;
39      e = generateEntry(countType, id, ONE);
40      if (e != null) {
41        retv.add(e);
42      }
43      countType = LONG_VALUE_MAX;
44      id = "max";
45      e = generateEntry(countType, id, new Text(word));
46      if (e != null) {
47        retv.add(e);
48      }
49     
50      countType = LONG_VALUE_MIN;
51      id = "min";
52      e = generateEntry(countType, id, new Text(word));
53      if (e != null) {
54        retv.add(e);
55      }
56     
57      countType = STRING_VALUE_MAX;
58      id = "value_as_string_max";
59      e = generateEntry(countType, id, new Text(""+numVal));
60      if (e != null) {
61        retv.add(e);
62      }
63     
64      countType = STRING_VALUE_MIN;
65      id = "value_as_string_min";
66      e = generateEntry(countType, id, new Text(""+numVal));
67      if (e != null) {
68        retv.add(e);
69      }
70     
71      countType = UNIQ_VALUE_COUNT;
72      id = "uniq_count";
73      e = generateEntry(countType, id, new Text(word));
74      if (e != null) {
75        retv.add(e);
76      }
77     
78      countType = VALUE_HISTOGRAM;
79      id = "histogram";
80      e = generateEntry(countType, id, new Text(word));
81      if (e != null) {
82        retv.add(e);
83      }
84    }
85    return retv;
86  }
87
88}
Note: See TracBrowser for help on using the repository browser.