Search in sources :

Example 21 with DataflowException

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

the class RegexSplitOperator method setUp.

@Override
protected void setUp() throws DataflowException {
    Schema inputSchema = inputOperator.getOutputSchema();
    // generate output schema by transforming the input schema based on what output format
    // is chosen (OneToOne vs. OneToMany)
    this.outputSchema = transformSchema(inputSchema);
    // 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 DataflowException(String.format("input attribute %s must have type String or Text, its actual type is %s", predicate.getInputAttributeName(), inputAttributeType));
    }
}
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)

Example 22 with DataflowException

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

the class AbstractSink method processTuples.

@Override
public void processTuples() throws TexeraException {
    if (cursor == CLOSED) {
        throw new DataflowException(ErrorMessages.OPERATOR_NOT_OPENED);
    }
    Tuple nextTuple;
    while ((nextTuple = inputOperator.getNextTuple()) != null) {
        processOneTuple(nextTuple);
        cursor++;
    }
}
Also used : DataflowException(edu.uci.ics.texera.api.exception.DataflowException) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 23 with DataflowException

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

the class MysqlSink method processTuples.

/**
 * Insert tuples into mysql database using prepared statement. No output
 */
@Override
public void processTuples() throws TexeraException {
    String sqlStatemnt = "INSERT INTO " + predicate.getTable() + " VALUES(" + Stream.generate(() -> "?").limit(outputSchema.getAttributeNames().size()).collect(Collectors.joining(",")) + ");";
    try {
        prepStatement = connection.prepareStatement(sqlStatemnt);
        Tuple tuple;
        while ((tuple = this.getNextTuple()) != null) {
            List<IField> fieldList = new ArrayList<>();
            for (int i = 0; i < outputSchema.getAttributeNames().size(); i++) {
                fieldList.add(tuple.getField(outputSchema.getAttributeNames().get(i)));
            }
            for (int i = 0; i < fieldList.size(); i++) {
                prepareField(i, fieldList.get(i));
            }
            prepStatement.executeUpdate();
        }
    } catch (SQLException e) {
        throw new DataflowException("MysqlSink processTuples fails to execute prepared statement. " + e.getMessage());
    }
}
Also used : SQLException(java.sql.SQLException) ArrayList(java.util.ArrayList) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) IField(edu.uci.ics.texera.api.field.IField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 24 with DataflowException

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

the class MysqlSink method mysqlCreateTable.

/**
 * Get the table schema from inputOperator, create table in mysql database
 */
private int mysqlCreateTable() {
    List<Attribute> attributeList = outputSchema.getAttributes();
    String createTableStatement = "CREATE TABLE " + predicate.getTable() + " (\n";
    createTableStatement += attributeList.stream().map(attr -> convertAttribute(attr)).collect(Collectors.joining(",\n"));
    createTableStatement += "\n); ";
    try {
        if (statement == null)
            statement = connection.createStatement();
        return statement.executeUpdate(createTableStatement);
    } catch (SQLException e) {
        throw new DataflowException("MysqlSink failed to create table " + predicate.getTable() + ". " + e.getMessage());
    }
}
Also used : Attribute(edu.uci.ics.texera.api.schema.Attribute) SQLException(java.sql.SQLException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException)

Example 25 with DataflowException

use of edu.uci.ics.texera.api.exception.DataflowException 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

DataflowException (edu.uci.ics.texera.api.exception.DataflowException)56 TexeraException (edu.uci.ics.texera.api.exception.TexeraException)23 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)20 Schema (edu.uci.ics.texera.api.schema.Schema)20 Tuple (edu.uci.ics.texera.api.tuple.Tuple)18 IOException (java.io.IOException)14 Span (edu.uci.ics.texera.api.span.Span)11 Collectors (java.util.stream.Collectors)10 SchemaConstants (edu.uci.ics.texera.api.constants.SchemaConstants)9 ArrayList (java.util.ArrayList)9 Attribute (edu.uci.ics.texera.api.schema.Attribute)8 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)7 IField (edu.uci.ics.texera.api.field.IField)7 ListField (edu.uci.ics.texera.api.field.ListField)7 List (java.util.List)7 AbstractSingleInputOperator (edu.uci.ics.texera.dataflow.common.AbstractSingleInputOperator)6 ErrorMessages (edu.uci.ics.texera.api.constants.ErrorMessages)5 StorageException (edu.uci.ics.texera.api.exception.StorageException)5 IntegerField (edu.uci.ics.texera.api.field.IntegerField)4 DataflowUtils (edu.uci.ics.texera.dataflow.utils.DataflowUtils)4