Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
doujutun3207
flink
提交
3fc96cd1
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,发现更多精彩内容 >>
未验证
提交
3fc96cd1
编写于
7月 02, 2017
作者:
D
Dian Fu
提交者:
Dawid Wysakowicz
7月 05, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[FLINK-7061] [cep] Fix quantifier range starting from 0
This closes #4242
上级
3096bd03
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
63 addition
and
2 deletion
+63
-2
flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
...p/src/main/java/org/apache/flink/cep/pattern/Pattern.java
+1
-0
flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Quantifier.java
...rc/main/java/org/apache/flink/cep/pattern/Quantifier.java
+1
-2
flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/nfa/TimesRangeITCase.java
.../test/java/org/apache/flink/cep/nfa/TimesRangeITCase.java
+51
-0
flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/pattern/PatternTest.java
...c/test/java/org/apache/flink/cep/pattern/PatternTest.java
+10
-0
未找到文件。
flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Pattern.java
浏览文件 @
3fc96cd1
...
...
@@ -368,6 +368,7 @@ public class Pattern<T, F extends T> {
this
.
quantifier
=
Quantifier
.
times
(
quantifier
.
getConsumingStrategy
());
if
(
from
==
0
)
{
this
.
quantifier
.
optional
();
from
=
1
;
}
this
.
times
=
Times
.
of
(
from
,
to
);
return
this
;
...
...
flink-libraries/flink-cep/src/main/java/org/apache/flink/cep/pattern/Quantifier.java
浏览文件 @
3fc96cd1
...
...
@@ -153,9 +153,8 @@ public class Quantifier {
private
final
int
to
;
private
Times
(
int
from
,
int
to
)
{
Preconditions
.
checkArgument
(
from
>
=
0
,
"The from should be a non-negative number greater than or equal to
0."
);
Preconditions
.
checkArgument
(
from
>
0
,
"The from should be a positive number greater than
0."
);
Preconditions
.
checkArgument
(
to
>=
from
,
"The to should be a number greater than or equal to from: "
+
from
+
"."
);
Preconditions
.
checkArgument
(
from
!=
to
||
from
!=
0
,
"The from and to should not be both equal to 0."
);
this
.
from
=
from
;
this
.
to
=
to
;
}
...
...
flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/nfa/TimesRangeITCase.java
浏览文件 @
3fc96cd1
...
...
@@ -91,6 +91,57 @@ public class TimesRangeITCase extends TestLogger {
));
}
@Test
public
void
testTimesRangeFromZero
()
{
List
<
StreamRecord
<
Event
>>
inputEvents
=
new
ArrayList
<>();
Event
startEvent
=
new
Event
(
40
,
"c"
,
1.0
);
Event
middleEvent1
=
new
Event
(
41
,
"a"
,
2.0
);
Event
middleEvent2
=
new
Event
(
42
,
"a"
,
3.0
);
Event
middleEvent3
=
new
Event
(
43
,
"a"
,
4.0
);
Event
end1
=
new
Event
(
44
,
"b"
,
5.0
);
inputEvents
.
add
(
new
StreamRecord
<>(
startEvent
,
1
));
inputEvents
.
add
(
new
StreamRecord
<>(
middleEvent1
,
2
));
inputEvents
.
add
(
new
StreamRecord
<>(
middleEvent2
,
3
));
inputEvents
.
add
(
new
StreamRecord
<>(
middleEvent3
,
4
));
inputEvents
.
add
(
new
StreamRecord
<>(
end1
,
6
));
Pattern
<
Event
,
?>
pattern
=
Pattern
.<
Event
>
begin
(
"start"
).
where
(
new
SimpleCondition
<
Event
>()
{
private
static
final
long
serialVersionUID
=
5726188262756267490L
;
@Override
public
boolean
filter
(
Event
value
)
throws
Exception
{
return
value
.
getName
().
equals
(
"c"
);
}
}).
next
(
"middle"
).
where
(
new
SimpleCondition
<
Event
>()
{
private
static
final
long
serialVersionUID
=
5726188262756267490L
;
@Override
public
boolean
filter
(
Event
value
)
throws
Exception
{
return
value
.
getName
().
equals
(
"a"
);
}
}).
times
(
0
,
2
).
allowCombinations
().
followedBy
(
"end1"
).
where
(
new
SimpleCondition
<
Event
>()
{
private
static
final
long
serialVersionUID
=
5726188262756267490L
;
@Override
public
boolean
filter
(
Event
value
)
throws
Exception
{
return
value
.
getName
().
equals
(
"b"
);
}
});
NFA
<
Event
>
nfa
=
NFACompiler
.
compile
(
pattern
,
Event
.
createTypeSerializer
(),
false
);
final
List
<
List
<
Event
>>
resultingPatterns
=
feedNFA
(
inputEvents
,
nfa
);
compareMaps
(
resultingPatterns
,
Lists
.<
List
<
Event
>>
newArrayList
(
Lists
.
newArrayList
(
startEvent
,
middleEvent1
,
middleEvent2
,
end1
),
Lists
.
newArrayList
(
startEvent
,
middleEvent1
,
middleEvent3
,
end1
),
Lists
.
newArrayList
(
startEvent
,
middleEvent1
,
end1
),
Lists
.
newArrayList
(
startEvent
,
end1
)
));
}
@Test
public
void
testTimesRangeNonStrict
()
{
List
<
StreamRecord
<
Event
>>
inputEvents
=
new
ArrayList
<>();
...
...
flink-libraries/flink-cep/src/test/java/org/apache/flink/cep/pattern/PatternTest.java
浏览文件 @
3fc96cd1
...
...
@@ -195,6 +195,16 @@ public class PatternTest extends TestLogger {
assertEquals
(
previous2
.
getName
(),
"start"
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testPatternTimesNegativeTimes
()
throws
Exception
{
Pattern
.
begin
(
"start"
).
where
(
dummyCondition
()).
times
(-
1
);
}
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
testPatternTimesNegativeFrom
()
throws
Exception
{
Pattern
.
begin
(
"start"
).
where
(
dummyCondition
()).
times
(-
1
,
2
);
}
@Test
(
expected
=
MalformedPatternException
.
class
)
public
void
testPatternCanHaveQuantifierSpecifiedOnce1
()
throws
Exception
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录