List of usage examples for org.apache.spark.api.java Optional of
public static <T> Optional<T> of(T value)
From source file:com.splicemachine.derby.stream.control.ControlPairDataSet.java
License:Apache License
@Override public <W> PairDataSet<K, Tuple2<V, Optional<W>>> hashLeftOuterJoin(final PairDataSet<K, W> rightDataSet) { // Materializes the right side final Multimap<K, W> rightSide = multimapFromIterator(((ControlPairDataSet) rightDataSet).source); return new ControlPairDataSet(Iterators.concat(Iterators.transform(source, new Function<Tuple2<K, V>, Iterable<Tuple2<K, Tuple2<V, Optional<W>>>>>() { @Nullable//from ww w . j av a 2 s . c o m @Override public Iterable<Tuple2<K, Tuple2<V, Optional<W>>>> apply(@Nullable Tuple2<K, V> t) { assert t != null : "T cannot be null"; List<Tuple2<K, Tuple2<V, Optional<W>>>> result = new ArrayList<>(); K key = t._1(); V value = t._2(); if (rightSide.containsKey(key)) { for (W rightValue : rightSide.get(key)) { result.add(new Tuple2<>(key, new Tuple2<>(value, Optional.of(rightValue)))); } } else result.add(new Tuple2<>(key, new Tuple2<>(value, Optional.<W>empty()))); return result; } }))); }
From source file:com.splicemachine.derby.stream.control.ControlPairDataSet.java
License:Apache License
@Override public <W> PairDataSet<K, Tuple2<Optional<V>, W>> hashRightOuterJoin(PairDataSet<K, W> rightDataSet) { // Materializes the left side final Multimap<K, V> leftSide = multimapFromIterator(source); return new ControlPairDataSet(Iterators.transform(((ControlPairDataSet<K, W>) rightDataSet).source, new Function<Tuple2<K, W>, Iterator<Tuple2<K, Tuple2<Optional<V>, W>>>>() { @Nullable//from w ww .j ava2 s.c om @Override public Iterator<Tuple2<K, Tuple2<Optional<V>, W>>> apply(@Nullable Tuple2<K, W> t) { assert t != null : "t cannot be null!"; List<Tuple2<K, Tuple2<Optional<V>, W>>> result = new ArrayList<>(); K key = t._1(); W value = t._2(); if (leftSide.containsKey(key)) { for (V leftValue : leftSide.get(key)) { result.add(new Tuple2<>(key, new Tuple2<>(Optional.of(leftValue), value))); } } else result.add(new Tuple2<>(key, new Tuple2<>(Optional.<V>absent(), value))); return result.iterator(); } })); }