Java Code Examples for org.apache.flink.api.java.tuple.Tuple2#getField()

The following examples show how to use org.apache.flink.api.java.tuple.Tuple2#getField() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MatchRemovingJoiner.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void join(Tuple2<Integer, String> rec1, Tuple2<Integer, String> rec2, Collector<Tuple2<Integer, String>> out) throws Exception {
	final Integer key = rec1 != null ? (Integer) rec1.getField(0) : (Integer) rec2.getField(0);
	final String value1 = rec1 != null ? (String) rec1.getField(1) : null;
	final String value2 = rec2 != null ? (String) rec2.getField(1) : null;

	Collection<Match> matches = this.toRemoveFrom.get(key);
	if (matches == null) {
		Assert.fail("Match " + key + " - " + value1 + ":" + value2 + " is unexpected.");
	}

	boolean contained = matches.remove(new Match(value1, value2));
	if (!contained) {
		Assert.fail("Produced match was not contained: " + key + " - " + value1 + ":" + value2);
	}
	if (matches.isEmpty()) {
		this.toRemoveFrom.remove(key);
	}
}
 
Example 2
Source File: ReusingSortMergeInnerJoinIteratorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
throws Exception
{
	Map<Integer, Collection<String>> map = new HashMap<Integer, Collection<String>>();
	Tuple2<Integer, String> pair = new Tuple2<Integer, String>();
	
	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);
		
		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<String>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 3
Source File: AbstractSortMergeOuterJoinIteratorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
		throws Exception {
	final Map<Integer, Collection<String>> map = new HashMap<>();
	Tuple2<Integer, String> pair = new Tuple2<>();

	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);

		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<String>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 4
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
		throws Exception
{
	Map<Integer, Collection<String>> map = new HashMap<Integer, Collection<String>>();
	Tuple2<Integer, String> pair = new Tuple2<Integer, String>();

	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);

		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<String>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 5
Source File: RandomSortMergeInnerJoinTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public static Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
		throws Exception {
	final Map<Integer, Collection<String>> map = new HashMap<>();
	Tuple2<Integer, String> pair = new Tuple2<>();

	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);

		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 6
Source File: ReusingSortMergeInnerJoinIteratorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
throws Exception
{
	Map<Integer, Collection<String>> map = new HashMap<Integer, Collection<String>>();
	Tuple2<Integer, String> pair = new Tuple2<Integer, String>();
	
	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);
		
		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<String>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 7
Source File: AbstractSortMergeOuterJoinIteratorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
		throws Exception {
	final Map<Integer, Collection<String>> map = new HashMap<>();
	Tuple2<Integer, String> pair = new Tuple2<>();

	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);

		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<String>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 8
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java    From flink with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
		throws Exception
{
	Map<Integer, Collection<String>> map = new HashMap<Integer, Collection<String>>();
	Tuple2<Integer, String> pair = new Tuple2<Integer, String>();

	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);

		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<String>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 9
Source File: RandomSortMergeInnerJoinTest.java    From flink with Apache License 2.0 6 votes vote down vote up
public static Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
		throws Exception {
	final Map<Integer, Collection<String>> map = new HashMap<>();
	Tuple2<Integer, String> pair = new Tuple2<>();

	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);

		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 10
Source File: MatchRemovingJoiner.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
public void join(Tuple2<Integer, String> rec1, Tuple2<Integer, String> rec2, Collector<Tuple2<Integer, String>> out) throws Exception {
	final Integer key = rec1 != null ? (Integer) rec1.getField(0) : (Integer) rec2.getField(0);
	final String value1 = rec1 != null ? (String) rec1.getField(1) : null;
	final String value2 = rec2 != null ? (String) rec2.getField(1) : null;

	Collection<Match> matches = this.toRemoveFrom.get(key);
	if (matches == null) {
		Assert.fail("Match " + key + " - " + value1 + ":" + value2 + " is unexpected.");
	}

	boolean contained = matches.remove(new Match(value1, value2));
	if (!contained) {
		Assert.fail("Produced match was not contained: " + key + " - " + value1 + ":" + value2);
	}
	if (matches.isEmpty()) {
		this.toRemoveFrom.remove(key);
	}
}
 
Example 11
Source File: MatchRemovingJoiner.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
public void join(Tuple2<Integer, String> rec1, Tuple2<Integer, String> rec2, Collector<Tuple2<Integer, String>> out) throws Exception {
	final Integer key = rec1 != null ? (Integer) rec1.getField(0) : (Integer) rec2.getField(0);
	final String value1 = rec1 != null ? (String) rec1.getField(1) : null;
	final String value2 = rec2 != null ? (String) rec2.getField(1) : null;

	Collection<Match> matches = this.toRemoveFrom.get(key);
	if (matches == null) {
		Assert.fail("Match " + key + " - " + value1 + ":" + value2 + " is unexpected.");
	}

	boolean contained = matches.remove(new Match(value1, value2));
	if (!contained) {
		Assert.fail("Produced match was not contained: " + key + " - " + value1 + ":" + value2);
	}
	if (matches.isEmpty()) {
		this.toRemoveFrom.remove(key);
	}
}
 
Example 12
Source File: AbstractSortMergeOuterJoinIteratorITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
		throws Exception {
	final Map<Integer, Collection<String>> map = new HashMap<>();
	Tuple2<Integer, String> pair = new Tuple2<>();

	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);

		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<String>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 13
Source File: NonReusingSortMergeInnerJoinIteratorITCase.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private Map<Integer, Collection<String>> collectData(MutableObjectIterator<Tuple2<Integer, String>> iter)
		throws Exception
{
	Map<Integer, Collection<String>> map = new HashMap<Integer, Collection<String>>();
	Tuple2<Integer, String> pair = new Tuple2<Integer, String>();

	while ((pair = iter.next(pair)) != null) {
		final Integer key = pair.getField(0);

		if (!map.containsKey(key)) {
			map.put(key, new ArrayList<String>());
		}

		Collection<String> values = map.get(key);
		final String value = pair.getField(1);
		values.add(value);
	}

	return map;
}
 
Example 14
Source File: AdvertisingTopologyFlinkState.java    From yahoo-streaming-benchmark with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 15
Source File: AdvertisingTopologyFlinkWindows.java    From yahoo-streaming-benchmark with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 16
Source File: AdvertisingTopologyNative.java    From yahoo-streaming-benchmark with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 17
Source File: AdvertisingTopologyNative.java    From streaming-benchmarks with Apache License 2.0 5 votes vote down vote up
@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<String, String, String>(
            campaign_id,
            (String) input.getField(0),
            (String) input.getField(1));
    out.collect(tuple);
}
 
Example 18
Source File: TupleUnwrappingJoiner.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <V> V unwrap(Tuple2<K, V> t) {
	return t == null ? null : (V) (t.getField(1));
}
 
Example 19
Source File: TupleUnwrappingJoiner.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <V> V unwrap(Tuple2<K, V> t) {
	return t == null ? null : (V) (t.getField(1));
}
 
Example 20
Source File: TupleUnwrappingJoiner.java    From flink with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private <V> V unwrap(Tuple2<K, V> t) {
	return t == null ? null : (V) (t.getField(1));
}