/** * Project "supplier". * * <p>Output Schema: Key: nationkey Value: suppkey */ @Override public void map(Record record, Collector<Record> out) throws Exception { suppKey = record.getField(0, suppKey); inputTuple = record.getField(1, inputTuple); /* Project (suppkey | name, address, nationkey, phone, acctbal, comment): */ IntValue nationKey = new IntValue(Integer.parseInt(inputTuple.getStringValueAt(3))); record.setField(0, nationKey); record.setField(1, suppKey); out.collect(record); }
@Override public Record readRecord(Record target, byte[] record, int offset, int numBytes) { String line = new String(record, offset, numBytes); try { this.key.setValue(Integer.parseInt(line.substring(0, line.indexOf("_")))); this.value.setValue(Integer.parseInt(line.substring(line.indexOf("_") + 1, line.length()))); } catch (RuntimeException re) { return null; } target.setField(0, this.key); target.setField(1, this.value); return target; }
@Override public void coGroup( Iterator<Record> candidates, Iterator<Record> current, Collector<Record> out) throws Exception { if (!current.hasNext()) { throw new Exception("Error: Id not encountered before."); } Record old = current.next(); long oldId = old.getField(1, LongValue.class).getValue(); long minimumComponentID = Long.MAX_VALUE; while (candidates.hasNext()) { long candidateComponentID = candidates.next().getField(1, LongValue.class).getValue(); if (candidateComponentID < minimumComponentID) { minimumComponentID = candidateComponentID; } } if (minimumComponentID < oldId) { newComponentId.setValue(minimumComponentID); old.setField(1, newComponentId); out.collect(old); } }