@SuppressWarnings("unchecked") private <V> V unwrap(Tuple2<K, V> t) { return t == null ? null : (V) (t.getField(1)); }
@Override public String getKey(Tuple2<String, Integer> value) throws Exception { return value.getField(0); } },
@SuppressWarnings("unchecked") @Override public void join(Tuple2<K, I1> value1, I2 value2, Collector<OUT> collector) throws Exception { wrappedFunction.join(value1 == null ? null : (I1) value1.getField(1), value2, collector); } }
@SuppressWarnings("unchecked") @Override public void join(I1 value1, Tuple2<K, I2> value2, Collector<OUT> collector) throws Exception { wrappedFunction.join(value1, value2 == null ? null : (I2) value2.getField(1), collector); } }
@Override public Tuple2<Integer, Integer> map(Tuple2<Integer, Integer> value) throws Exception { Tuple2<Integer, Integer> t = new Tuple2<Integer, Integer>(); t.setField(value.f1, 0); t.setField(value.getField(0), 1); return t; } }
@SuppressWarnings("unchecked") private <V> V unwrap(Tuple2<K, V> t) { return t == null ? null : (V) (t.getField(1)); }
@SuppressWarnings("unchecked") private <V> V unwrap(Tuple2<K, V> t) { return t == null ? null : (V) (t.getField(1)); }
/** * Creates a tuple of integer and string from the input text. * * @param tuple tuple received from TextInputFormat, for each line * @return tuple of the text, which was split into integer and string * @throws Exception */ @Override public Tuple2<Integer, String> map(Tuple2<LongWritable, Text> tuple) throws Exception { String[] stringArray = tuple.getField(1).toString().split(" "); returnTuple.f0 = Integer.parseInt(stringArray[1]); returnTuple.f1 = stringArray[0]; return returnTuple; } }
/** * Creates a tuple of integer and string from the input text. * * @param tuple tuple received from TextInputFormat, for each line * @return tuple of the text, which was split into integer and string * @throws Exception */ @Override public Tuple2<Integer, String> map(Tuple2<LongWritable, Text> tuple) throws Exception { String[] stringArray = tuple.getField(1).toString().split(" "); returnTuple.f0 = Integer.parseInt(stringArray[1]); returnTuple.f1 = stringArray[0]; return returnTuple; } }
@SuppressWarnings("unchecked") @Override public void join(Tuple2<K, I1> value1, I2 value2, Collector<OUT> collector) throws Exception { wrappedFunction.join(value1 == null ? null : (I1) value1.getField(1), value2, collector); } }
@SuppressWarnings("unchecked") @Override public void join(I1 value1, Tuple2<K, I2> value2, Collector<OUT> collector) throws Exception { wrappedFunction.join(value1, value2 == null ? null : (I2) value2.getField(1), collector); } }
@SuppressWarnings("unchecked") @Override public void join(Tuple2<K, I1> value1, I2 value2, Collector<OUT> collector) throws Exception { wrappedFunction.join(value1 == null ? null : (I1) value1.getField(1), value2, collector); } }
@SuppressWarnings("unchecked") @Override public void join(I1 value1, Tuple2<K, I2> value2, Collector<OUT> collector) throws Exception { wrappedFunction.join(value1, value2 == null ? null : (I2) value2.getField(1), collector); } }
/** * Reduces the Tuple2 iterable into one map. * * @param iterable containing tuples of integer and string * @param collector collects one map from integer to string * @throws Exception */ @Override public void reduce( Iterable<Tuple2<Integer, String>> iterable, Collector<Map<Integer, String>> collector) throws Exception { Map<Integer, String> dictionary = Maps.newHashMap(); for (Tuple2<Integer, String> tuple : iterable) { dictionary.put( (Integer) tuple.getField(0), (String) tuple.getField(1)); } collector.collect(dictionary); } }
@Override public void flatMap(Tuple2<String, String> input, Collector<Tuple3<String, String, String>> out) throws Exception { String ad_id = input.getField(0); String campaign_id = this.redisAdCampaignCache.execute(ad_id); if (campaign_id == null) { return; } Tuple3<String, String, String> tuple = new Tuple3<>( campaign_id, (String) input.getField(0), (String) input.getField(1)); out.collect(tuple); } }
@Override public void flatMap(Tuple2<String, String> input, Collector<Tuple2<String, String>> out) throws Exception { String ad_id = input.getField(0); String campaign_id = this.redisAdCampaignCache.execute(ad_id); if (campaign_id == null) { return; } Tuple2<String, String> tuple = new Tuple2<>(campaign_id, (String) input.getField(1)); // event_time out.collect(tuple); } }
@Override public void flatMap(Tuple2<String, String> input, Collector<Tuple2<String, Long>> out) throws Exception { String ad_id = input.getField(0); String campaign_id = this.redisAdCampaignCache.execute(ad_id); if (campaign_id == null) { return; } Tuple2<String, Long> tuple = new Tuple2<>(campaign_id, Long.parseLong(input.f1)); out.collect(tuple); } }