1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package datafu.pig.bags; |
18 | |
|
19 | |
import java.io.IOException; |
20 | |
|
21 | |
import org.apache.pig.EvalFunc; |
22 | |
import org.apache.pig.data.BagFactory; |
23 | |
import org.apache.pig.data.DataBag; |
24 | |
import org.apache.pig.data.DataType; |
25 | |
import org.apache.pig.data.Tuple; |
26 | |
import org.apache.pig.data.TupleFactory; |
27 | |
import org.apache.pig.impl.logicalLayer.schema.Schema; |
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | 1264 | public class BagConcat extends EvalFunc<DataBag> |
50 | |
{ |
51 | 1 | private static final BagFactory bagFactory = BagFactory.getInstance(); |
52 | 1 | private static final TupleFactory tupleFactory = TupleFactory.getInstance(); |
53 | |
|
54 | |
@Override |
55 | |
public DataBag exec(Tuple input) throws IOException |
56 | |
{ |
57 | 2 | DataBag outputBag = bagFactory.newDefaultBag(); |
58 | |
|
59 | |
try { |
60 | 8 | for (int i=0; i < input.size(); i++) { |
61 | 6 | Object o = input.get(i); |
62 | 6 | if (!(o instanceof DataBag)) |
63 | 0 | throw new RuntimeException("parameters must be databags"); |
64 | |
|
65 | 6 | DataBag inputBag = (DataBag) o; |
66 | 6 | for (Tuple elem : inputBag) |
67 | 14 | outputBag.add(elem); |
68 | |
} |
69 | |
|
70 | 2 | return outputBag; |
71 | |
} |
72 | 0 | catch (Exception e) { |
73 | 0 | throw new IOException(e); |
74 | |
} |
75 | |
} |
76 | |
|
77 | |
@Override |
78 | |
public Schema outputSchema(Schema input) |
79 | |
{ |
80 | |
try { |
81 | 275 | return new Schema(new Schema.FieldSchema(getSchemaName(this.getClass().getName().toLowerCase(), input), |
82 | |
input.getField(0).schema, DataType.BAG)); |
83 | |
} |
84 | 0 | catch (Exception e) { |
85 | 0 | return null; |
86 | |
} |
87 | |
} |
88 | |
} |
89 | |
|