Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
93354e92
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,发现更多精彩内容 >>
提交
93354e92
编写于
7月 14, 2014
作者:
G
gaborhermann
提交者:
Stephan Ewen
8月 18, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[streaming] Started implementing FlatStreamTask
上级
486d7e0c
变更
15
显示空白变更内容
内联
并排
Showing
15 changed file
with
279 addition
and
209 deletion
+279
-209
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/FlatStreamRecord.java
.../java/eu/stratosphere/streaming/api/FlatStreamRecord.java
+52
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamSink.java
...c/main/java/eu/stratosphere/streaming/api/StreamSink.java
+39
-39
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamSource.java
...main/java/eu/stratosphere/streaming/api/StreamSource.java
+73
-72
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamTask.java
...c/main/java/eu/stratosphere/streaming/api/StreamTask.java
+10
-7
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/DefaultSinkInvokable.java
...osphere/streaming/api/invokable/DefaultSinkInvokable.java
+6
-8
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/DefaultSourceInvokable.java
...phere/streaming/api/invokable/DefaultSourceInvokable.java
+10
-10
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/DefaultTaskInvokable.java
...osphere/streaming/api/invokable/DefaultTaskInvokable.java
+5
-8
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/StreamInvokable.java
...stratosphere/streaming/api/invokable/StreamInvokable.java
+26
-0
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/UserSinkInvokable.java
...ratosphere/streaming/api/invokable/UserSinkInvokable.java
+1
-3
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/UserSourceInvokable.java
...tosphere/streaming/api/invokable/UserSourceInvokable.java
+4
-4
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/UserTaskInvokable.java
...ratosphere/streaming/api/invokable/UserTaskInvokable.java
+5
-5
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/test/QuerySourceInvokable.java
.../eu/stratosphere/streaming/test/QuerySourceInvokable.java
+8
-8
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/test/TestSinkInvokable.java
...ava/eu/stratosphere/streaming/test/TestSinkInvokable.java
+7
-9
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/test/TestSourceInvokable.java
...a/eu/stratosphere/streaming/test/TestSourceInvokable.java
+11
-12
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/test/TestTaskInvokable.java
...ava/eu/stratosphere/streaming/test/TestTaskInvokable.java
+22
-24
未找到文件。
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/FlatStreamRecord.java
0 → 100644
浏览文件 @
93354e92
package
eu.stratosphere.streaming.api
;
import
eu.stratosphere.types.LongValue
;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.types.Value
;
public
class
FlatStreamRecord
{
private
long
id
;
private
Record
record
;
private
int
numberOfFields
;
public
FlatStreamRecord
()
{
id
=
94
;
}
public
FlatStreamRecord
(
int
numberOfFields
)
{
this
();
this
.
numberOfFields
=
numberOfFields
;
record
=
new
Record
(
numberOfFields
+
1
);
LongValue
idValue
=
new
LongValue
(
id
);
record
.
addField
(
idValue
);
}
public
FlatStreamRecord
(
Record
record
)
{
this
();
this
.
numberOfFields
=
record
.
getNumFields
();
this
.
record
=
record
;
LongValue
idValue
=
new
LongValue
(
id
);
record
.
addField
(
idValue
);
}
public
int
getNumFields
()
{
return
this
.
numberOfFields
;
}
public
boolean
getFieldInto
(
int
fieldNum
,
Value
target
)
{
return
record
.
getFieldInto
(
fieldNum
,
target
);
}
public
<
T
extends
Value
>
T
getField
(
final
int
fieldNum
,
final
Class
<
T
>
type
)
{
return
record
.
getField
(
fieldNum
,
type
);
}
//TODO: set to private or package private, this cannot be seen from outside!
public
Record
getRecord
()
{
return
this
.
record
;
}
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamSink.java
浏览文件 @
93354e92
...
...
@@ -68,7 +68,7 @@ public class StreamSink extends AbstractOutputTask {
for
(
RecordReader
<
Record
>
input
:
inputs
)
{
if
(
input
.
hasNext
())
{
hasInput
=
true
;
userFunction
.
invoke
(
input
.
next
(),
input
);
userFunction
.
invoke
(
input
.
next
()
);
}
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamSource.java
浏览文件 @
93354e92
...
...
@@ -56,8 +56,7 @@ public class StreamSource extends AbstractInputTask<RandIS> {
private
void
setConfigInputs
()
{
numberOfOutputs
=
getTaskConfiguration
().
getInteger
(
"numberOfOutputs"
,
0
);
numberOfOutputs
=
getTaskConfiguration
().
getInteger
(
"numberOfOutputs"
,
0
);
Class
<?
extends
ChannelSelector
<
Record
>>
partitioner
;
for
(
int
i
=
1
;
i
<=
numberOfOutputs
;
i
++)
{
...
...
@@ -73,12 +72,18 @@ public class StreamSource extends AbstractInputTask<RandIS> {
}
}
for
(
ChannelSelector
<
Record
>
outputPartitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
this
,
Record
.
class
,
outputPartitioner
));
}
Class
<?
extends
UserSourceInvokable
>
userFunctionClass
;
userFunctionClass
=
getTaskConfiguration
().
getClass
(
"userfunction"
,
DefaultSourceInvokable
.
class
,
UserSourceInvokable
.
class
);
try
{
userFunction
=
userFunctionClass
.
newInstance
();
userFunction
.
declareOutputs
(
outputs
);
}
catch
(
Exception
e
)
{
}
...
...
@@ -88,18 +93,14 @@ public class StreamSource extends AbstractInputTask<RandIS> {
@Override
public
void
registerInputOutput
()
{
setConfigInputs
();
for
(
ChannelSelector
<
Record
>
partitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
this
,
Record
.
class
,
partitioner
));
}
}
@Override
public
void
invoke
()
throws
Exception
{
for
(
RecordWriter
<
Record
>
output
:
outputs
)
{
userFunction
.
invoke
(
output
);
}
userFunction
.
invoke
();
}
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/StreamTask.java
浏览文件 @
93354e92
...
...
@@ -26,6 +26,7 @@ import eu.stratosphere.streaming.api.invokable.DefaultTaskInvokable;
import
eu.stratosphere.streaming.api.invokable.UserTaskInvokable
;
import
eu.stratosphere.streaming.partitioner.DefaultPartitioner
;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.types.StringValue
;
public
class
StreamTask
extends
AbstractTask
{
...
...
@@ -67,11 +68,17 @@ public class StreamTask extends AbstractTask {
}
}
for
(
ChannelSelector
<
Record
>
outputPartitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
this
,
Record
.
class
,
outputPartitioner
));
}
Class
<?
extends
UserTaskInvokable
>
userFunctionClass
;
userFunctionClass
=
getTaskConfiguration
().
getClass
(
"userfunction"
,
DefaultTaskInvokable
.
class
,
UserTaskInvokable
.
class
);
try
{
userFunction
=
userFunctionClass
.
newInstance
();
userFunction
.
declareOutputs
(
outputs
);
}
catch
(
Exception
e
)
{
}
...
...
@@ -80,12 +87,10 @@ public class StreamTask extends AbstractTask {
@Override
public
void
registerInputOutput
()
{
setConfigInputs
();
for
(
ChannelSelector
<
Record
>
partitioner
:
partitioners
)
{
outputs
.
add
(
new
RecordWriter
<
Record
>(
this
,
Record
.
class
,
partitioner
));
}
Record
r
=
new
Record
();
r
.
addField
(
new
StringValue
(
""
));
}
// TODO: Performance with multiple outputs
@Override
public
void
invoke
()
throws
Exception
{
boolean
hasInput
=
true
;
...
...
@@ -94,9 +99,7 @@ public class StreamTask extends AbstractTask {
for
(
RecordReader
<
Record
>
input
:
inputs
)
{
if
(
input
.
hasNext
())
{
hasInput
=
true
;
for
(
RecordWriter
<
Record
>
output
:
outputs
)
{
userFunction
.
invoke
(
input
.
next
(),
output
);
}
userFunction
.
invoke
(
new
FlatStreamRecord
(
input
.
next
()));
}
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/DefaultSinkInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,15 +15,13 @@
package
eu.stratosphere.streaming.api.invokable
;
import
eu.stratosphere.nephele.io.RecordReader
;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.types.StringValue
;
public
class
DefaultSinkInvokable
implements
UserSinkInvokable
{
@Override
public
void
invoke
(
Record
record
,
RecordReader
<
Record
>
input
)
throws
Exception
{
public
void
invoke
(
Record
record
)
throws
Exception
{
StringValue
value
=
new
StringValue
(
""
);
record
.
getFieldInto
(
0
,
value
);
System
.
out
.
println
(
value
.
getValue
());
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/DefaultSourceInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,19 +15,19 @@
package
eu.stratosphere.streaming.api.invokable
;
import
eu.stratosphere.
nephele.io.RecordWriter
;
import
eu.stratosphere.
streaming.api.FlatStreamRecord
;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.types.StringValue
;
public
class
DefaultSourceInvokable
implement
s
UserSourceInvokable
{
public
class
DefaultSourceInvokable
extend
s
UserSourceInvokable
{
private
String
motto
=
"Stratosphere -- Big Data looks tiny from here"
;
private
String
[]
mottoArray
=
motto
.
split
(
" "
);
@Override
public
void
invoke
(
RecordWriter
<
Record
>
output
)
throws
Exception
{
public
void
invoke
(
)
throws
Exception
{
for
(
CharSequence
word
:
mottoArray
)
{
output
.
emit
(
new
Record
(
new
StringValue
(
word
)));
emit
(
new
FlatStreamRecord
(
new
Record
(
new
StringValue
(
word
)
)));
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/DefaultTaskInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,15 +15,12 @@
package
eu.stratosphere.streaming.api.invokable
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.streaming.api.FlatStreamRecord
;
public
class
DefaultTaskInvokable
implement
s
UserTaskInvokable
{
public
class
DefaultTaskInvokable
extend
s
UserTaskInvokable
{
@Override
public
void
invoke
(
Record
record
,
RecordWriter
<
Record
>
output
)
throws
Exception
{
output
.
emit
(
record
);
public
void
invoke
(
FlatStreamRecord
streamRecord
)
throws
Exception
{
emit
(
streamRecord
);
}
}
\ No newline at end of file
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/StreamInvokable.java
0 → 100644
浏览文件 @
93354e92
package
eu.stratosphere.streaming.api.invokable
;
import
java.util.List
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.streaming.api.FlatStreamRecord
;
import
eu.stratosphere.types.Record
;
public
abstract
class
StreamInvokable
{
private
List
<
RecordWriter
<
Record
>>
outputs
;
public
final
void
declareOutputs
(
List
<
RecordWriter
<
Record
>>
outputs
)
{
this
.
outputs
=
outputs
;
}
public
final
void
emit
(
FlatStreamRecord
streamRecord
)
{
for
(
RecordWriter
<
Record
>
output
:
outputs
)
{
try
{
output
.
emit
(
streamRecord
.
getRecord
());
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"Emit error"
);
}
}
}
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/UserSinkInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,11 +15,9 @@
package
eu.stratosphere.streaming.api.invokable
;
import
eu.stratosphere.nephele.io.RecordReader
;
import
eu.stratosphere.types.Record
;
public
interface
UserSinkInvokable
{
public
void
invoke
(
Record
record
,
RecordReader
<
Record
>
input
)
throws
Exception
;
public
void
invoke
(
Record
record
)
throws
Exception
;
}
\ No newline at end of file
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/UserSourceInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,9 +15,9 @@
package
eu.stratosphere.streaming.api.invokable
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.types.Record
;
public
abstract
class
UserSourceInvokable
extends
StreamInvokable
{
public
interface
UserSourceInvokable
{
public
void
invoke
(
RecordWriter
<
Record
>
output
)
throws
Exception
;
public
void
invoke
()
throws
Exception
{
}
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/invokable/UserTaskInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,11 +15,11 @@
package
eu.stratosphere.streaming.api.invokable
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.streaming.api.FlatStreamRecord
;
public
interface
UserTask
Invokable
{
public
abstract
class
UserTaskInvokable
extends
Stream
Invokable
{
public
void
invoke
(
Record
record
,
RecordWriter
<
Record
>
output
)
throws
Exception
;
public
void
invoke
(
FlatStreamRecord
record
)
throws
Exception
{
}
}
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/test/QuerySourceInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,16 +15,16 @@
package
eu.stratosphere.streaming.test
;
import
eu.stratosphere.
nephele.io.RecordWriter
;
import
eu.stratosphere.
streaming.api.FlatStreamRecord
;
import
eu.stratosphere.streaming.api.invokable.UserSourceInvokable
;
import
eu.stratosphere.types.IntValue
;
import
eu.stratosphere.types.LongValue
;
import
eu.stratosphere.types.Record
;
public
class
QuerySourceInvokable
implement
s
UserSourceInvokable
{
public
class
QuerySourceInvokable
extend
s
UserSourceInvokable
{
@Override
public
void
invoke
(
RecordWriter
<
Record
>
output
)
throws
Exception
{
public
void
invoke
()
throws
Exception
{
for
(
int
i
=
0
;
i
<
5
;
i
++)
{
Record
record1
=
new
Record
(
3
);
record1
.
setField
(
0
,
new
IntValue
(
5
));
...
...
@@ -34,10 +34,10 @@ public class QuerySourceInvokable implements UserSourceInvokable {
Record
record2
=
new
Record
(
3
);
record2
.
setField
(
0
,
new
IntValue
(
4
));
record2
.
setField
(
1
,
new
LongValue
(
510
));
record
1
.
setField
(
2
,
new
LongValue
(
100
));
record
2
.
setField
(
2
,
new
LongValue
(
100
));
output
.
emit
(
record1
);
output
.
emit
(
record2
);
emit
(
new
FlatStreamRecord
(
record1
)
);
emit
(
new
FlatStreamRecord
(
record2
)
);
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/test/TestSinkInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,7 +15,6 @@
package
eu.stratosphere.streaming.test
;
import
eu.stratosphere.nephele.io.RecordReader
;
import
eu.stratosphere.streaming.api.invokable.UserSinkInvokable
;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.types.StringValue
;
...
...
@@ -23,8 +22,7 @@ import eu.stratosphere.types.StringValue;
public
class
TestSinkInvokable
implements
UserSinkInvokable
{
@Override
public
void
invoke
(
Record
record
,
RecordReader
<
Record
>
input
)
throws
Exception
{
public
void
invoke
(
Record
record
)
throws
Exception
{
StringValue
value
=
new
StringValue
(
""
);
record
.
getFieldInto
(
0
,
value
);
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/test/TestSourceInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,17 +15,16 @@
package
eu.stratosphere.streaming.test
;
import
eu.stratosphere.nephele.io.RecordWriter
;
import
eu.stratosphere.streaming.api.FlatStreamRecord
;
import
eu.stratosphere.streaming.api.invokable.UserSourceInvokable
;
import
eu.stratosphere.types.IntValue
;
import
eu.stratosphere.types.LongValue
;
import
eu.stratosphere.types.Record
;
public
class
TestSourceInvokable
implement
s
UserSourceInvokable
{
public
class
TestSourceInvokable
extend
s
UserSourceInvokable
{
@Override
public
void
invoke
(
RecordWriter
<
Record
>
output
)
throws
Exception
{
public
void
invoke
()
throws
Exception
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
Record
record1
=
new
Record
(
2
);
record1
.
setField
(
0
,
new
IntValue
(
5
));
...
...
@@ -33,8 +32,8 @@ public class TestSourceInvokable implements UserSourceInvokable {
Record
record2
=
new
Record
(
2
);
record2
.
setField
(
0
,
new
IntValue
(
4
));
record2
.
setField
(
1
,
new
LongValue
(
500
));
output
.
emit
(
record1
);
output
.
emit
(
record2
);
emit
(
new
FlatStreamRecord
(
record1
)
);
emit
(
new
FlatStreamRecord
(
record2
)
);
}
}
...
...
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/test/TestTaskInvokable.java
浏览文件 @
93354e92
...
...
@@ -15,7 +15,7 @@
package
eu.stratosphere.streaming.test
;
import
eu.stratosphere.
nephele.io.RecordWriter
;
import
eu.stratosphere.
streaming.api.FlatStreamRecord
;
import
eu.stratosphere.streaming.api.invokable.UserTaskInvokable
;
import
eu.stratosphere.streaming.test.cellinfo.WorkerEngineExact
;
import
eu.stratosphere.types.IntValue
;
...
...
@@ -23,13 +23,12 @@ import eu.stratosphere.types.LongValue;
import
eu.stratosphere.types.Record
;
import
eu.stratosphere.types.StringValue
;
public
class
TestTaskInvokable
implement
s
UserTaskInvokable
{
public
class
TestTaskInvokable
extend
s
UserTaskInvokable
{
private
WorkerEngineExact
engine
=
new
WorkerEngineExact
(
10
,
1000
,
0
);
@Override
public
void
invoke
(
Record
record
,
RecordWriter
<
Record
>
output
)
throws
Exception
{
public
void
invoke
(
FlatStreamRecord
record
)
throws
Exception
{
IntValue
value1
=
new
IntValue
(
0
);
record
.
getFieldInto
(
0
,
value1
);
LongValue
value2
=
new
LongValue
(
0
);
...
...
@@ -38,15 +37,14 @@ public class TestTaskInvokable implements UserTaskInvokable {
// INFO
if
(
record
.
getNumFields
()
==
2
)
{
engine
.
put
(
value1
.
getValue
(),
value2
.
getValue
());
output
.
emit
(
new
Record
(
new
StringValue
(
value1
+
" "
+
value2
)));
emit
(
new
FlatStreamRecord
(
new
Record
(
new
StringValue
(
value1
+
" "
+
value2
)
)));
}
// QUERY
else
if
(
record
.
getNumFields
()
==
3
)
{
LongValue
value3
=
new
LongValue
(
0
);
record
.
getFieldInto
(
2
,
value3
);
output
.
emit
(
new
Record
(
new
StringValue
(
String
.
valueOf
(
engine
.
get
(
value2
.
getValue
(),
value3
.
getValue
(),
value1
.
getValue
())))));
emit
(
new
FlatStreamRecord
(
new
Record
(
new
StringValue
(
String
.
valueOf
(
engine
.
get
(
value2
.
getValue
(),
value3
.
getValue
(),
value1
.
getValue
()))))));
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录