简体   繁体   English

将文本文件中的数据存储到Esper引擎中以用于EPL

[英]Storing data from text file into Esper engine for use in EPL

I have a text file which has lines in this format: 我有一个文本文件,其中包含以下格式的行:

XYZ 120 
ABC 200 
...

Essentially, one 3 character string and an integer value. 本质上是一个3字符串和一个整数值。 Their format will not change but the value of the integer might depending on the events. 它们的格式不会改变,但是整数的值可能取决于事件。

I would like to store the information from this file into the engine so that I could use it in EPL statements. 我想将此文件中的信息存储到引擎中,以便可以在EPL语句中使用它。 I want to be able to compare the incoming events with my list and act when certain conditions occurs. 我希望能够将传入的事件与我的列表进行比较,并在发生某些情况时采取行动。

That is, every time an events occurs, I check my data to see if its in my list. 也就是说,每次发生事件时,我都会检查我的数据以查看其是否在列表中。 Say an event has code XYZ, I check and see that I have it, I perform operations and then change the value of the XYZ's integer. 假设某个事件的代码为XYZ,我检查并确认代码已存在,然后执行操作,然后更改XYZ整数的值。 Updating the file is not necessary, it's just a mean to feed the data into the engine. 不需要更新文件,这只是将数据输入引擎的一种手段。

I believe there are a few possible ways to go about this but I am not sure how their implementation is to be completed and which is the best practice. 我相信有几种可能的解决方法,但是我不确定如何完成它们的实现以及哪种是最佳实践。

Option 1: Using the method invocation as explained in 选项1:使用方法调用,如

5.14. Accessing Non-Relational Data via Method, Script or UDF Invocation

I followed the instructions about providing the method and the metadata but I am quite confused how to iterate the returned data within the EPL statement? 我遵循了有关提供方法和元数据的说明,但是我很困惑如何在EPL语句中迭代返回的数据? The return of my method is: 我的方法的返回结果是:

Collection<MyStock> stocks 

where MyStock is the [String, Integer] pair. 其中MyStock是[String,Integer]对。

where event.code = stocks.code 

obviously does not work because stocks is a collection 显然不起作用,因为库存是一个集合

So how to iterate through the collection within the EPL? 那么如何遍历EPL中的集合呢?

Option 2: Alternatively, I can probably feed the file into a Map and then save the Map into the engine as a variable? 选项2:或者,我可能可以将文件输入到Map中,然后将Map作为变量保存到引擎中?

I get stuck with the iteration here as well. 在这里,我也陷入了迭代。 I believe I might have missed crucial part in those concepts and I'd like to be pointed at the right direction. 我相信我可能已经错过了那些概念中的关键部分,我想指出正确的方向。 Better yet, a working example of something similar would be nice. 更好的是,一个类似的工作示例会很好。

Possible solution: 可能的解决方案:

@Name('createTable')
create table HolderTable(code string primary key, amount int);

@Name('insertTable')
insert into HolderTable select code, amount from MyStock; 

@Name('compareEventsWithTable')
@Subscriber(className='subscribers.MySubscriber')
on TickEvent as tick
select code, amount from HolderTable
where tick.stockCode = code;

It sounds like you want to collect data and use the collected data in multiple queries. 听起来您想收集数据并在多个查询中使用收集的数据。 You can use a named window or table for that. 您可以为此使用命名窗口或表。

create window StockWindow#unique(stock) (stock string, value double);

insert into StockWindow select stock, value from IncomingEvent;

select MyLib.computeSomething(select window(*) from StockWindow) from StockWindow;

The engine calls the "computeSomething" function provided by class "MyLib" and passes the window contents to that, when StockWindow has a new event entering the window. 当StockWindow有新事件进入窗口时,引擎将调用类“ MyLib”提供的“ computeSomething”函数,并将窗口内容传递给该函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM