I am using MATCH_RECOGNIZE for pattern matching in events, I am trying to find average usage less than 60 withing 10 seconds interval, the issue here is that in result i am only seeing only 2 result (till the marked position in the data bellow) not sure why further data is not processed or there is some problem with my query.
CREATE TABLE CPU_IN_TIMEBASED (
hostname STRING,
cpu STRING,
usage DOUBLE,
occurred_at BIGINT,
time_ltz AS TO_TIMESTAMP_LTZ(occurred_at, 3),
WATERMARK FOR time_ltz AS time_ltz - INTERVAL '5' SECONDS
) WITH (
'connector' = 'kafka',
'properties.bootstrap.servers' = 'localhost:9092',
'topic' = 'cpu_load_timebased',
'value.format' = 'json',
'properties.group.id' = 'testGroup',
'scan.startup.mode' = 'earliest-offset'
);
SELECT * FROM CPU_IN_TIMEBASED
MATCH_RECOGNIZE (
PARTITION BY hostname
ORDER BY time_ltz
MEASURES
FIRST(A.time_ltz) as start_tstamp,
LAST(A.time_ltz) as end_tstamp,
AVG(A.usage) as avgUsage,
A.cpu as brain,
A.occurred_at as ts
AFTER MATCH SKIP PAST LAST ROW
PATTERN (A+ B) WITHIN INTERVAL '5' SECOND
DEFINE
A AS AVG(A.usage) < 60
) MR;
{"hostname":"one","cpu":"cpu1","usage":95,"occurred_at":1691645762224} x
{"hostname":"one","cpu":"cpu1","usage":35,"occurred_at":1691645764078} -
{"hostname":"one","cpu":"cpu1","usage":63,"occurred_at":1691645765122} |
{"hostname":"one","cpu":"cpu1","usage":24,"occurred_at":1691645766158} | 1st match
{"hostname":"one","cpu":"cpu1","usage":86,"occurred_at":1691645767188} |
{"hostname":"one","cpu":"cpu1","usage":82,"occurred_at":1691645768286} -
{"hostname":"one","cpu":"cpu1","usage":73,"occurred_at":1691645769315} x
{"hostname":"one","cpu":"cpu1","usage":23,"occurred_at":1691645770335} - skipped?
{"hostname":"one","cpu":"cpu1","usage":37,"occurred_at":1691645771365} - 2nd match
{"hostname":"one","cpu":"cpu1","usage":84,"occurred_at":1691645772383} result till 2nd match
{"hostname":"one","cpu":"cpu1","usage":39,"occurred_at":1691645773408}
{"hostname":"one","cpu":"cpu1","usage":18,"occurred_at":1691645774428}
{"hostname":"one","cpu":"cpu1","usage":77,"occurred_at":1691645775459}
{"hostname":"one","cpu":"cpu1","usage":91,"occurred_at":1691645776478}
{"hostname":"one","cpu":"cpu1","usage":35,"occurred_at":1691645777498}
{"hostname":"one","cpu":"cpu1","usage":28,"occurred_at":1691645778532}
{"hostname":"one","cpu":"cpu1","usage":41,"occurred_at":1691645779674}
{"hostname":"one","cpu":"cpu1","usage":50,"occurred_at":1691645780703}
{"hostname":"one","cpu":"cpu1","usage":81,"occurred_at":1691645781723}
{"hostname":"one","cpu":"cpu1","usage":20,"occurred_at":1691645782755}
{"hostname":"one","cpu":"cpu1","usage":35,"occurred_at":1691645783774}
{"hostname":"one","cpu":"cpu1","usage":43,"occurred_at":1691645784794}
{"hostname":"one","cpu":"cpu1","usage":22,"occurred_at":1691645785812}
{"hostname":"one","cpu":"cpu1","usage":37,"occurred_at":1691645786831}
{"hostname":"one","cpu":"cpu1","usage":64,"occurred_at":1691645787861}
Result SS: Result of the query
I am not sure how does it works but not able to trace it