Search in sources :

Example 1 with QueryPlanBean

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

the class PlanStoreResource method updateQueryPlan.

@PUT
@Path("/{plan_name}")
public TexeraWebResponse updateQueryPlan(@PathParam("plan_name") String planName, String queryPlanBeanJson) {
    try {
        QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
        // Updating the plan in the plan store
        planStore.updatePlan(planName, queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
    } catch (IOException | TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    }
    return new TexeraWebResponse(0, "Success");
}
Also used : TexeraWebResponse(edu.uci.ics.texera.web.response.TexeraWebResponse) 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with QueryPlanBean

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

the class PlanStoreResource method addQueryPlan.

@POST
public TexeraWebResponse addQueryPlan(String queryPlanBeanJson) {
    try {
        QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
        // Adding the query plan to the PlanStore
        planStore.addPlan(queryPlanBean.getName(), queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
    } catch (TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    } catch (IOException e) {
        throw new TexeraWebException(e.getMessage());
    }
    return new TexeraWebResponse(0, "Success");
}
Also used : TexeraWebResponse(edu.uci.ics.texera.web.response.TexeraWebResponse) 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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 3 with QueryPlanBean

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

the class PlanStoreResource method getQueryPlan.

@GET
@Path("/{plan_name}")
public QueryPlanBean getQueryPlan(@PathParam("plan_name") String planName) {
    try {
        Tuple tuple = planStore.getPlan(planName);
        if (tuple == null) {
            throw new TexeraWebException("Plan with the given name does not exist");
        }
        QueryPlanBean queryPlanBean = new QueryPlanBean(tuple.getField(PlanStoreConstants.NAME).getValue().toString(), tuple.getField(PlanStoreConstants.DESCRIPTION).getValue().toString(), mapper.readValue(tuple.getField(PlanStoreConstants.LOGICAL_PLAN_JSON).getValue().toString(), LogicalPlan.class));
        return queryPlanBean;
    } catch (TexeraException e) {
        throw new TexeraWebException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : LogicalPlan(edu.uci.ics.texera.dataflow.plangen.LogicalPlan) IOException(java.io.IOException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) TexeraWebException(edu.uci.ics.texera.web.TexeraWebException) Tuple(edu.uci.ics.texera.api.tuple.Tuple) QueryPlanBean(edu.uci.ics.texera.web.response.planstore.QueryPlanBean)

Example 4 with QueryPlanBean

use of edu.uci.ics.texera.web.response.planstore.QueryPlanBean 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)

Aggregations

TexeraException (edu.uci.ics.texera.api.exception.TexeraException)4 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)4 QueryPlanBean (edu.uci.ics.texera.web.response.planstore.QueryPlanBean)4 IOException (java.io.IOException)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Tuple (edu.uci.ics.texera.api.tuple.Tuple)2 TexeraWebResponse (edu.uci.ics.texera.web.response.TexeraWebResponse)2 LogicalPlan (edu.uci.ics.texera.dataflow.plangen.LogicalPlan)1 DataReader (edu.uci.ics.texera.storage.DataReader)1 QueryPlanListBean (edu.uci.ics.texera.web.response.planstore.QueryPlanListBean)1 ArrayList (java.util.ArrayList)1