forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-1110] Started implementing the JoinOperatorBase.
Implemented JoinOperatorBase and test cases.
- Loading branch information
1 parent
77ac6c0
commit 471f340
Showing
9 changed files
with
355 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
...k-core/src/test/java/org/apache/flink/api/common/operators/base/JoinOperatorBaseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http:https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.flink.api.common.operators.base; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
import org.apache.flink.api.common.functions.FlatJoinFunction; | ||
import org.apache.flink.api.common.functions.RichFlatJoinFunction; | ||
import org.apache.flink.api.common.functions.util.RuntimeUDFContext; | ||
import org.apache.flink.api.common.operators.BinaryOperatorInformation; | ||
import org.apache.flink.api.common.typeinfo.BasicTypeInfo; | ||
import org.apache.flink.configuration.Configuration; | ||
import org.apache.flink.util.Collector; | ||
import org.junit.Test; | ||
|
||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
@SuppressWarnings("serial") | ||
public class JoinOperatorBaseTest implements Serializable { | ||
|
||
@Test | ||
public void testJoinPlain(){ | ||
final FlatJoinFunction<String, String, Integer> joiner = new FlatJoinFunction<String, String, Integer>() { | ||
|
||
@Override | ||
public void join(String first, String second, Collector<Integer> out) throws Exception { | ||
out.collect(first.length()); | ||
out.collect(second.length()); | ||
} | ||
}; | ||
|
||
@SuppressWarnings({ "rawtypes", "unchecked" }) | ||
JoinOperatorBase<String, String, Integer, | ||
FlatJoinFunction<String, String,Integer> > base = new JoinOperatorBase(joiner, | ||
new BinaryOperatorInformation(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO, | ||
BasicTypeInfo.INT_TYPE_INFO), new int[0], new int[0], "TestJoiner"); | ||
|
||
List<String> inputData1 = new ArrayList<String>(Arrays.asList("foo", "bar", "foobar")); | ||
List<String> inputData2 = new ArrayList<String>(Arrays.asList("foobar", "foo")); | ||
List<Integer> expected = new ArrayList<Integer>(Arrays.asList(3, 3, 6 ,6)); | ||
|
||
try { | ||
List<Integer> result = base.executeOnCollections(inputData1, inputData2, null); | ||
|
||
assertEquals(expected, result); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
fail(e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testJoinRich(){ | ||
final AtomicBoolean opened = new AtomicBoolean(false); | ||
final AtomicBoolean closed = new AtomicBoolean(false); | ||
final String taskName = "Test rich join function"; | ||
|
||
final RichFlatJoinFunction<String, String, Integer> joiner = new RichFlatJoinFunction<String, String, Integer>() { | ||
@Override | ||
public void open(Configuration parameters) throws Exception { | ||
opened.compareAndSet(false, true); | ||
assertEquals(0, getRuntimeContext().getIndexOfThisSubtask()); | ||
assertEquals(1, getRuntimeContext().getNumberOfParallelSubtasks()); | ||
} | ||
|
||
@Override | ||
public void close() throws Exception{ | ||
closed.compareAndSet(false, true); | ||
} | ||
|
||
@Override | ||
public void join(String first, String second, Collector<Integer> out) throws Exception { | ||
out.collect(first.length()); | ||
out.collect(second.length()); | ||
} | ||
}; | ||
|
||
JoinOperatorBase<String, String, Integer, | ||
RichFlatJoinFunction<String, String, Integer>> base = new JoinOperatorBase<String, String, Integer, | ||
RichFlatJoinFunction<String, String, Integer>>(joiner, new BinaryOperatorInformation<String, String, | ||
Integer>(BasicTypeInfo.STRING_TYPE_INFO, BasicTypeInfo.STRING_TYPE_INFO, | ||
BasicTypeInfo.INT_TYPE_INFO), new int[0], new int[0], taskName); | ||
|
||
final List<String> inputData1 = new ArrayList<String>(Arrays.asList("foo", "bar", "foobar")); | ||
final List<String> inputData2 = new ArrayList<String>(Arrays.asList("foobar", "foo")); | ||
final List<Integer> expected = new ArrayList<Integer>(Arrays.asList(3, 3, 6, 6)); | ||
|
||
|
||
try { | ||
List<Integer> result = base.executeOnCollections(inputData1, inputData2, new RuntimeUDFContext(taskName, | ||
1, 0)); | ||
|
||
assertEquals(expected, result); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
fail(e.getMessage()); | ||
} | ||
|
||
assertTrue(opened.get()); | ||
assertTrue(closed.get()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.