/** * Gets this StringValue as a String. * * @return A String resembling the contents of this StringValue. */ public String getValue() { return toString(); }
/** * Gets this StringValue as a String. * * @return A String resembling the contents of this StringValue. */ public String getValue() { return toString(); }
@Override public void writeRecord(Record record) throws IOException { this.buffer.setLength(0); this.buffer.append(record.getField(0, keyString).toString()); this.buffer.append(' '); this.buffer.append(record.getField(1, valueInteger).getValue()); this.buffer.append('\n'); byte[] bytes = this.buffer.toString().getBytes(); if (LOG.isDebugEnabled()) LOG.debug("Writing out: [" + keyString.toString() + "," + valueInteger.getValue() + "]"); this.stream.write(bytes); } }
@Override public void writeRecord(Record record) throws IOException { this.buffer.setLength(0); this.buffer.append(record.getField(0, keyString).toString()); this.buffer.append(' '); this.buffer.append(record.getField(1, valueInteger).getValue()); this.buffer.append('\n'); byte[] bytes = this.buffer.toString().getBytes(); LOG.debug("Writing out: [" + keyString.toString() + "," + valueInteger.getValue() + "]"); this.stream.write(bytes); } }
@Override public void map(Record record, Collector<Record> out) throws Exception { keyString = record.getField(0, keyString); valueString = record.getField(1, valueString); if (LOG.isDebugEnabled()) LOG.debug("Processed: [" + keyString.toString() + "," + valueString.getValue() + "]"); if (Integer.parseInt(keyString.toString()) + Integer.parseInt(valueString.toString()) < 10) { record.setField(0, valueString); record.setField(1, new IntValue(Integer.parseInt(keyString.toString()) + 10)); out.collect(record); } } }
@Override public void map(Record record, Collector<Record> out) throws Exception { keyString = record.getField(0, keyString); valueString = record.getField(1, valueString); LOG.debug("Processed: [" + keyString.toString() + "," + valueString.getValue() + "]"); if (Integer.parseInt(keyString.toString()) + Integer.parseInt(valueString.toString()) < 10) { record.setField(0, valueString); record.setField(1, new IntValue(Integer.parseInt(keyString.toString()) + 10)); out.collect(record); } } }
@Override public void map(Record record, Collector<Record> out) throws Exception { keyString = record.getField(0, keyString); valueString = record.getField(1, valueString); if (Integer.parseInt(keyString.toString()) + Integer.parseInt(valueString.toString()) < 10) { record.setField(0, valueString); record.setField(1, new IntValue(Integer.parseInt(keyString.toString()) + 10)); out.collect(record); } } }
@Override public void combine(Iterator<Record> records, Collector<Record> out) throws Exception { int sum = 0; Record record = new Record(); while (records.hasNext()) { record = records.next(); combineValue = record.getField(1, combineValue); sum += Integer.parseInt(combineValue.toString()); LOG.debug("Processed: [" + record.getField(0, StringValue.class).toString() + "," + combineValue.toString() + "]"); } combineValue.setValue(sum + ""); record.setField(1, combineValue); out.collect(record); }
@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); } }
@Override public void reduce(Iterator<Record> records, Collector<Record> out) throws Exception { int sum = 0; Record record = new Record(); while (records.hasNext()) { record = records.next(); reduceValue = record.getField(1, reduceValue); sum += Integer.parseInt(reduceValue.toString()); LOG.debug("Processed: [" + record.getField(0, StringValue.class).toString() + "," + reduceValue.toString() + "]"); } record.setField(1, new IntValue(sum)); out.collect(record); } }
@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 int serializeRecord(Record rec, byte[] target) throws Exception { String string = rec.getField(0, StringValue.class).toString(); byte[] stringBytes = string.getBytes(); Tuple tuple = rec.getField(1, Tuple.class); String tupleStr = tuple.toString(); byte[] tupleBytes = tupleStr.getBytes(); int totalLength = stringBytes.length + 1 + tupleBytes.length; if(target.length >= totalLength) { System.arraycopy(stringBytes, 0, target, 0, stringBytes.length); target[stringBytes.length] = '|'; System.arraycopy(tupleBytes, 0, target, stringBytes.length + 1, tupleBytes.length); return totalLength; } else { return -1 * totalLength; } }
@Override public void cross(Record record1, Record record2, Collector<Record> out) { string = record1.getField(1, string); int val1 = Integer.parseInt(string.toString()); string = record2.getField(1, string); int val2 = Integer.parseInt(string.toString()); string = record1.getField(0, string); int key1 = Integer.parseInt(string.toString()); string = record2.getField(0, string); int key2 = Integer.parseInt(string.toString()); LOG.debug("Processing { [" + key1 + "," + val1 + "] , [" + key2 + "," + val2 + "] }"); if (val1 + val2 <= 6) { string.setValue((key1 + key2 + 2) + ""); integer.setValue(val2 - val1 + 1); record1.setField(0, string); record1.setField(1, integer); out.collect(record1); } }
@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 map(Record record, Collector<Record> out) throws Exception { final StringValue keyString = record.getField(0, this.string); final int key = Integer.parseInt(keyString.toString()); final StringValue valueString = record.getField(1, this.string); final int value = Integer.parseInt(valueString.toString()); if (key + value < 10) { record.setField(0, valueString); this.integer.setValue(key + 10); record.setField(1, this.integer); out.collect(record); } } }
/** * Aggregate "amount": * * sum(amount) * GROUP BY nation, year * * Output Schema: * Key: (nation, year) * Value: amount * */ @Override public void reduce(Iterator<Record> records, Collector<Record> out) throws Exception { Record record = null; float amount = 0; while (records.hasNext()) { record = records.next(); StringValue value = record.getField(1, StringValue.class); amount += Float.parseFloat(value.toString()); } value.setValue(String.valueOf(amount)); record.setField(1, value); out.collect(record); }
/** * Filters for documents that contain all of the given keywords and projects the records on the URL field. * * Output Format: * 0: URL */ @Override public void map(Record record, Collector<Record> out) throws Exception { // FILTER // Only collect the document if all keywords are contained String docText = record.getField(1, StringValue.class).toString(); boolean allContained = true; for (String kw : KEYWORDS) { if (!docText.contains(kw)) { allContained = false; break; } } if (allContained) { record.setNull(1); out.collect(record); } } }
@Override public void join(Record value1, Record value2, Collector<Record> out) throws Exception { keyString = value1.getField(0, keyString); keyString.setValue(""+ (Integer.parseInt(keyString.getValue())+1)); value1.setField(0, keyString); valueString = value1.getField(1, valueString); int val1 = Integer.parseInt(valueString.getValue())+2; valueString = value2.getField(1, valueString); int val2 = Integer.parseInt(valueString.getValue())+1; value1.setField(1, new IntValue(val1 - val2)); out.collect(value1); if (LOG.isDebugEnabled()) LOG.debug("Processed: [" + keyString.toString() + "," + val1 + "] + " + "[" + keyString.toString() + "," + val2 + "]"); }
first = false; rec.copyTo(outRecord); returnTuple.addAttribute(rec.getField(0, StringValue.class).toString());
/** * Join together parts and orderedParts by matching partkey and suppkey. * * Output Schema: * Key: suppkey * Value: (amount, year) * */ @Override public void join(Record value1, Record value2, Collector<Record> out) throws Exception { IntPair partAndSupplierKey = value1.getField(0, this.partAndSupplierKey); StringValue supplyCostStr = value1.getField(1, this.supplyCostStr); Tuple ordersValue = value2.getField(1, this.ordersValue); IntValue year = new IntValue(Integer.parseInt(ordersValue.getStringValueAt(0))); float quantity = Float.parseFloat(ordersValue.getStringValueAt(1)); float price = Float.parseFloat(ordersValue.getStringValueAt(2)); float supplyCost = Float.parseFloat(supplyCostStr.toString()); float amount = price - supplyCost * quantity; /* Push (supplierKey, (amount, year)): */ value1.setField(0, partAndSupplierKey.getSecond()); value1.setField(1, new StringIntPair(new StringValue("" + amount), year)); out.collect(value1); }