Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
114af5a3
F
flink
项目概览
doujutun3207
/
flink
与 Fork 源项目一致
从无法访问的项目Fork
通知
24
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
F
flink
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
114af5a3
编写于
9月 22, 2014
作者:
U
Ufuk Celebi
提交者:
Stephan Ewen
10月 03, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-1110] Add execution on collections for flatMap
上级
fdad5bf8
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
130 addition
and
3 deletion
+130
-3
flink-core/src/main/java/org/apache/flink/api/common/operators/base/FlatMapOperatorBase.java
.../flink/api/common/operators/base/FlatMapOperatorBase.java
+28
-3
flink-core/src/test/java/org/apache/flink/api/common/operators/base/FlatMapOperatorCollectionExecutionTest.java
...perators/base/FlatMapOperatorCollectionExecutionTest.java
+102
-0
未找到文件。
flink-core/src/main/java/org/apache/flink/api/common/operators/base/FlatMapOperatorBase.java
浏览文件 @
114af5a3
...
...
@@ -16,16 +16,20 @@
* limitations under the License.
*/
package
org.apache.flink.api.common.operators.base
;
import
org.apache.flink.api.common.functions.FlatMapFunction
;
import
org.apache.flink.api.common.functions.RuntimeContext
;
import
org.apache.flink.api.common.functions.util.FunctionUtils
;
import
org.apache.flink.api.common.functions.util.ListCollector
;
import
org.apache.flink.api.common.operators.SingleInputOperator
;
import
org.apache.flink.api.common.operators.UnaryOperatorInformation
;
import
org.apache.flink.api.common.operators.util.UserCodeClassWrapper
;
import
org.apache.flink.api.common.operators.util.UserCodeObjectWrapper
;
import
org.apache.flink.api.common.operators.util.UserCodeWrapper
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* @see org.apache.flink.api.common.functions.FlatMapFunction
...
...
@@ -43,4 +47,25 @@ public class FlatMapOperatorBase<IN, OUT, FT extends FlatMapFunction<IN, OUT>> e
public
FlatMapOperatorBase
(
Class
<?
extends
FT
>
udf
,
UnaryOperatorInformation
<
IN
,
OUT
>
operatorInfo
,
String
name
)
{
super
(
new
UserCodeClassWrapper
<
FT
>(
udf
),
operatorInfo
,
name
);
}
// ------------------------------------------------------------------------
@Override
protected
List
<
OUT
>
executeOnCollections
(
List
<
IN
>
input
,
RuntimeContext
ctx
)
throws
Exception
{
FlatMapFunction
<
IN
,
OUT
>
function
=
userFunction
.
getUserCodeObject
();
FunctionUtils
.
setFunctionRuntimeContext
(
function
,
ctx
);
FunctionUtils
.
openFunction
(
function
,
parameters
);
ArrayList
<
OUT
>
result
=
new
ArrayList
<
OUT
>(
input
.
size
());
ListCollector
<
OUT
>
resultCollector
=
new
ListCollector
<
OUT
>(
result
);
for
(
IN
element
:
input
)
{
function
.
flatMap
(
element
,
resultCollector
);
}
FunctionUtils
.
closeFunction
(
function
);
return
result
;
}
}
flink-core/src/test/java/org/apache/flink/api/common/operators/base/FlatMapOperatorCollectionExecutionTest.java
0 → 100644
浏览文件 @
114af5a3
/**
* 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://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
org.apache.flink.api.common.functions.FlatMapFunction
;
import
org.apache.flink.api.common.functions.RichFlatMapFunction
;
import
org.apache.flink.api.common.functions.RuntimeContext
;
import
org.apache.flink.api.common.functions.util.RuntimeUDFContext
;
import
org.apache.flink.api.common.operators.UnaryOperatorInformation
;
import
org.apache.flink.api.common.typeinfo.BasicTypeInfo
;
import
org.apache.flink.configuration.Configuration
;
import
org.apache.flink.util.Collector
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
public
class
FlatMapOperatorCollectionExecutionTest
implements
Serializable
{
@Test
public
void
testExecuteOnCollection
()
{
try
{
IdRichFlatMap
<
String
>
udf
=
new
IdRichFlatMap
<
String
>();
testExecuteOnCollection
(
udf
,
Arrays
.
asList
(
"f"
,
"l"
,
"i"
,
"n"
,
"k"
));
Assert
.
assertTrue
(
udf
.
isClosed
);
testExecuteOnCollection
(
new
IdRichFlatMap
<
String
>(),
new
ArrayList
<
String
>());
}
catch
(
Throwable
t
)
{
Assert
.
fail
(
t
.
getMessage
());
}
}
private
void
testExecuteOnCollection
(
FlatMapFunction
<
String
,
String
>
udf
,
List
<
String
>
input
)
throws
Exception
{
// run on collections
final
List
<
String
>
result
=
getTestFlatMapOperator
(
udf
)
.
executeOnCollections
(
input
,
new
RuntimeUDFContext
(
"Test UDF"
,
4
,
0
));
Assert
.
assertEquals
(
input
.
size
(),
result
.
size
());
for
(
int
i
=
0
;
i
<
input
.
size
();
i
++)
{
Assert
.
assertEquals
(
input
.
get
(
i
),
result
.
get
(
i
));
}
}
public
class
IdRichFlatMap
<
IN
>
extends
RichFlatMapFunction
<
IN
,
IN
>
{
private
boolean
isOpened
=
false
;
private
boolean
isClosed
=
false
;
@Override
public
void
open
(
Configuration
parameters
)
throws
Exception
{
isOpened
=
true
;
RuntimeContext
ctx
=
getRuntimeContext
();
Assert
.
assertEquals
(
"Test UDF"
,
ctx
.
getTaskName
());
Assert
.
assertEquals
(
4
,
ctx
.
getNumberOfParallelSubtasks
());
Assert
.
assertEquals
(
0
,
ctx
.
getIndexOfThisSubtask
());
}
@Override
public
void
flatMap
(
IN
value
,
Collector
<
IN
>
out
)
throws
Exception
{
Assert
.
assertTrue
(
isOpened
);
Assert
.
assertFalse
(
isClosed
);
out
.
collect
(
value
);
}
@Override
public
void
close
()
throws
Exception
{
isClosed
=
true
;
}
}
private
FlatMapOperatorBase
<
String
,
String
,
FlatMapFunction
<
String
,
String
>>
getTestFlatMapOperator
(
FlatMapFunction
<
String
,
String
>
udf
)
{
UnaryOperatorInformation
<
String
,
String
>
typeInfo
=
new
UnaryOperatorInformation
<
String
,
String
>(
BasicTypeInfo
.
STRING_TYPE_INFO
,
BasicTypeInfo
.
STRING_TYPE_INFO
);
return
new
FlatMapOperatorBase
<
String
,
String
,
FlatMapFunction
<
String
,
String
>>(
udf
,
typeInfo
,
"flatMap on Collections"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录