Search in sources :

Example 6 with DataReader

use of edu.uci.ics.texera.storage.DataReader 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

DataReader (edu.uci.ics.texera.storage.DataReader)6 Tuple (edu.uci.ics.texera.api.tuple.Tuple)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 MatchAllDocsQuery (org.apache.lucene.search.MatchAllDocsQuery)3 Term (org.apache.lucene.index.Term)2 TermQuery (org.apache.lucene.search.TermQuery)2 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)1 StorageException (edu.uci.ics.texera.api.exception.StorageException)1 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)1 IField (edu.uci.ics.texera.api.field.IField)1 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)1 QueryPlanBean (edu.uci.ics.texera.web.response.planstore.QueryPlanBean)1 QueryPlanListBean (edu.uci.ics.texera.web.response.planstore.QueryPlanListBean)1 HashMap (java.util.HashMap)1 IndexReader (org.apache.lucene.index.IndexReader)1 Terms (org.apache.lucene.index.Terms)1 TermsEnum (org.apache.lucene.index.TermsEnum)1 Query (org.apache.lucene.search.Query)1 Test (org.junit.Test)1