如何从 Esper EPL 中的查询中检索和分组多列?
How to retrieve and group multiple columns from a query in Esper EPL?
我正在编写查询以获取 inputStream 标题字段的第一个字符,并计算返回的字符类型。
这两个查询单独工作并给我结果数和 sub-stringing 之后的字符数。
"select count(*) as count as character from Data.win:time_batch(5 sec) ";
"select title.substring(0,1) as character from Data.win:time_batch(5 sec) ";
但是当我将它们组合起来并按字符分组时,我在分组时遇到错误。
public String getStatement() {
return "select count(*) as count, title.substring(0,1) as character from
Data.win:time_batch(5 sec) group by character";
}
/**
* Listener method called when Esper has detected a pattern match.
*/
public void update(Map<String, String> eventMap) {
System.out.println(eventMap);
// Titles in the last 5 seconds
String character = (String) eventMap.get("character");
String count = (String) eventMap.get("count");
StringBuilder sb = new StringBuilder();
sb.append("---------------------------------");
sb.append("\n- [MONITOR] Char = " + character + " Count =" + count);
sb.append("\n---------------------------------");
LOG.debug(sb.toString());
}
任何人都可以建议如何对 select 语句中的两个字段进行分组和返回。
EPL 中的 select-子句不全局命名表达式。
为了在 EPL 或全局范围内共享命名表达式,Esper 有表达式(参见 5.2.9)作为示例。
备选方案是:
insert into Character select title.substring(0,1) as character from Data
select count(*) as count, character from Character.win:time_batch(5 sec) group by character
我正在编写查询以获取 inputStream 标题字段的第一个字符,并计算返回的字符类型。
这两个查询单独工作并给我结果数和 sub-stringing 之后的字符数。
"select count(*) as count as character from Data.win:time_batch(5 sec) ";
"select title.substring(0,1) as character from Data.win:time_batch(5 sec) ";
但是当我将它们组合起来并按字符分组时,我在分组时遇到错误。
public String getStatement() {
return "select count(*) as count, title.substring(0,1) as character from
Data.win:time_batch(5 sec) group by character";
}
/**
* Listener method called when Esper has detected a pattern match.
*/
public void update(Map<String, String> eventMap) {
System.out.println(eventMap);
// Titles in the last 5 seconds
String character = (String) eventMap.get("character");
String count = (String) eventMap.get("count");
StringBuilder sb = new StringBuilder();
sb.append("---------------------------------");
sb.append("\n- [MONITOR] Char = " + character + " Count =" + count);
sb.append("\n---------------------------------");
LOG.debug(sb.toString());
}
任何人都可以建议如何对 select 语句中的两个字段进行分组和返回。
EPL 中的 select-子句不全局命名表达式。
为了在 EPL 或全局范围内共享命名表达式,Esper 有表达式(参见 5.2.9)作为示例。
备选方案是:
insert into Character select title.substring(0,1) as character from Data
select count(*) as count, character from Character.win:time_batch(5 sec) group by character