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));
}
}
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++;
}
}
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());
}
}
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());
}
}
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;
}
Aggregations