public void write(DECISIONS dec, Context context, String url) throws IOException, InterruptedException{ DefaultTuple defTup=new DefaultTuple(); defTup.append(url); context.write(new IntWritable(dec.ordinal()), defTup); }
@Override public void write(DataOutput out) throws IOException { out.writeByte(DataType.TUPLE); int sz = size(); out.writeInt(sz); for (int i = 0; i < sz; i++) { DataReaderWriter.writeDatum(out, mFields.get(i)); } }
@Override public Class<? extends TupleRawComparator> tupleRawComparatorClass() { return DefaultTuple.getComparatorClass(); } }
@Override public void putNext(Tuple tuple) throws IOException { System.out.println(tuple.getClass().getName()); if (tuple != null) { try { Tuple t = new DefaultTuple(); for(Object val: tuple.getAll()) { t.append(val); } writer.write(NullWritable.get(), t); } catch (InterruptedException e) { // Under what circumstances does this happen? throw new IOException(e); } } } }
@Override public void readFields(DataInput in) throws IOException { // Clear our fields, in case we're being reused. mFields.clear(); // Make sure it's a tuple. byte b = in.readByte(); if (b != DataType.TUPLE) { int errCode = 2112; String msg = "Unexpected data while reading tuple " + "from binary file."; throw new ExecException(msg, errCode, PigException.BUG); } // Read the number of fields int sz = in.readInt(); for (int i = 0; i < sz; i++) { try { append(DataReaderWriter.readDatum(in)); } catch (ExecException ee) { throw ee; } } }
@Override public Tuple apply(Tuple2<IndexedKey, Tuple> v1) { LOG.debug("ToTupleFunction in : " + v1); DataBag bag = DefaultBagFactory.getInstance().newDefaultBag(); Tuple t = new DefaultTuple(); Tuple packagedTuple = null; try { Object key = v1._2().get(0); bag.add((Tuple) v1._2().get(1)); t.append(key); t.append(bag); poReduce.getPKGOp().getPkgr().attachInput(key, new DataBag[]{(DataBag) t.get(1)}, new boolean[]{true}); packagedTuple = (Tuple) poReduce.getPKGOp().getPkgr().getNext().result; } catch (ExecException e) { throw new RuntimeException(e); } LOG.debug("ToTupleFunction out : " + packagedTuple); return packagedTuple; } }
Tuple result = tf.newTuple(2); DataBag bag = DefaultBagFactory.getInstance().newDefaultBag(); Tuple t = new DefaultTuple(); try {
@SuppressWarnings("rawtypes") public Long exec(Tuple input) throws IOException { if (input == null) { return 0L; } long n = 0; if (input.size() != 0) { Object obj = input.get(0); if (obj instanceof DefaultTuple) { n = ((DefaultTuple)obj).size(); } else if (obj instanceof DataBag) { n = ((DataBag)obj).size(); } else if (obj instanceof String) { n = ((String)obj).length(); } else if (obj instanceof Map) { n = ((Map)obj).size(); } } return n; }