Esper:EPL 查询中的链接属性访问和方法调用
我目前正在努力让一些 Esper EPL 查询正常工作。查询如下所示:
select a.center.distance(b.center) as delta
from pattern [
every-distinct(a.id, b.id) (
a=org.example.PositionEvent -> b=org.example.PositionEvent
)
]
当我尝试通过 EPAdministrator.createEPL()
将其编译为 EPLStatement
时,它会抛出以下异常:
com.espertech.esper.client.EPStatementException:启动语句时出错:无法按名称“a.center”加载类,请检查导入
如果我修改事件类和查询以像这样读取,
select a.distance(b) as delta
from pattern [
every-distinct(a.id, b.id) (
a=org.example.PositionEvent -> b=org.example.PositionEvent
)
]
它编译得很好。 Esper 似乎将 a.center.distance(...)
解释为类名,后跟静态方法调用,而它解释 a.distance(...)
作为对对象 a
的方法调用。
如何让 Esper 按预期解释我的原始查询(即作为属性访问,然后是方法调用)?
I am currently struggling to get some Esper EPL queries to work. The queries are looking like this:
select a.center.distance(b.center) as delta
from pattern [
every-distinct(a.id, b.id) (
a=org.example.PositionEvent -> b=org.example.PositionEvent
)
]
When I try to compile this into an EPLStatement
via EPAdministrator.createEPL()
it throws the following exception:
com.espertech.esper.client.EPStatementException: Error starting statement: Could not load class by name 'a.center', please check imports
If I modify the event classes and the query to read like this
select a.distance(b) as delta
from pattern [
every-distinct(a.id, b.id) (
a=org.example.PositionEvent -> b=org.example.PositionEvent
)
]
it compiles just fine. Esper seems to interpret a.center.distance(...)
as a class name followed by a static method invocation, while it interprets a.distance(...)
as a method call on the object a
.
How can I make Esper interpret my original query as intended (i.e. as a property access followed by a method invocation)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决方案实际上简单明了(但有点难看):使用括号,就像在其他地方当某些内容可能不明确时所做的那样。因此,为了使第一个查询工作,请像这样编写:
在这种情况下,通过添加括号,它实际上看起来更具可读性。
The solution is actually simple and straightforward (yet a little bit ugly): Use parentheses, just like you do everywhere else when something could be ambiguous. So to make that first query work, write it like this:
In this case, it actually looks even slightly more readable with the added parentheses.