Search in sources :

Example 6 with TextDBException

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;
}
Also used : IDField(edu.uci.ics.textdb.api.field.IDField) StringField(edu.uci.ics.textdb.api.field.StringField) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) StorageException(edu.uci.ics.textdb.api.exception.StorageException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) DataWriter(edu.uci.ics.textdb.storage.DataWriter)

Example 7 with TextDBException

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));
}
Also used : Schema(edu.uci.ics.textdb.api.schema.Schema) List(java.util.List) Attribute(edu.uci.ics.textdb.api.schema.Attribute) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) AbstractSingleInputOperator(edu.uci.ics.textdb.exp.common.AbstractSingleInputOperator) IField(edu.uci.ics.textdb.api.field.IField) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) Collectors(java.util.stream.Collectors) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) Attribute(edu.uci.ics.textdb.api.schema.Attribute) Schema(edu.uci.ics.textdb.api.schema.Schema) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException)

Example 8 with TextDBException

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;
}
Also used : DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException)

Example 9 with TextDBException

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);
}
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 10 with TextDBException

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);
    }
}
Also used : DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException) Tuple(edu.uci.ics.textdb.api.tuple.Tuple) TextDBException(edu.uci.ics.textdb.api.exception.TextDBException) DataFlowException(edu.uci.ics.textdb.api.exception.DataFlowException)

Aggregations

TextDBException (edu.uci.ics.textdb.api.exception.TextDBException)15 DataFlowException (edu.uci.ics.textdb.api.exception.DataFlowException)9 Tuple (edu.uci.ics.textdb.api.tuple.Tuple)8 IOException (java.io.IOException)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 TextdbWebException (edu.uci.ics.textdb.web.TextdbWebException)4 QueryPlanBean (edu.uci.ics.textdb.web.response.planstore.QueryPlanBean)4 StorageException (edu.uci.ics.textdb.api.exception.StorageException)3 Attribute (edu.uci.ics.textdb.api.schema.Attribute)3 Schema (edu.uci.ics.textdb.api.schema.Schema)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 SchemaConstants (edu.uci.ics.textdb.api.constants.SchemaConstants)2 IField (edu.uci.ics.textdb.api.field.IField)2 AttributeType (edu.uci.ics.textdb.api.schema.AttributeType)2 Utils (edu.uci.ics.textdb.api.utils.Utils)2 AbstractSingleInputOperator (edu.uci.ics.textdb.exp.common.AbstractSingleInputOperator)2 TextdbWebResponse (edu.uci.ics.textdb.web.response.TextdbWebResponse)2 Collectors (java.util.stream.Collectors)2