无法在esper

时间:2016-01-09 21:15:38

标签: java esper

我为执行查询而编写的代码如下:

EPServiceProvider cep = EPServiceProviderManager.getProvider("EventChannelling",config);
EPRuntime rt=cep.getEPRuntime();            
EPServiceProvider cep1 = EPServiceProviderManager.getDefaultProvider(config);
String query = "create table CustomerRules ( C_ID String primary key, E_Type int primary key, Rule int )";
rt.executeQuery(query);

但是我收到以下错误:

  

线程中的异常" main"   com.espertech.esper.client.EPStatementException:执行错误   声明:0 [create table CustomerRules(C_ID String主键,   E_Type int主键,Rule int)] at   com.espertech.esper.core.service.EPRuntimeImpl.getExecuteMethod(EPRuntimeImpl.java:1671)     在   com.espertech.esper.core.service.EPRuntimeImpl.executeQueryInternal(EPRuntimeImpl.java:1552)     在   com.espertech.esper.core.service.EPRuntimeImpl.executeQuery(EPRuntimeImpl.java:1526)     在Example.main(Example.java:148)

有人可以告诉我这个错误的原因吗?

3 个答案:

答案 0 :(得分:0)

试试这个:

Configuration config = new Configuration();

//TODO Configure...

EPServiceProvider epService = EPServiceProviderManager.getDefaultProvider(config);

Module module = epService.getEPAdministrator().getDeploymentAdmin().parse("create table CustomerRules (C_ID String primary key, E_Type int primary key, Rule int);");

epService.getEPAdministrator().getDeploymentAdmin().deploy(module, null);

epService.getEPRuntime().executeQuery("insert into CustomerRules(C_ID, E_Type, Rule) values ('1', 1, 1)");

让我知道它是否有效!

答案 1 :(得分:0)

问题是您正在尝试使用EPRuntime执行create语句,该语句用于按需查询。试试这个:

    Configuration config = new Configuration();
    config.addEventType("Event", new String[] {"C_ID", "E_Type", "Rule"}, new Object[] {String.class, Integer.class, Integer.class});

    EPServiceProvider cep = EPServiceProviderManager.getProvider("EventChannelling",config);
EPRuntime rt=cep.getEPRuntime();
        String query = "create table CustomerRules ( C_ID String primary key, E_Type int primary key, Rule int )";
    cep.getEPAdministrator().createEPL(query);
    cep.getEPAdministrator().createEPL("insert into CustomerRules select C_ID, E_Type, Rule from Event");
cep.getEPRuntime().getEventSender("Event").sendEvent(new Object[]{"Prueba", 100, 100});
    System.out.println(rt.executeQuery("select * from CustomerRules").getArray()[0].get("C_ID"));

我编译了这段代码,我没有来自esper引擎的抱怨,我得到了输出“Prueba”

如果这有用,请告诉我。

答案 2 :(得分:-1)

使用createEPL方法创建表格。运行时查询API用于查询,而不是用于创建表。