Search in sources :

Example 6 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class EmojiSentimentOperator method open.

@Override
public void open() throws TexeraException {
    if (cursor != CLOSED) {
        return;
    }
    if (inputOperator == null) {
        throw new DataflowException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED);
    }
    inputOperator.open();
    Schema inputSchema = inputOperator.getOutputSchema();
    // check if input schema is present
    if (!inputSchema.containsAttribute(predicate.getInputAttributeName())) {
        throw new TexeraException(String.format("input attribute %s is not in the input schema %s", predicate.getInputAttributeName(), inputSchema.getAttributeNames()));
    }
    // check if attribute type is valid
    AttributeType inputAttributeType = inputSchema.getAttribute(predicate.getInputAttributeName()).getType();
    boolean isValidType = inputAttributeType.equals(AttributeType.STRING) || inputAttributeType.equals(AttributeType.TEXT);
    if (!isValidType) {
        throw new TexeraException(String.format("input attribute %s must have type String or Text, its actual type is %s", predicate.getInputAttributeName(), inputAttributeType));
    }
    // generate output schema by transforming the input schema
    outputSchema = transformSchema(inputOperator.getOutputSchema());
    cursor = OPENED;
}
Also used : AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException)

Example 7 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class NltkSentimentOperator method open.

@Override
public void open() throws TexeraException {
    if (cursor != CLOSED) {
        return;
    }
    if (inputOperator == null) {
        throw new DataflowException(ErrorMessages.INPUT_OPERATOR_NOT_SPECIFIED);
    }
    inputOperator.open();
    Schema inputSchema = inputOperator.getOutputSchema();
    // check if the input schema is presented
    if (!inputSchema.containsAttribute(predicate.getInputAttributeName())) {
        throw new TexeraException(String.format("input attribute %s is not in the input schema %s", predicate.getInputAttributeName(), inputSchema.getAttributeNames()));
    }
    // check if the attribute type is valid
    AttributeType inputAttributeType = inputSchema.getAttribute(predicate.getInputAttributeName()).getType();
    boolean isValidType = inputAttributeType.equals(AttributeType.STRING) || inputAttributeType.equals(AttributeType.TEXT);
    if (!isValidType) {
        throw new TexeraException(String.format("input attribute %s must have type String or Text, its actual type is %s", predicate.getInputAttributeName(), inputAttributeType));
    }
    // generate output schema by transforming the input schema
    outputSchema = transformSchema(inputOperator.getOutputSchema());
    cursor = OPENED;
}
Also used : AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException)

Example 8 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException 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 TexeraException, 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 TexeraException {
    if (planName == null || description == null || logicalPlanJson == null) {
        throw new TexeraException("Arguments cannot be null when adding a plan");
    }
    if (!PlanStoreConstants.VALID_PLAN_NAME.matcher(planName).find()) {
        throw new TexeraException("Plan name is not valid. It can only contain alphanumeric characters, " + "underscore, and hyphen.");
    }
    if (getPlan(planName) != null) {
        throw new TexeraException("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.texera.api.field.IDField) StringField(edu.uci.ics.texera.api.field.StringField) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) StorageException(edu.uci.ics.texera.api.exception.StorageException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataWriter(edu.uci.ics.texera.storage.DataWriter)

Example 9 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class ProjectionOperator method setUp.

@Override
protected void setUp() throws TexeraException {
    inputSchema = inputOperator.getOutputSchema();
    List<Attribute> outputAttributes = inputSchema.getAttributes().stream().filter(attr -> predicate.getProjectionFields().contains(attr.getName().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 : List(java.util.List) IField(edu.uci.ics.texera.api.field.IField) AbstractSingleInputOperator(edu.uci.ics.texera.dataflow.common.AbstractSingleInputOperator) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) Schema(edu.uci.ics.texera.api.schema.Schema) Attribute(edu.uci.ics.texera.api.schema.Attribute) Collectors(java.util.stream.Collectors) Attribute(edu.uci.ics.texera.api.schema.Attribute) Schema(edu.uci.ics.texera.api.schema.Schema) DataflowException(edu.uci.ics.texera.api.exception.DataflowException)

Example 10 with TexeraException

use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.

the class AbstractSingleInputOperator method open.

@Override
public void open() throws TexeraException {
    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.texera.api.exception.DataflowException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException)

Aggregations

TexeraException (edu.uci.ics.texera.api.exception.TexeraException)25 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)17 IOException (java.io.IOException)12 Tuple (edu.uci.ics.texera.api.tuple.Tuple)11 Schema (edu.uci.ics.texera.api.schema.Schema)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)8 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)5 Attribute (edu.uci.ics.texera.api.schema.Attribute)5 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)5 IField (edu.uci.ics.texera.api.field.IField)4 QueryPlanBean (edu.uci.ics.texera.web.response.planstore.QueryPlanBean)4 SchemaConstants (edu.uci.ics.texera.api.constants.SchemaConstants)3 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)3 ISink (edu.uci.ics.texera.api.dataflow.ISink)3 StorageException (edu.uci.ics.texera.api.exception.StorageException)3 IntegerField (edu.uci.ics.texera.api.field.IntegerField)3 Collectors (java.util.stream.Collectors)3