Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
48512386
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,发现更多精彩内容 >>
提交
48512386
编写于
7月 14, 2014
作者:
G
ghermann
提交者:
Stephan Ewen
8月 18, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[streaming] Tested BatchReduce
上级
8da89a74
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
143 addition
and
44 deletion
+143
-44
flink-addons/flink-streaming/src/main/java/eu/stratosphere/api/datastream/DataStream.java
.../main/java/eu/stratosphere/api/datastream/DataStream.java
+1
-1
flink-addons/flink-streaming/src/main/java/eu/stratosphere/api/datastream/FileSourceFunction.java
...va/eu/stratosphere/api/datastream/FileSourceFunction.java
+14
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamComponentHelper.java
.../streaming/api/streamcomponent/StreamComponentHelper.java
+9
-10
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/examples/wordcount/WordCountCounter.java
...sphere/streaming/examples/wordcount/WordCountCounter.java
+10
-10
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/examples/wordcount/WordCountSplitter.java
...phere/streaming/examples/wordcount/WordCountSplitter.java
+25
-23
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/BatchReduceTest.java
...t/java/eu/stratosphere/streaming/api/BatchReduceTest.java
+84
-0
未找到文件。
flink-addons/flink-streaming/src/main/java/eu/stratosphere/api/datastream/DataStream.java
浏览文件 @
48512386
...
@@ -94,7 +94,7 @@ public class DataStream<T extends Tuple> {
...
@@ -94,7 +94,7 @@ public class DataStream<T extends Tuple> {
return
context
.
addMapFunction
(
this
,
mapper
);
return
context
.
addMapFunction
(
this
,
mapper
);
}
}
public
<
R
extends
Tuple
>
DataStream
<
R
>
flatMap
(
GroupReduceFunction
<
T
,
R
>
reducer
)
{
public
<
R
extends
Tuple
>
DataStream
<
R
>
batchReduce
(
GroupReduceFunction
<
T
,
R
>
reducer
)
{
return
context
.
addBatchReduceFunction
(
this
,
reducer
);
return
context
.
addBatchReduceFunction
(
this
,
reducer
);
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/api/datastream/FileSourceFunction.java
浏览文件 @
48512386
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed 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
eu.stratosphere.api.datastream
;
package
eu.stratosphere.api.datastream
;
import
java.io.BufferedReader
;
import
java.io.BufferedReader
;
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamcomponent/StreamComponentHelper.java
浏览文件 @
48512386
...
@@ -117,9 +117,7 @@ public final class StreamComponentHelper<T extends AbstractInvokable> {
...
@@ -117,9 +117,7 @@ public final class StreamComponentHelper<T extends AbstractInvokable> {
try
{
try
{
ObjectInputStream
in
=
new
ObjectInputStream
(
new
ByteArrayInputStream
(
operatorBytes
));
ObjectInputStream
in
=
new
ObjectInputStream
(
new
ByteArrayInputStream
(
operatorBytes
));
if
(
operatorName
.
equals
(
"flatMap"
))
{
if
(
operatorName
.
equals
(
"flatMap"
))
{
FlatMapFunction
<
Tuple
,
Tuple
>
f
=
(
FlatMapFunction
<
Tuple
,
Tuple
>)
in
.
readObject
();
FlatMapFunction
<
Tuple
,
Tuple
>
f
=
(
FlatMapFunction
<
Tuple
,
Tuple
>)
in
.
readObject
();
inTupleTypeInfo
=
(
TupleTypeInfo
)
TypeExtractor
.
createTypeInfo
(
inTupleTypeInfo
=
(
TupleTypeInfo
)
TypeExtractor
.
createTypeInfo
(
...
@@ -152,16 +150,17 @@ public final class StreamComponentHelper<T extends AbstractInvokable> {
...
@@ -152,16 +150,17 @@ public final class StreamComponentHelper<T extends AbstractInvokable> {
}
else
if
(
operatorName
.
equals
(
"batchReduce"
))
{
}
else
if
(
operatorName
.
equals
(
"batchReduce"
))
{
GroupReduceFunction
<
Tuple
,
Tuple
>
f
=
(
GroupReduceFunction
<
Tuple
,
Tuple
>)
in
.
readObject
();
GroupReduceFunction
<
Tuple
,
Tuple
>
f
=
(
GroupReduceFunction
<
Tuple
,
Tuple
>)
in
.
readObject
();
inTupleTypeInfo
=
(
TupleTypeInfo
)
TypeExtractor
.
createTypeInfo
(
GroupReduceFunction
.
class
,
inTupleTypeInfo
=
(
TupleTypeInfo
)
TypeExtractor
.
createTypeInfo
(
f
.
getClass
(),
0
,
null
,
null
);
GroupReduceFunction
.
class
,
f
.
getClass
(),
0
,
null
,
null
);
inTupleSerializer
=
inTupleTypeInfo
.
createSerializer
();
inTupleSerializer
=
inTupleTypeInfo
.
createSerializer
();
inDeserializationDelegate
=
new
DeserializationDelegate
<
Tuple
>(
inTupleSerializer
);
inDeserializationDelegate
=
new
DeserializationDelegate
<
Tuple
>(
inTupleSerializer
);
outTupleTypeInfo
=
(
TupleTypeInfo
)
TypeExtractor
.
createTypeInfo
(
GroupReduceFunction
.
class
,
outTupleTypeInfo
=
(
TupleTypeInfo
)
TypeExtractor
.
createTypeInfo
(
f
.
getClass
(),
1
,
null
,
null
);
GroupReduceFunction
.
class
,
f
.
getClass
(),
1
,
null
,
null
);
outTupleSerializer
=
outTupleTypeInfo
.
createSerializer
();
outTupleSerializer
=
outTupleTypeInfo
.
createSerializer
();
outSerializationDelegate
=
new
SerializationDelegate
<
Tuple
>(
outTupleSerializer
);
outSerializationDelegate
=
new
SerializationDelegate
<
Tuple
>(
outTupleSerializer
);
...
@@ -170,8 +169,8 @@ public final class StreamComponentHelper<T extends AbstractInvokable> {
...
@@ -170,8 +169,8 @@ public final class StreamComponentHelper<T extends AbstractInvokable> {
SinkFunction
<
Tuple
>
f
=
(
SinkFunction
<
Tuple
>)
in
.
readObject
();
SinkFunction
<
Tuple
>
f
=
(
SinkFunction
<
Tuple
>)
in
.
readObject
();
inTupleTypeInfo
=
(
TupleTypeInfo
)
TypeExtractor
.
createTypeInfo
(
inTupleTypeInfo
=
(
TupleTypeInfo
)
TypeExtractor
.
createTypeInfo
(
SinkFunction
.
class
,
SinkFunction
.
class
,
f
.
getClass
(),
0
,
null
,
null
);
f
.
getClass
(),
0
,
null
,
null
);
inTupleSerializer
=
inTupleTypeInfo
.
createSerializer
();
inTupleSerializer
=
inTupleTypeInfo
.
createSerializer
();
inDeserializationDelegate
=
new
DeserializationDelegate
<
Tuple
>(
inTupleSerializer
);
inDeserializationDelegate
=
new
DeserializationDelegate
<
Tuple
>(
inTupleSerializer
);
...
@@ -195,7 +194,7 @@ public final class StreamComponentHelper<T extends AbstractInvokable> {
...
@@ -195,7 +194,7 @@ public final class StreamComponentHelper<T extends AbstractInvokable> {
}
}
}
}
public
AbstractRecordReader
getConfigInputs
(
T
taskBase
,
Configuration
taskConfiguration
)
public
AbstractRecordReader
getConfigInputs
(
T
taskBase
,
Configuration
taskConfiguration
)
throws
StreamComponentException
{
throws
StreamComponentException
{
int
numberOfInputs
=
taskConfiguration
.
getInteger
(
"numberOfInputs"
,
0
);
int
numberOfInputs
=
taskConfiguration
.
getInteger
(
"numberOfInputs"
,
0
);
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/examples/wordcount/WordCountCounter.java
浏览文件 @
48512386
...
@@ -18,22 +18,22 @@ package eu.stratosphere.streaming.examples.wordcount;
...
@@ -18,22 +18,22 @@ package eu.stratosphere.streaming.examples.wordcount;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
eu.stratosphere.api.java.functions.MapFunction
;
import
eu.stratosphere.api.java.tuple.Tuple1
;
import
eu.stratosphere.api.java.tuple.Tuple2
;
import
eu.stratosphere.api.java.tuple.Tuple2
;
import
eu.stratosphere.streaming.api.invokable.UserTaskInvokable
;
import
eu.stratosphere.streaming.api.streamrecord.StreamRecord
;
public
class
WordCountCounter
extends
UserTaskInvokable
{
public
class
WordCountCounter
extends
MapFunction
<
Tuple1
<
String
>,
Tuple2
<
String
,
Integer
>>
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
private
Map
<
String
,
Integer
>
wordCounts
=
new
HashMap
<
String
,
Integer
>();
private
Map
<
String
,
Integer
>
wordCounts
=
new
HashMap
<
String
,
Integer
>();
private
String
word
=
""
;
private
String
word
=
""
;
private
Integer
count
=
0
;
private
Integer
count
=
0
;
private
StreamRecord
outRecord
=
new
StreamRecord
(
new
Tuple2
<
String
,
Integer
>()
);
private
Tuple2
<
String
,
Integer
>
outTuple
=
new
Tuple2
<
String
,
Integer
>(
);
@Override
@Override
public
void
invoke
(
StreamRecord
record
)
throws
Exception
{
public
Tuple2
<
String
,
Integer
>
map
(
Tuple1
<
String
>
inTuple
)
throws
Exception
{
word
=
record
.
getString
(
0
)
;
word
=
inTuple
.
f0
;
if
(
wordCounts
.
containsKey
(
word
))
{
if
(
wordCounts
.
containsKey
(
word
))
{
count
=
wordCounts
.
get
(
word
)
+
1
;
count
=
wordCounts
.
get
(
word
)
+
1
;
...
@@ -43,10 +43,10 @@ public class WordCountCounter extends UserTaskInvokable {
...
@@ -43,10 +43,10 @@ public class WordCountCounter extends UserTaskInvokable {
wordCounts
.
put
(
word
,
1
);
wordCounts
.
put
(
word
,
1
);
}
}
out
Record
.
setString
(
0
,
word
)
;
out
Tuple
.
f0
=
word
;
out
Record
.
setInteger
(
1
,
count
)
;
out
Tuple
.
f1
=
count
;
emit
(
outRecord
)
;
return
outTuple
;
// performanceCounter.count();
// performanceCounter.count();
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/examples/wordcount/WordCountSplitter.java
浏览文件 @
48512386
...
@@ -15,39 +15,41 @@
...
@@ -15,39 +15,41 @@
package
eu.stratosphere.streaming.examples.wordcount
;
package
eu.stratosphere.streaming.examples.wordcount
;
import
eu.stratosphere.api.java.functions.FlatMapFunction
;
import
eu.stratosphere.api.java.tuple.Tuple1
;
import
eu.stratosphere.api.java.tuple.Tuple1
;
import
eu.stratosphere.streaming.api.invokable.UserTaskInvokable
;
import
eu.stratosphere.util.Collector
;
import
eu.stratosphere.streaming.api.streamrecord.StreamRecord
;
import
eu.stratosphere.streaming.util.PerformanceCounter
;
import
eu.stratosphere.streaming.util.PerformanceTimer
;
public
class
WordCountSplitter
extends
UserTaskInvokable
{
public
class
WordCountSplitter
extends
FlatMapFunction
<
Tuple1
<
String
>,
Tuple1
<
String
>>
{
private
static
final
long
serialVersionUID
=
1L
;
private
static
final
long
serialVersionUID
=
1L
;
private
String
[]
words
=
new
String
[]
{};
private
String
[]
words
=
new
String
[]
{};
private
StreamRecord
outputRecord
=
new
StreamRecord
(
new
Tuple1
<
String
>());
private
Tuple1
<
String
>
outTuple
=
new
Tuple1
<
String
>();
PerformanceCounter
pCounter
=
new
PerformanceCounter
(
"SplitterEmitCounter"
,
1000
,
1000
,
"/home/strato/stratosphere-distrib/log/counter/Splitter"
+
channelID
);
//TODO move the performance tracked version to a separate package and clean this
PerformanceTimer
pTimer
=
new
PerformanceTimer
(
"SplitterEmitTimer"
,
1000
,
1000
,
true
,
// PerformanceCounter pCounter = new
"/home/strato/stratosphere-distrib/log/timer/Splitter"
+
channelID
);
// PerformanceCounter("SplitterEmitCounter", 1000, 1000,
// "/home/strato/stratosphere-distrib/log/counter/Splitter" + channelID);
// PerformanceTimer pTimer = new PerformanceTimer("SplitterEmitTimer", 1000,
// 1000, true,
// "/home/strato/stratosphere-distrib/log/timer/Splitter" + channelID);
@Override
@Override
public
void
invoke
(
StreamRecord
record
)
throws
Exception
{
public
void
flatMap
(
Tuple1
<
String
>
inTuple
,
Collector
<
Tuple1
<
String
>>
out
)
throws
Exception
{
words
=
record
.
getString
(
0
)
.
split
(
" "
);
words
=
inTuple
.
f0
.
split
(
" "
);
for
(
String
word
:
words
)
{
for
(
String
word
:
words
)
{
out
putRecord
.
setString
(
0
,
word
)
;
out
Tuple
.
f0
=
word
;
pTimer
.
startTimer
();
//
pTimer.startTimer();
emit
(
outputRecord
);
out
.
collect
(
outTuple
);
pTimer
.
stopTimer
();
//
pTimer.stopTimer();
pCounter
.
count
();
//
pCounter.count();
}
}
}
}
@Override
//
@Override
public
String
getResult
()
{
//
public String getResult() {
pCounter
.
writeCSV
();
//
pCounter.writeCSV();
pTimer
.
writeCSV
();
//
pTimer.writeCSV();
return
""
;
//
return "";
}
//
}
}
}
\ No newline at end of file
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/BatchReduceTest.java
0 → 100644
浏览文件 @
48512386
/***********************************************************************************************************************
*
* Copyright (C) 2010-2014 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed 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
eu.stratosphere.streaming.api
;
import
static
org
.
junit
.
Assert
.
fail
;
import
java.util.Iterator
;
import
org.junit.Test
;
import
eu.stratosphere.api.datastream.DataStream
;
import
eu.stratosphere.api.datastream.SinkFunction
;
import
eu.stratosphere.api.datastream.SourceFunction
;
import
eu.stratosphere.api.datastream.StreamExecutionEnvironment
;
import
eu.stratosphere.api.java.functions.FlatMapFunction
;
import
eu.stratosphere.api.java.functions.GroupReduceFunction
;
import
eu.stratosphere.api.java.tuple.Tuple1
;
import
eu.stratosphere.util.Collector
;
public
class
BatchReduceTest
{
public
static
final
class
MyBatchReduce
extends
GroupReduceFunction
<
Tuple1
<
Double
>,
Tuple1
<
Double
>>
{
@Override
public
void
reduce
(
Iterator
<
Tuple1
<
Double
>>
values
,
Collector
<
Tuple1
<
Double
>>
out
)
throws
Exception
{
Double
sum
=
0
.;
Double
count
=
0
.;
while
(
values
.
hasNext
())
{
sum
+=
values
.
next
().
f0
;
count
++;
}
out
.
collect
(
new
Tuple1
<
Double
>(
sum
/
count
));
System
.
out
.
println
(
"batchReduce "
+
sum
);
}
}
public
static
final
class
MySink
extends
SinkFunction
<
Tuple1
<
Double
>>
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
public
void
invoke
(
Tuple1
<
Double
>
tuple
)
{
System
.
out
.
println
(
"AVG: "
+
tuple
);
}
}
public
static
final
class
MySource
extends
SourceFunction
<
Tuple1
<
Double
>>
{
private
static
final
long
serialVersionUID
=
1L
;
@Override
public
void
invoke
(
Collector
<
Tuple1
<
Double
>>
collector
)
{
for
(
Double
i
=
0
.;
i
<
20
;
i
++)
{
collector
.
collect
(
new
Tuple1
<
Double
>(
i
));
}
}
}
@Test
public
void
test
()
throws
Exception
{
StreamExecutionEnvironment
context
=
new
StreamExecutionEnvironment
(
4
);
DataStream
<
Tuple1
<
Double
>>
dataStream0
=
context
.
addSource
(
new
MySource
()).
batchReduce
(
new
MyBatchReduce
()).
addSink
(
new
MySink
());
context
.
execute
();
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录