use of edu.uci.ics.textdb.storage.DataReader in project textdb by TextDB.
the class PlanStore method getPlan.
/**
* Retrieves a plan by given name from plan store.
*
* @param planName, the name of the plan.
* @Return ITuple, the tuple consisting of fields of the plan.
* @throws TextDBException
*/
public Tuple getPlan(String planName) throws TextDBException {
Query q = new TermQuery(new Term(PlanStoreConstants.NAME, planName));
DataReader reader = relationManager.getTableDataReader(PlanStoreConstants.TABLE_NAME, q);
reader.open();
Tuple inputTuple = null;
while ((inputTuple = reader.getNextTuple()) != null) {
IField nameField = inputTuple.getField(PlanStoreConstants.NAME);
if (nameField.getValue().toString().equals(planName)) {
reader.close();
return inputTuple;
}
}
reader.close();
return null;
}
use of edu.uci.ics.textdb.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 (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);
}
use of edu.uci.ics.textdb.storage.DataReader in project textdb by TextDB.
the class WordCountIndexSource method computeWordCount.
private void computeWordCount() throws TextDBException {
try {
HashMap<String, Integer> wordCountMap = new HashMap<>();
DataReader dataReader = RelationManager.getRelationManager().getTableDataReader(predicate.getTableName(), new MatchAllDocsQuery());
dataReader.open();
IndexReader luceneIndexReader = dataReader.getLuceneIndexReader();
for (int i = 0; i < luceneIndexReader.numDocs(); i++) {
Terms termVector = luceneIndexReader.getTermVector(i, predicate.getAttribute());
TermsEnum termsEnum = termVector.iterator();
while (termsEnum.next() != null) {
String key = termsEnum.term().utf8ToString();
wordCountMap.put(key, wordCountMap.get(key) == null ? ((int) termsEnum.totalTermFreq()) : wordCountMap.get(key) + ((int) termsEnum.totalTermFreq()));
}
}
luceneIndexReader.close();
dataReader.close();
sortedWordCountMap = wordCountMap.entrySet().stream().sorted((e1, e2) -> e2.getValue().compareTo(e1.getValue())).collect(Collectors.toList());
wordCountIterator = sortedWordCountMap.iterator();
} catch (IOException e) {
throw new DataFlowException(e);
}
}
use of edu.uci.ics.textdb.storage.DataReader in project textdb by TextDB.
the class PlanStoreTest method testPlanIterator.
@Test
public void testPlanIterator() throws TextDBException {
List<String> validPlans = new ArrayList<>();
validPlans.add(logicalPlanJson1);
validPlans.add(logicalPlanJson2);
List<String> expectedPlans = new ArrayList<>();
String planNamePrefix = "plan_";
for (int i = 0; i < 100; i++) {
String plan = validPlans.get(i % 2);
expectedPlans.add(plan);
planStore.addPlan(planNamePrefix + i, "basic plan " + i, plan);
}
DataReader reader = planStore.getPlanIterator();
reader.open();
Tuple tuple;
String[] returnedPlans = new String[expectedPlans.size()];
while ((tuple = reader.getNextTuple()) != null) {
String planName = tuple.getField(PlanStoreConstants.NAME).getValue().toString();
int planIdx = Integer.parseInt(planName.split("_")[1]);
String logicalPlanJson = tuple.getField(PlanStoreConstants.LOGICAL_PLAN_JSON).getValue().toString();
returnedPlans[planIdx] = logicalPlanJson;
}
reader.close();
for (int i = 0; i < expectedPlans.size(); i++) {
assertPlanEquivalence(expectedPlans.get(i), returnedPlans[i]);
}
}
Aggregations