Search in sources :

Example 1 with TextdbWebException

use of edu.uci.ics.textdb.web.TextdbWebException 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 TextdbWebException

use of edu.uci.ics.textdb.web.TextdbWebException in project textdb by TextDB.

the class NewQueryPlanResource method executeQueryPlan.

/**
     * This is the edu.uci.ics.textdb.web.request handler for the execution of a Query Plan.
     * @param logicalPlanJson, the json representation of the logical plan
     * @return - Generic TextdbWebResponse object
     */
@POST
@Path("/execute")
public // TODO: investigate how to use LogicalPlan directly
TextdbWebResponse executeQueryPlan(String logicalPlanJson) {
    try {
        LogicalPlan logicalPlan = new ObjectMapper().readValue(logicalPlanJson, LogicalPlan.class);
        Plan plan = logicalPlan.buildQueryPlan();
        ISink sink = plan.getRoot();
        // send response back to frontend
        if (sink instanceof TupleSink) {
            TupleSink tupleSink = (TupleSink) sink;
            tupleSink.open();
            List<Tuple> results = tupleSink.collectAllTuples();
            tupleSink.close();
            ArrayNode arrayNode = new ObjectMapper().createArrayNode();
            for (Tuple tuple : results) {
                arrayNode.add(tuple.getReadableJson());
            }
            return new TextdbWebResponse(0, new ObjectMapper().writeValueAsString(arrayNode));
        } else {
            // execute the plan and return success message
            Engine.getEngine().evaluate(plan);
            ObjectNode objectNode = new ObjectMapper().createObjectNode();
            objectNode.put("status", "plan sucessfully executed");
            return new TextdbWebResponse(0, new ObjectMapper().writeValueAsString(objectNode));
        }
    } catch (IOException | RuntimeException e) {
        // TODO remove RuntimeException after the exception refactor
        e.printStackTrace();
        throw new TextdbWebException(e.getMessage());
    }
}
Also used : TupleSink(edu.uci.ics.textdb.exp.sink.tuple.TupleSink) TextdbWebResponse(edu.uci.ics.textdb.web.response.TextdbWebResponse) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) IOException(java.io.IOException) LogicalPlan(edu.uci.ics.textdb.exp.plangen.LogicalPlan) Plan(edu.uci.ics.textdb.api.engine.Plan) ISink(edu.uci.ics.textdb.api.dataflow.ISink) TextdbWebException(edu.uci.ics.textdb.web.TextdbWebException) LogicalPlan(edu.uci.ics.textdb.exp.plangen.LogicalPlan) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 3 with TextdbWebException

use of edu.uci.ics.textdb.web.TextdbWebException in project textdb by TextDB.

the class PlanStoreResource method updateQueryPlan.

@PUT
@Path("/{plan_name}")
public TextdbWebResponse 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 | TextDBException e) {
        throw new TextdbWebException(e.getMessage());
    }
    return new TextdbWebResponse(0, "Success");
}
Also used : TextdbWebResponse(edu.uci.ics.textdb.web.response.TextdbWebResponse) TextdbWebException(edu.uci.ics.textdb.web.TextdbWebException) IOException(java.io.IOException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) QueryPlanBean(edu.uci.ics.textdb.web.response.planstore.QueryPlanBean) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with TextdbWebException

use of edu.uci.ics.textdb.web.TextdbWebException 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 TextdbWebException("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 (TextDBException e) {
        throw new TextdbWebException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : TextdbWebException(edu.uci.ics.textdb.web.TextdbWebException) LogicalPlan(edu.uci.ics.textdb.exp.plangen.LogicalPlan) IOException(java.io.IOException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) QueryPlanBean(edu.uci.ics.textdb.web.response.planstore.QueryPlanBean)

Example 5 with TextdbWebException

use of edu.uci.ics.textdb.web.TextdbWebException in project textdb by TextDB.

the class PlanStoreResource method addQueryPlan.

@POST
public TextdbWebResponse 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 (TextDBException e) {
        throw new TextdbWebException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new TextdbWebResponse(0, "Success");
}
Also used : TextdbWebResponse(edu.uci.ics.textdb.web.response.TextdbWebResponse) TextdbWebException(edu.uci.ics.textdb.web.TextdbWebException) IOException(java.io.IOException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) QueryPlanBean(edu.uci.ics.textdb.web.response.planstore.QueryPlanBean) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

TextdbWebException (edu.uci.ics.textdb.web.TextdbWebException)5 IOException (java.io.IOException)5 TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)4 QueryPlanBean (edu.uci.ics.textdb.web.response.planstore.QueryPlanBean)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)3 TextdbWebResponse (edu.uci.ics.textdb.web.response.TextdbWebResponse)3 LogicalPlan (edu.uci.ics.textdb.exp.plangen.LogicalPlan)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ISink (edu.uci.ics.textdb.api.dataflow.ISink)1 Plan (edu.uci.ics.textdb.api.engine.Plan)1 TupleSink (edu.uci.ics.textdb.exp.sink.tuple.TupleSink)1 DataReader (edu.uci.ics.textdb.storage.DataReader)1 QueryPlanListBean (edu.uci.ics.textdb.web.response.planstore.QueryPlanListBean)1 ArrayList (java.util.ArrayList)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1