@Override public void writeRecord(Record record) throws IOException { key = record.getField(0, key); value = record.getField(1, value); this.buffer.setLength(0); this.buffer.append(key.getFirst().toString()); this.buffer.append('|'); this.buffer.append(key.getSecond().toString()); this.buffer.append('|'); this.buffer.append(value.toString()); this.buffer.append('\n'); byte[] bytes = this.buffer.toString().getBytes(); this.stream.write(bytes); }
@Override public void writeRecord(Record record) throws IOException { StringBuilder line = new StringBuilder(); // append from-node line.append(record.getField(0, StringValue.class).toString()); line.append("|"); // append to-node line.append(record.getField(1, StringValue.class).toString()); line.append("|"); // append length line.append(record.getField(2, IntValue.class).toString()); line.append("|"); // append hopCnt line.append(record.getField(3, IntValue.class).toString()); line.append("|"); // append hopList line.append(record.getField(4, StringValue.class).toString()); line.append("|"); line.append("\n"); stream.write(line.toString().getBytes()); } }
@Override public void writeRecord(Record record) throws IOException { this.buffer.setLength(0); this.buffer.append(record.getField(0, IntValue.class).toString()).append('|'); this.buffer.append(record.getField(1, StringValue.class).toString()).append('|'); this.buffer.append(this.formatter.format(record.getField(2, DoubleValue.class).getValue())).append('|'); this.buffer.append(record.getField(3, StringValue.class).toString()).append('|'); this.buffer.append(record.getField(4, StringValue.class).toString()).append('|'); this.buffer.append(record.getField(5, StringValue.class).toString()).append('|'); this.buffer.append(record.getField(6, StringValue.class).toString()).append('|'); this.buffer.append(record.getField(7, StringValue.class).toString()).append('|'); this.buffer.append('\n'); final byte[] bytes = this.buffer.toString().getBytes(); this.stream.write(bytes); } }
/** * Join "orders" and "lineitem" by "orderkey". * * Output Schema: * Key: (partkey, suppkey) * Value: (year, quantity, price) * */ @Override public void join(Record value1, Record value2, Collector<Record> out) throws Exception { IntValue year = value1.getField(1, IntValue.class); Tuple lineItem = value2.getField(1, Tuple.class); /* (partkey, suppkey) from lineItem: */ IntPair newKey = new IntPair(new IntValue(Integer.parseInt(lineItem.getStringValueAt(0))), new IntValue(Integer.parseInt(lineItem.getStringValueAt(1)))); Tuple newValue = new Tuple(); newValue.addAttribute(year.toString()); // year newValue.addAttribute(lineItem.getStringValueAt(2)); // quantity newValue.addAttribute(lineItem.getStringValueAt(3)); // price value1.setField(0, newKey); value1.setField(1, newValue); out.collect(value1); }