public Tuple2<String, Integer> call(String x){ return new Tuple2(x, 1); }}).reduceByKey(new Function2<Integer, Integer, Integer>(){ public Integer call(Integer x, Integer y){ return x+y;}});
@Override public Tuple2<String, String> call(String x) { return new Tuple2(x.split(" ")[0], x); } };
public Tuple2<String, Integer> call(Tuple2<Text, IntWritable> record) { return new Tuple2(record._1.toString(), record._2.get()); } }
// you'll have to write or download a Tuple class in Java, (.NET ships with one) // create our map Map<string, Tuple2<Person, Person> peopleByForename = new HashMap<string, Tuple2<Person, Person>>(); // populate it peopleByForename.put("Bob", new Tuple2(new Person("Bob Smith", new Person("Bob Jones")); // read from it Tuple<Person, Person> bobs = peopleByForename["Bob"]; Person bob1 = bobs.Item1; Person bob2 = bobs.Item2;
public Tuple2<Text, IntWritable> call(Tuple2<String, Integer> record) { return new Tuple2(new Text(record._1), new IntWritable(record._2)); } }
@Override public Tuple2<String, Long> call(ApacheAccessLog log) { return new Tuple2<>(log.getIpAddress(), 1L); } }
@Override public Tuple2<String, Long> call(ApacheAccessLog log) { return new Tuple2<>(log.getEndpoint(), 1L); } }
@Override public Tuple2<Integer, Long> call(ApacheAccessLog log) { return new Tuple2<>(log.getResponseCode(), 1L); } }
public Tuple2<String, Long> call(ApacheAccessLog entry) { return new Tuple2(entry.getIpAddress(), 1L); }}); JavaPairDStream<String, Long> ipCountDStream = ipAddressPairDStream.reduceByKeyAndWindow(
public Tuple2<Integer, String[]> call(String line) throws Exception { CSVReader reader = new CSVReader(new StringReader(line)); String[] elements = reader.readNext(); Integer key = Integer.parseInt(elements[0]); return new Tuple2(key, elements); } }
public Tuple2<Text, LongWritable> call(Tuple2<String, Long> e) { return new Tuple2(new Text(e._1()), new LongWritable(e._2())); } });
@Override public List<Tuple2<Long, Integer>> snapshotState(long checkpointId, long timestamp) throws Exception { LOG.debug("Snapshotting state {} @ ID {}.", current, checkpointId); return Collections.singletonList(new Tuple2<>(this.current, this.repeat)); }
public Tuple2<Long, Integer> call(Tuple2<LongWritable, Text> input) { return new Tuple2(input._1().get(), Integer.parseInt(input._2().toString())); } });
@Override public Tuple2<String, Long> call(ApacheAccessLog log) { return new Tuple2<>(log.getIpAddress(), log.getContentSize()); } }
@Override public Tuple2<WritableComparable, Writable> call(Tuple2<WritableComparable, Writable> tuple) throws Exception { if (conf == null) { conf = new Configuration(); } return new Tuple2<WritableComparable, Writable>(tuple._1(), WritableUtils.clone(tuple._2(), conf)); }
@Override public Tuple2<RowKeyWritable, KeyValue> call(Tuple2<Text, Text> textTextTuple2) throws Exception { KeyValue outputValue = keyValueCreators.get(0).create(textTextTuple2._1, textTextTuple2._2.getBytes(), 0, textTextTuple2._2.getLength()); return new Tuple2<>(new RowKeyWritable(outputValue.createKeyOnly(false).getKey()), outputValue); } });
static Tuple2<String, CallLog[]> fetchResultFromRequest(ObjectMapper mapper, Tuple2<String, ContentExchange> signExchange) { String sign = signExchange._1(); ContentExchange exchange = signExchange._2(); return new Tuple2(sign, readExchangeCallLog(mapper, exchange)); } static Tuple2<String, ContentExchange> createRequestForSign(String sign, HttpClient client) throws Exception {
static Tuple2<String, ContentExchange> createRequestForSign(String sign, HttpClient client) throws Exception { ContentExchange exchange = new ContentExchange(true); exchange.setURL("http://new73s.herokuapp.com/qsos/" + sign + ".json"); client.send(exchange); return new Tuple2(sign, exchange); } static ObjectMapper createMapper() {
@Override public Tuple2<ImmutableBytesWritable, KeyValue> call( Tuple2<RowKeyWritable, KeyValue> rowKeyWritableKeyValueTuple2) throws Exception { return new Tuple2<>(new ImmutableBytesWritable(rowKeyWritableKeyValueTuple2._2.getKey()), rowKeyWritableKeyValueTuple2._2); } }).saveAsNewAPIHadoopDataset(job.getConfiguration());
public Tuple2<String, Integer> call(Tuple2<String, Integer> callSignCount) { String sign = callSignCount._1(); String country = lookupCountry(sign, signPrefixes.value()); return new Tuple2(country, callSignCount._2()); }}).reduceByKey(new SumInts()); countryContactCounts.saveAsTextFile(outputDir + "/countries.txt");