Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
bb71b239
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,发现更多精彩内容 >>
提交
bb71b239
编写于
9月 22, 2014
作者:
S
Stephan Ewen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-1110] Fix MapOperator execution and added simple test
上级
d10d59eb
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
111 addition
and
1 deletion
+111
-1
flink-core/src/main/java/org/apache/flink/api/common/operators/base/MapOperatorBase.java
...ache/flink/api/common/operators/base/MapOperatorBase.java
+1
-1
flink-core/src/test/java/org/apache/flink/api/common/operators/base/MapOperatorTest.java
...ache/flink/api/common/operators/base/MapOperatorTest.java
+110
-0
未找到文件。
flink-core/src/main/java/org/apache/flink/api/common/operators/base/MapOperatorBase.java
浏览文件 @
bb71b239
...
@@ -58,8 +58,8 @@ public class MapOperatorBase<IN, OUT, FT extends MapFunction<IN, OUT>> extends S
...
@@ -58,8 +58,8 @@ public class MapOperatorBase<IN, OUT, FT extends MapFunction<IN, OUT>> extends S
protected
List
<
OUT
>
executeOnCollections
(
List
<
IN
>
inputData
,
RuntimeContext
ctx
)
throws
Exception
{
protected
List
<
OUT
>
executeOnCollections
(
List
<
IN
>
inputData
,
RuntimeContext
ctx
)
throws
Exception
{
MapFunction
<
IN
,
OUT
>
function
=
this
.
userFunction
.
getUserCodeObject
();
MapFunction
<
IN
,
OUT
>
function
=
this
.
userFunction
.
getUserCodeObject
();
FunctionUtils
.
openFunction
(
function
,
this
.
parameters
);
FunctionUtils
.
setFunctionRuntimeContext
(
function
,
ctx
);
FunctionUtils
.
setFunctionRuntimeContext
(
function
,
ctx
);
FunctionUtils
.
openFunction
(
function
,
this
.
parameters
);
ArrayList
<
OUT
>
result
=
new
ArrayList
<
OUT
>(
inputData
.
size
());
ArrayList
<
OUT
>
result
=
new
ArrayList
<
OUT
>(
inputData
.
size
());
for
(
IN
element
:
inputData
)
{
for
(
IN
element
:
inputData
)
{
...
...
flink-core/src/test/java/org/apache/flink/api/common/operators/base/MapOperatorTest.java
0 → 100644
浏览文件 @
bb71b239
/**
* 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
static
org
.
junit
.
Assert
.*;
import
static
java
.
util
.
Arrays
.
asList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
org.apache.flink.api.common.functions.MapFunction
;
import
org.apache.flink.api.common.functions.RichMapFunction
;
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.operators.base.MapOperatorBase
;
import
org.apache.flink.api.common.typeinfo.BasicTypeInfo
;
import
org.apache.flink.configuration.Configuration
;
import
org.junit.Test
;
@SuppressWarnings
(
"serial"
)
public
class
MapOperatorTest
implements
java
.
io
.
Serializable
{
@Test
public
void
testMapPlain
()
{
try
{
final
MapFunction
<
String
,
Integer
>
parser
=
new
MapFunction
<
String
,
Integer
>()
{
@Override
public
Integer
map
(
String
value
)
{
return
Integer
.
parseInt
(
value
);
}
};
MapOperatorBase
<
String
,
Integer
,
MapFunction
<
String
,
Integer
>>
op
=
new
MapOperatorBase
<
String
,
Integer
,
MapFunction
<
String
,
Integer
>>(
parser
,
new
UnaryOperatorInformation
<
String
,
Integer
>(
BasicTypeInfo
.
STRING_TYPE_INFO
,
BasicTypeInfo
.
INT_TYPE_INFO
),
"TestMapper"
);
List
<
String
>
input
=
new
ArrayList
<
String
>(
asList
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
));
List
<
Integer
>
result
=
op
.
executeOnCollections
(
input
,
null
);
assertEquals
(
asList
(
1
,
2
,
3
,
4
,
5
,
6
),
result
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
fail
(
e
.
getMessage
());
}
}
@Test
public
void
testMapWithRuntimeContext
()
{
try
{
final
String
taskName
=
"Test Task"
;
final
AtomicBoolean
opened
=
new
AtomicBoolean
();
final
AtomicBoolean
closed
=
new
AtomicBoolean
();
final
MapFunction
<
String
,
Integer
>
parser
=
new
RichMapFunction
<
String
,
Integer
>()
{
@Override
public
void
open
(
Configuration
parameters
)
throws
Exception
{
opened
.
set
(
true
);
RuntimeContext
ctx
=
getRuntimeContext
();
assertEquals
(
0
,
ctx
.
getIndexOfThisSubtask
());
assertEquals
(
1
,
ctx
.
getNumberOfParallelSubtasks
());
assertEquals
(
taskName
,
ctx
.
getTaskName
());
}
@Override
public
Integer
map
(
String
value
)
{
return
Integer
.
parseInt
(
value
);
}
@Override
public
void
close
()
throws
Exception
{
closed
.
set
(
true
);
}
};
MapOperatorBase
<
String
,
Integer
,
MapFunction
<
String
,
Integer
>>
op
=
new
MapOperatorBase
<
String
,
Integer
,
MapFunction
<
String
,
Integer
>>(
parser
,
new
UnaryOperatorInformation
<
String
,
Integer
>(
BasicTypeInfo
.
STRING_TYPE_INFO
,
BasicTypeInfo
.
INT_TYPE_INFO
),
taskName
);
List
<
String
>
input
=
new
ArrayList
<
String
>(
asList
(
"1"
,
"2"
,
"3"
,
"4"
,
"5"
,
"6"
));
List
<
Integer
>
result
=
op
.
executeOnCollections
(
input
,
new
RuntimeUDFContext
(
taskName
,
1
,
0
));
assertEquals
(
asList
(
1
,
2
,
3
,
4
,
5
,
6
),
result
);
assertTrue
(
opened
.
get
());
assertTrue
(
closed
.
get
());
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
fail
(
e
.
getMessage
());
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录