Java Code Examples for org.apache.flink.api.common.typeutils.TypePairComparator#setReference()
The following examples show how to use
org.apache.flink.api.common.typeutils.TypePairComparator#setReference() .
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: TuplePairComparatorTestBase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testEqualityWithReference() { try { TypePairComparator<T, R> comparator = getComparator(true); Tuple2<T[], R[]> data = getSortedData(); for (int x = 0; x < data.f0.length; x++) { comparator.setReference(data.f0[x]); assertTrue(comparator.equalToReference(data.f1[x])); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
Example 2
Source File: TuplePairComparatorTestBase.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
protected void testGreatSmallAscDescWithReference(boolean ascending) { try { Tuple2<T[], R[]> data = getSortedData(); TypePairComparator<T, R> comparator = getComparator(ascending); //compares every element in high with every element in low for (int x = 0; x < data.f0.length - 1; x++) { for (int y = x + 1; y < data.f1.length; y++) { comparator.setReference(data.f0[x]); if (ascending) { assertTrue(comparator.compareToReference(data.f1[y]) > 0); } else { assertTrue(comparator.compareToReference(data.f1[y]) < 0); } } } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
Example 3
Source File: TuplePairComparatorTestBase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testEqualityWithReference() { try { TypePairComparator<T, R> comparator = getComparator(true); Tuple2<T[], R[]> data = getSortedData(); for (int x = 0; x < data.f0.length; x++) { comparator.setReference(data.f0[x]); assertTrue(comparator.equalToReference(data.f1[x])); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
Example 4
Source File: TuplePairComparatorTestBase.java From flink with Apache License 2.0 | 6 votes |
protected void testGreatSmallAscDescWithReference(boolean ascending) { try { Tuple2<T[], R[]> data = getSortedData(); TypePairComparator<T, R> comparator = getComparator(ascending); //compares every element in high with every element in low for (int x = 0; x < data.f0.length - 1; x++) { for (int y = x + 1; y < data.f1.length; y++) { comparator.setReference(data.f0[x]); if (ascending) { assertTrue(comparator.compareToReference(data.f1[y]) > 0); } else { assertTrue(comparator.compareToReference(data.f1[y]) < 0); } } } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
Example 5
Source File: TuplePairComparatorTestBase.java From flink with Apache License 2.0 | 6 votes |
@Test public void testEqualityWithReference() { try { TypePairComparator<T, R> comparator = getComparator(true); Tuple2<T[], R[]> data = getSortedData(); for (int x = 0; x < data.f0.length; x++) { comparator.setReference(data.f0[x]); assertTrue(comparator.equalToReference(data.f1[x])); } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
Example 6
Source File: TuplePairComparatorTestBase.java From flink with Apache License 2.0 | 6 votes |
protected void testGreatSmallAscDescWithReference(boolean ascending) { try { Tuple2<T[], R[]> data = getSortedData(); TypePairComparator<T, R> comparator = getComparator(ascending); //compares every element in high with every element in low for (int x = 0; x < data.f0.length - 1; x++) { for (int y = x + 1; y < data.f1.length; y++) { comparator.setReference(data.f0[x]); if (ascending) { assertTrue(comparator.compareToReference(data.f1[y]) > 0); } else { assertTrue(comparator.compareToReference(data.f1[y]) < 0); } } } } catch (Exception e) { System.err.println(e.getMessage()); e.printStackTrace(); fail("Exception in test: " + e.getMessage()); } }
Example 7
Source File: AbstractMergeInnerJoinIterator.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
/** * Calls the <code>JoinFunction#join()</code> method for all two key-value pairs that share the same key and come * from different inputs. The output of the <code>join()</code> method is forwarded. * <p> * This method first zig-zags between the two sorted inputs in order to find a common * key, and then calls the join stub with the cross product of the values. * * @throws Exception Forwards all exceptions from the user code and the I/O system. * @see org.apache.flink.runtime.operators.util.JoinTaskIterator#callWithNextKey(org.apache.flink.api.common.functions.FlatJoinFunction, org.apache.flink.util.Collector) */ @Override public boolean callWithNextKey(final FlatJoinFunction<T1, T2, O> joinFunction, final Collector<O> collector) throws Exception { if (!this.iterator1.nextKey() || !this.iterator2.nextKey()) { // consume all remaining keys (hack to prevent remaining inputs during iterations, lets get rid of this soon) while (this.iterator1.nextKey()) { } while (this.iterator2.nextKey()) { } return false; } final TypePairComparator<T1, T2> comparator = this.pairComparator; comparator.setReference(this.iterator1.getCurrent()); T2 current2 = this.iterator2.getCurrent(); // zig zag while (true) { // determine the relation between the (possibly composite) keys final int comp = comparator.compareToReference(current2); if (comp == 0) { break; } if (comp < 0) { if (!this.iterator2.nextKey()) { return false; } current2 = this.iterator2.getCurrent(); } else { if (!this.iterator1.nextKey()) { return false; } comparator.setReference(this.iterator1.getCurrent()); } } // here, we have a common key! call the join function with the cross product of the // values final Iterator<T1> values1 = this.iterator1.getValues(); final Iterator<T2> values2 = this.iterator2.getValues(); crossMatchingGroup(values1, values2, joinFunction, collector); return true; }
Example 8
Source File: AbstractMergeInnerJoinIterator.java From flink with Apache License 2.0 | 4 votes |
/** * Calls the <code>JoinFunction#join()</code> method for all two key-value pairs that share the same key and come * from different inputs. The output of the <code>join()</code> method is forwarded. * <p> * This method first zig-zags between the two sorted inputs in order to find a common * key, and then calls the join stub with the cross product of the values. * * @throws Exception Forwards all exceptions from the user code and the I/O system. * @see org.apache.flink.runtime.operators.util.JoinTaskIterator#callWithNextKey(org.apache.flink.api.common.functions.FlatJoinFunction, org.apache.flink.util.Collector) */ @Override public boolean callWithNextKey(final FlatJoinFunction<T1, T2, O> joinFunction, final Collector<O> collector) throws Exception { if (!this.iterator1.nextKey() || !this.iterator2.nextKey()) { // consume all remaining keys (hack to prevent remaining inputs during iterations, lets get rid of this soon) while (this.iterator1.nextKey()) { } while (this.iterator2.nextKey()) { } return false; } final TypePairComparator<T1, T2> comparator = this.pairComparator; comparator.setReference(this.iterator1.getCurrent()); T2 current2 = this.iterator2.getCurrent(); // zig zag while (true) { // determine the relation between the (possibly composite) keys final int comp = comparator.compareToReference(current2); if (comp == 0) { break; } if (comp < 0) { if (!this.iterator2.nextKey()) { return false; } current2 = this.iterator2.getCurrent(); } else { if (!this.iterator1.nextKey()) { return false; } comparator.setReference(this.iterator1.getCurrent()); } } // here, we have a common key! call the join function with the cross product of the // values final Iterator<T1> values1 = this.iterator1.getValues(); final Iterator<T2> values2 = this.iterator2.getValues(); crossMatchingGroup(values1, values2, joinFunction, collector); return true; }
Example 9
Source File: AbstractMergeInnerJoinIterator.java From flink with Apache License 2.0 | 4 votes |
/** * Calls the <code>JoinFunction#join()</code> method for all two key-value pairs that share the same key and come * from different inputs. The output of the <code>join()</code> method is forwarded. * <p> * This method first zig-zags between the two sorted inputs in order to find a common * key, and then calls the join stub with the cross product of the values. * * @throws Exception Forwards all exceptions from the user code and the I/O system. * @see org.apache.flink.runtime.operators.util.JoinTaskIterator#callWithNextKey(org.apache.flink.api.common.functions.FlatJoinFunction, org.apache.flink.util.Collector) */ @Override public boolean callWithNextKey(final FlatJoinFunction<T1, T2, O> joinFunction, final Collector<O> collector) throws Exception { if (!this.iterator1.nextKey() || !this.iterator2.nextKey()) { // consume all remaining keys (hack to prevent remaining inputs during iterations, lets get rid of this soon) while (this.iterator1.nextKey()) { } while (this.iterator2.nextKey()) { } return false; } final TypePairComparator<T1, T2> comparator = this.pairComparator; comparator.setReference(this.iterator1.getCurrent()); T2 current2 = this.iterator2.getCurrent(); // zig zag while (true) { // determine the relation between the (possibly composite) keys final int comp = comparator.compareToReference(current2); if (comp == 0) { break; } if (comp < 0) { if (!this.iterator2.nextKey()) { return false; } current2 = this.iterator2.getCurrent(); } else { if (!this.iterator1.nextKey()) { return false; } comparator.setReference(this.iterator1.getCurrent()); } } // here, we have a common key! call the join function with the cross product of the // values final Iterator<T1> values1 = this.iterator1.getValues(); final Iterator<T2> values2 = this.iterator2.getValues(); crossMatchingGroup(values1, values2, joinFunction, collector); return true; }