如何在EPL Online Tryout中使用事件自带的ESPER时间戳
Absolutely, you can use your event's built-in timestamp field as Esper's event time without relying on manual time offsets like t.plus(10 seconds)—here's a step-by-step guide to set this up correctly in the EPL Online Tryout:
Step 1: Define the SensorVal Event Schema
First, you need to register your event type so Esper knows how to parse your input data. You can do this directly in the EPL editor with a create schema statement:
create schema SensorVal( id int, timestamp long, temp_livingroom double, temp_bedroom double, temp_garden double, humidity_garden double );
Step 2: Tie Esper's Event Time to Your Timestamp Field
To tell Esper to use the timestamp field from your events as the official event time (instead of processing time or manual adjustments), you have two straightforward options:
Option A: Annotate the Schema
Modify your schema to mark the timestamp field as the event time source using the @eventtimestamp annotation. This makes it the default for all statements using this schema:
create schema SensorVal( id int, timestamp long @eventtimestamp, temp_livingroom double, temp_bedroom double, temp_garden double, humidity_garden double );
Option B: Explicitly Reference the Timestamp in Your EPL
If you prefer not to modify the schema, you can explicitly link your field to Esper's event time in individual statements. For example, when using a time-based window:
select * from SensorVal#ext_timed(timestamp, 30 seconds) where temp_livingroom > 20;
The #ext_timed clause tells Esper to use the timestamp field to manage the 30-second window, no manual offsets required.
Step 3: Use Your Existing Event Data Directly as Input
Yes, your current SensorVal event format works perfectly in the EPL Online Tryout's "Send Events" tab. Just paste each event line into the input area—Esper will parse them correctly as long as they match the schema you defined.
For example, you can send these events (either one at a time or in bulk):
SensorVal={id=1, timestamp=1521044250000, temp_livingroom=15, temp_bedroom=15, temp_garden=10, humidity_garden=50} SensorVal={id=1, timestamp=1521044260000, temp_livingroom=20, temp_bedroom=15, temp_garden=15, humidity_garden=30}
Step 4: Validate Rules Against Your Test Cases
Since you have test cases stored in your database where rules should trigger, export those test events in the same SensorVal format, send them through the tryout, and verify your rules fire as expected. Using the event's native timestamp ensures Esper processes the events in the exact order and timeline of your test data, no manual time tweaking needed.
Quick Notes
- Ensure your
timestampvalues are in milliseconds (your example uses Unix time in ms, which is Esper's default expected format for event timestamps). - When using time-based operations (like windows or patterns), Esper will automatically use your event's timestamp to position events correctly in time, so you don't have to adjust timestamps manually.
内容的提问来源于stack exchange,提问作者peggers

