Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
cc7d7ef2
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,发现更多精彩内容 >>
提交
cc7d7ef2
编写于
7月 14, 2014
作者:
G
gyfora
提交者:
Stephan Ewen
8月 18, 2014
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[streaming] StreamRecord copy updated
上级
b22a9e92
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
55 addition
and
20 deletion
+55
-20
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamrecord/StreamRecord.java
...stratosphere/streaming/api/streamrecord/StreamRecord.java
+27
-8
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/streamrecord/StreamRecordTest.java
...tosphere/streaming/api/streamrecord/StreamRecordTest.java
+28
-12
未找到文件。
flink-addons/flink-streaming/src/main/java/eu/stratosphere/streaming/api/streamrecord/StreamRecord.java
浏览文件 @
cc7d7ef2
...
...
@@ -95,6 +95,13 @@ public class StreamRecord implements IOReadableWritable, Serializable {
tupleBatch
=
new
ArrayList
<
Tuple
>();
}
public
StreamRecord
(
int
numOfFields
,
int
batchSize
)
{
this
.
numOfFields
=
numOfFields
;
this
.
numOfTuples
=
0
;
tupleBatch
=
new
ArrayList
<
Tuple
>(
batchSize
);
}
/**
* Creates a new batch of records containing only the given Tuple as element
...
...
@@ -457,7 +464,7 @@ public class StreamRecord implements IOReadableWritable, Serializable {
*/
public
void
setInteger
(
int
fieldNumber
,
Integer
i
)
throws
NoSuchFieldException
{
setInteger
(
0
,
i
);
setInteger
(
0
,
fieldNumber
,
i
);
}
/**
...
...
@@ -662,13 +669,8 @@ public class StreamRecord implements IOReadableWritable, Serializable {
}
}
/**
* Creates a deep copy of the StreamRecord
*
* @return Copy of the StreamRecord
*
*/
public
StreamRecord
copy
()
{
public
StreamRecord
copySerialized
()
{
ByteArrayOutputStream
buff
=
new
ByteArrayOutputStream
();
DataOutputStream
out
=
new
DataOutputStream
(
buff
);
...
...
@@ -684,6 +686,23 @@ public class StreamRecord implements IOReadableWritable, Serializable {
return
newRecord
;
}
/**
* Creates a deep copy of the StreamRecord
*
* @return Copy of the StreamRecord
*
*/
public
StreamRecord
copy
()
{
StreamRecord
newRecord
=
new
StreamRecord
(
numOfFields
,
numOfTuples
);
newRecord
.
uid
=
new
StringValue
(
uid
.
getValue
());
for
(
Tuple
tuple:
tupleBatch
){
newRecord
.
tupleBatch
.
add
(
StreamRecord
.
copyTuple
(
tuple
));
}
return
newRecord
;
}
/**
* Creates deep copy of Tuple
...
...
flink-addons/flink-streaming/src/test/java/eu/stratosphere/streaming/api/streamrecord/StreamRecordTest.java
浏览文件 @
cc7d7ef2
...
...
@@ -42,8 +42,11 @@ public class StreamRecordTest {
assertEquals
(
"Stratosphere"
,
record
.
getString
(
0
));
assertEquals
((
Integer
)
1
,
record
.
getInteger
(
1
));
record
.
setField
(
1
,
"Big Data"
);
assertEquals
(
"Big Data"
,
record
.
getString
(
1
));
record
.
setString
(
0
,
"Big Data"
);
record
.
setInteger
(
1
,
2
);
assertEquals
(
"Big Data"
,
record
.
getString
(
0
));
assertEquals
((
Integer
)
2
,
record
.
getInteger
(
1
));
record
.
setTuple
(
new
Tuple2
<
String
,
Long
>(
"Big Data looks tiny from here."
,
2L
));
assertEquals
(
2
,
record
.
getNumOfFields
());
...
...
@@ -66,9 +69,9 @@ public class StreamRecordTest {
assertEquals
(
"Big Data looks tiny from here."
,
tuple
.
getField
(
0
));
assertEquals
((
Double
)
2.5
,
tuple
.
getField
(
1
));
record
.
setDouble
(
1
,
3.3
);
record
.
setDouble
(
1
,
3.3
);
assertEquals
(
"Big Data looks tiny from here."
,
tuple
.
getField
(
0
));
assertEquals
((
Double
)
2.5
,
tuple
.
getField
(
1
));
}
...
...
@@ -107,6 +110,16 @@ public class StreamRecordTest {
assertFalse
(
a
.
getId
().
equals
(
b
.
getId
()));
assertFalse
(
a
.
getField
(
0
).
equals
(
b
.
getField
(
0
)));
StreamRecord
c
=
new
StreamRecord
(
new
Tuple1
<
String
>(
"Big"
));
long
t
=
System
.
nanoTime
();
c
.
copySerialized
();
System
.
out
.
println
(
"Serialized copy:\t"
+
(
System
.
nanoTime
()
-
t
));
t
=
System
.
nanoTime
();
c
.
copy
();
System
.
out
.
println
(
"New copy:\t"
+
(
System
.
nanoTime
()
-
t
));
}
@Test
...
...
@@ -163,20 +176,23 @@ public class StreamRecordTest {
}
}
@Test
public
void
tupleCopyTest
(){
Tuple2
<
String
,
Integer
>
t1
=
new
Tuple2
<
String
,
Integer
>(
"a"
,
1
);
@SuppressWarnings
(
"unchecked"
)
Tuple2
<
String
,
Integer
>
t2
=
(
Tuple2
<
String
,
Integer
>)
StreamRecord
.
copyTuple
(
t1
);
public
void
tupleCopyTest
()
{
Tuple2
<
String
,
Integer
>
t1
=
new
Tuple2
<
String
,
Integer
>(
"a"
,
1
);
Tuple2
t2
=
(
Tuple2
)
StreamRecord
.
copyTuple
(
t1
);
assertEquals
(
"a"
,
t2
.
getField
(
0
));
assertEquals
(
1
,
t2
.
getField
(
1
));
t1
.
setField
(
2
,
1
);
assertEquals
(
1
,
t2
.
getField
(
1
));
assertEquals
(
2
,
t1
.
getField
(
1
));
assertEquals
(
t1
.
getField
(
0
).
getClass
(),
t2
.
getField
(
0
).
getClass
());
assertEquals
(
t1
.
getField
(
1
).
getClass
(),
t2
.
getField
(
1
).
getClass
());
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录