use of edu.uci.ics.textdb.api.exception.TextDBException in project textdb by TextDB.
the class PlanStore method addPlan.
/**
* Adds a Logical Plan JSON to the plan store.
*
* @param planName, the name of the plan.
* @param description, the description of the plan.
* @param logicalPlanJson, the logical plan JSON string
* @Return IDField, the id field of the plan stored.
* @throws TextDBException, when there are null fields or the given name is invalid or there is an existing plan with same name.
*/
public IDField addPlan(String planName, String description, String logicalPlanJson) throws TextDBException {
if (planName == null || description == null || logicalPlanJson == null) {
throw new TextDBException("Arguments cannot be null when adding a plan");
}
if (!PlanStoreConstants.VALID_PLAN_NAME.matcher(planName).find()) {
throw new TextDBException("Plan name is not valid. It can only contain alphanumeric characters, " + "underscore, and hyphen.");
}
if (getPlan(planName) != null) {
throw new TextDBException("A plan with the same name already exists");
}
try {
// Converting the JSON String to a JSON Node to minimize space usage and to check validity of JSON string
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class);
logicalPlanJson = objectMapper.writeValueAsString(jsonNode);
} catch (IOException e) {
throw new StorageException("logical plan json is an invalid json string: " + logicalPlanJson);
}
Tuple tuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), new StringField(description), new StringField(logicalPlanJson));
DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME);
dataWriter.open();
IDField id = dataWriter.insertTuple(tuple);
dataWriter.close();
return id;
}
use of edu.uci.ics.textdb.api.exception.TextDBException in project textdb by TextDB.
the class ProjectionOperator method setUp.
@Override
protected void setUp() throws TextDBException {
inputSchema = inputOperator.getOutputSchema();
List<Attribute> outputAttributes = inputSchema.getAttributes().stream().filter(attr -> predicate.getProjectionFields().contains(attr.getAttributeName().toLowerCase())).collect(Collectors.toList());
if (outputAttributes.size() != predicate.getProjectionFields().size()) {
throw new DataFlowException("input schema doesn't contain one of the attributes to be projected");
}
outputSchema = new Schema(outputAttributes.stream().toArray(Attribute[]::new));
}
use of edu.uci.ics.textdb.api.exception.TextDBException in project textdb by TextDB.
the class AbstractSingleInputOperator method open.
@Override
public void open() throws TextDBException {
if (cursor != CLOSED) {
return;
}
try {
if (this.inputOperator == null) {
throw new DataFlowException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED);
}
inputOperator.open();
setUp();
} catch (Exception e) {
throw new DataFlowException(e.getMessage(), e);
}
cursor = OPENED;
}
use of edu.uci.ics.textdb.api.exception.TextDBException 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.api.exception.TextDBException in project textdb by TextDB.
the class Join method getNextTuple.
/**
* Gets the next tuple which is a joint of two tuples which passed the
* criteria set in the JoinPredicate. <br>
* Example in JoinPredicate.java
*
* @return nextTuple
*/
@Override
public Tuple getNextTuple() throws TextDBException {
if (cursor == CLOSED) {
throw new DataFlowException(ErrorMessages.OPERATOR_NOT_OPENED);
}
// load all tuples from inner operator into memory in the first time
if (innerTupleList == null) {
innerTupleList = new ArrayList<>();
Tuple tuple;
while ((tuple = innerOperator.getNextTuple()) != null) {
innerTupleList.add(tuple);
}
}
// load the first outer tuple
currentOuterTuple = outerOperator.getNextTuple();
// all outer tuples have been consumed
if (innerTupleList.isEmpty() || currentOuterTuple == null) {
return null;
}
if (resultCursor >= limit + offset - 1 || limit == 0) {
return null;
}
try {
Tuple resultTuple = null;
while (true) {
resultTuple = computeNextMatchingTuple();
if (resultTuple == null) {
break;
}
resultCursor++;
if (resultCursor >= offset) {
break;
}
}
return resultTuple;
} catch (Exception e) {
throw new DataFlowException(e.getMessage(), e);
}
}
Aggregations