Esper:EPL 查询中的链接属性访问和方法调用

发布于 2024-10-16 04:35:02 字数 851 浏览 3 评论 0原文

我目前正在努力让一些 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南风几经秋 2024-10-23 04:35:02

解决方案实际上简单明了(但有点难看):使用括号,就像在其他地方当某些内容可能不明确时所做的那样。因此,为了使第一个查询工作,请像这样编写:

select (a.center).distance(b.center) as delta
from pattern [
    every-distinct(a.id, b.id) (
        a=org.example.PositionEvent -> b=org.example.PositionEvent
    )
]

在这种情况下,通过添加括号,它实际上看起来更具可读性。

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:

select (a.center).distance(b.center) as delta
from pattern [
    every-distinct(a.id, b.id) (
        a=org.example.PositionEvent -> b=org.example.PositionEvent
    )
]

In this case, it actually looks even slightly more readable with the added parentheses.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文