Search in sources :

Example 1 with QueryPlanListBean

use of edu.uci.ics.texera.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 (TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    } catch (IOException e) {
        throw new TexeraWebException("fail to parse json:\n" + e.getMessage());
    }
    return new QueryPlanListBean(queryPlans);
}
Also used : QueryPlanListBean(edu.uci.ics.texera.web.response.planstore.QueryPlanListBean) DataReader(edu.uci.ics.texera.storage.DataReader) ArrayList(java.util.ArrayList) IOException(java.io.IOException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) QueryPlanBean(edu.uci.ics.texera.web.response.planstore.QueryPlanBean) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 2 with QueryPlanListBean

use of edu.uci.ics.texera.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.texera.web.response.planstore.QueryPlanListBean) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LogicalPlanTest(edu.uci.ics.texera.dataflow.plangen.LogicalPlanTest) Test(org.junit.Test)

Aggregations

QueryPlanListBean (edu.uci.ics.texera.web.response.planstore.QueryPlanListBean)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)1 Tuple (edu.uci.ics.texera.api.tuple.Tuple)1 LogicalPlanTest (edu.uci.ics.texera.dataflow.plangen.LogicalPlanTest)1 DataReader (edu.uci.ics.texera.storage.DataReader)1 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)1 QueryPlanBean (edu.uci.ics.texera.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