我想知道是否可以使用“count”函数或等效函数但指定了参数,只计算特定结果。
所以我想做类似的事情:
select
...
"nbAccel", count(type='c8y_HarshBehavior' and behaviorType = "ACCELERATION")
"nbBraking", count(type='c8y_HarshBehavior' and behaviorType = "BRAKING")
"nbUnknown", count(type='c8y_HarshBehavior' and behaviorType = "UNKNOWN")
from
...
让我告诉你我想要什么。我正在使用EPL Online tool。
以下是我的EPL声明(上面粘贴的部分不起作用):
create schema EventCreated(
source String,
type String,
time Date,
behaviorType String
);
create schema CreateMeasurement(
source String,
type String,
time Date,
fragments Object
);
@Name("no_message_20min")
insert into
EventCreated
select
e.source as source,
"c8y_SilentTracker" as type,
new Date() as time
from pattern [
every e = EventCreated(
type != "c8y_HeartbeatReport" and
type != "c8y_ObdDisconnectionReport" and
type != "c8y_PowerOffReport" and
type != "c8y_SilentTracker")
-> (timer:interval(20 minute) and
not EventCreated(
source = e.source and
type != "c8y_HeartbeatReport"))];
@Name("create_context")
create context Trip
context bySource
partition by source from EventCreated,
context byEvents
start EventCreated(
type = "c8y_ObdConnectionReport" or
type = "c8y_PowerOnReport" or
type = "c8y_FixedReport" or
type = "c8y_HarshBehaviorReport") as startEvent
end EventCreated(
type = "c8y_ObdDisconnectionReport" or
type = "c8y_PowerOffReport" or
type = "c8y_SilentTracker") as endEvent;
@Name("context_end")
context Trip
insert into
CreateMeasurement
select
context.bySource.key1 as source,
"Trip" as type,
e.time as time,
{
"startedBy", context.byEvents.startEvent.type,
"startedAt", context.byEvents.startEvent.time,
"endedBy", e.type,
"endedAt", e.time,
"nbAccel", count(type='c8y_HarshBehavior' and behaviorType = "ACCELERATION"),
"nbBraking", count(type='c8y_HarshBehavior' and behaviorType = "BRAKING"),
"nbUnknown", count(type='c8y_HarshBehavior' and behaviorType = "UNKNOWN")
} as fragments
from
EventCreated e
output
last when terminated;
这是我的时间和事件顺序:
EventCreated = {
source = 'tracker1',
type = 'c8y_ObdConnectionReport',
time = '2016-10-07T10:00:00.000'
}
t = t.plus(5 minutes)
EventCreated = {
source = 'tracker1',
type = 'c8y_HarshBehavior',
time = '2016-10-07 10:05:00.000',
behaviorType = "UNKNOWN"
}
t = t.plus(5 minutes)
EventCreated = {
source = 'tracker1',
type = 'c8y_HarshBehavior',
time = '2016-10-07 10:10:00.000',
behaviorType = "ACCELERATION"
}
t = t.plus(5 minutes)
EventCreated = {
source = 'tracker1',
type = 'c8y_HarshBehavior',
time = '2016-10-07 10:15:00.000',
behaviorType = "BRAKING"
}
t = t.plus(5 minutes)
EventCreated = {
source = 'tracker1',
type = 'c8y_Location',
time='2016-10-07 10:20:00.000'
}
t = t.plus(25 minutes)
EventCreated = {
source = 'tracker1',
type = 'c8y_Location',
time = '2016-10-07 10:45:00.000'
}
t = t.plus(5 minutes)
EventCreated = {
source = 'tracker1',
type = 'c8y_ObdDisconnectionReport',
time = '2016-10-07 10:50:00.000'
}
时间为2016-10-07 10:00:00.000
答案 0 :(得分:0)
好的,我发现如何使用sum函数这样做:
current_timestamp