Search in sources :

Example 1 with QueryPlanListBean

use of edu.uci.ics.textdb.web.response.planstore.QueryPlanListBean in project textdb by TextDB.

the class PlanStoreResource method getAllQueryPlans.

@GET
public QueryPlanListBean getAllQueryPlans() {
    ArrayList<QueryPlanBean> queryPlans = new ArrayList<>();
    try {
        // Getting an iterator for the plan store
        DataReader reader = planStore.getPlanIterator();
        reader.open();
        // Iterating through the stored plans, and mapping them to a QueryPlanRequest object
        Tuple tuple;
        while ((tuple = reader.getNextTuple()) != null) {
            String name = tuple.getField(PlanStoreConstants.NAME).getValue().toString();
            String description = tuple.getField(PlanStoreConstants.DESCRIPTION).getValue().toString();
            String logicalPlanJson = tuple.getField(PlanStoreConstants.LOGICAL_PLAN_JSON).getValue().toString();
            queryPlans.add(new QueryPlanBean(name, description, mapper.readValue(logicalPlanJson, LogicalPlan.class)));
        }
    } catch (TextDBException e) {
        e.printStackTrace();
        throw new TextdbWebException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new TextdbWebException("fail to parse json:\n" + e.getMessage());
    }
    return new QueryPlanListBean(queryPlans);
}
Also used : QueryPlanListBean(edu.uci.ics.textdb.web.response.planstore.QueryPlanListBean) DataReader(edu.uci.ics.textdb.storage.DataReader) TextdbWebException(edu.uci.ics.textdb.web.TextdbWebException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) QueryPlanBean(edu.uci.ics.textdb.web.response.planstore.QueryPlanBean) Tuple(edu.uci.ics.textdb.api.tuple.Tuple)

Example 2 with QueryPlanListBean

use of edu.uci.ics.textdb.web.response.planstore.QueryPlanListBean in project textdb by TextDB.

the class PlanStoreResourceTest method checkAddMultiplePlans.

@Test
public void checkAddMultiplePlans() throws IOException {
    Response response = client.target(String.format(planStoreEndpoint, RULE.getLocalPort())).request().post(Entity.entity(queryPlan2, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus()).isEqualTo(200);
    response = client.target(String.format(planStoreEndpoint, RULE.getLocalPort())).request().post(Entity.entity(queryPlan1, MediaType.APPLICATION_JSON));
    assertThat(response.getStatus()).isEqualTo(200);
    response = client.target(String.format(planStoreEndpoint, RULE.getLocalPort())).request().get();
    ObjectMapper mapper = new ObjectMapper();
    QueryPlanListBean queryPlanResponse = mapper.readValue(response.readEntity(String.class), QueryPlanListBean.class);
    assertThat(response.getStatus()).isEqualTo(200);
    assertThat(queryPlanResponse.getQueryPlanList().size() == 2);
}
Also used : Response(javax.ws.rs.core.Response) QueryPlanListBean(edu.uci.ics.textdb.web.response.planstore.QueryPlanListBean) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) LogicalPlanTest(edu.uci.ics.textdb.exp.plangen.LogicalPlanTest)

Aggregations

QueryPlanListBean (edu.uci.ics.textdb.web.response.planstore.QueryPlanListBean)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)1 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)1 LogicalPlanTest (edu.uci.ics.textdb.exp.plangen.LogicalPlanTest)1 DataReader (edu.uci.ics.textdb.storage.DataReader)1 TextdbWebException (edu.uci.ics.textdb.web.TextdbWebException)1 QueryPlanBean (edu.uci.ics.textdb.web.response.planstore.QueryPlanBean)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1