use of edu.uci.ics.texera.api.exception.DataflowException in project textdb by TextDB.
the class ExcelSink method close.
@Override
public void close() throws TexeraException {
if (cursor == CLOSED) {
return;
}
inputOperator.close();
try {
wb.write(fileOut);
fileOut.close();
cursor = CLOSED;
} catch (IOException e) {
throw new DataflowException(e);
}
}
use of edu.uci.ics.texera.api.exception.DataflowException in project textdb by TextDB.
the class ExcelSink method open.
@Override
public void open() throws TexeraException {
if (cursor != CLOSED) {
return;
}
inputOperator.open();
inputSchema = inputOperator.getOutputSchema();
outputSchema = new Schema(inputSchema.getAttributes().stream().filter(attr -> !attr.getName().equalsIgnoreCase(SchemaConstants._ID)).filter(attr -> !attr.getName().equalsIgnoreCase(SchemaConstants.PAYLOAD)).filter(attr -> !attr.getType().equals(AttributeType.LIST)).toArray(Attribute[]::new));
wb = new XSSFWorkbook();
DateFormat df = new SimpleDateFormat("yyyyMMdd-HHmmss");
fileName = df.format(new Date()) + ".xlsx";
try {
if (Files.notExists(excelIndexDirectory)) {
Files.createDirectories(excelIndexDirectory);
}
fileOut = new FileOutputStream(excelIndexDirectory.resolve(fileName).toString());
} catch (IOException e) {
throw new DataflowException(e);
}
sheet = wb.createSheet("new sheet");
Row row = sheet.createRow(0);
List<String> attributeNames = outputSchema.getAttributeNames();
for (int i = 0; i < attributeNames.size(); i++) {
String attributeName = attributeNames.get(i);
row.createCell(i).setCellValue(attributeName);
}
cursor = OPENED;
}
use of edu.uci.ics.texera.api.exception.DataflowException in project textdb by TextDB.
the class MysqlSink method open.
/**
* Filter the input tuples to removie _id and list fields Setup JDBC
* connection. Drop previous testTable and create new testTable based on
* output schema
*/
@Override
public void open() throws TexeraException {
if (cursor == OPENED) {
return;
}
inputOperator.open();
Schema inputSchema = inputOperator.getOutputSchema();
outputSchema = new Schema(inputSchema.getAttributes().stream().filter(attr -> !attr.getName().equalsIgnoreCase(SchemaConstants._ID)).filter(attr -> !attr.getName().equalsIgnoreCase(SchemaConstants.PAYLOAD)).filter(attr -> !attr.getType().equals(AttributeType.LIST)).toArray(Attribute[]::new));
// JDBC connection
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url = "jdbc:mysql://" + predicate.getHost() + ":" + predicate.getPort() + "/" + predicate.getDatabase() + "?autoReconnect=true&useSSL=true";
this.connection = DriverManager.getConnection(url, predicate.getUsername(), predicate.getPassword());
statement = connection.createStatement();
mysqlDropTable();
mysqlCreateTable();
cursor = OPENED;
} catch (SQLException | InstantiationException | IllegalAccessException | ClassNotFoundException e) {
throw new DataflowException("MysqlSink failed to connect to mysql database." + e.getMessage());
}
}
use of edu.uci.ics.texera.api.exception.DataflowException in project textdb by TextDB.
the class MysqlSink method close.
@Override
public void close() throws TexeraException {
if (cursor == CLOSED) {
return;
}
inputOperator.close();
try {
if (statement != null)
statement.close();
if (prepStatement != null)
prepStatement.close();
connection.close();
cursor = CLOSED;
} catch (SQLException e) {
throw new DataflowException("MysqlSink fail to close. " + e.getMessage());
}
}
use of edu.uci.ics.texera.api.exception.DataflowException in project textdb by TextDB.
the class AsterixSource method getNextTuple.
@Override
public Tuple getNextTuple() throws TexeraException {
if (cursor == CLOSED) {
throw new DataflowException(ErrorMessages.OPERATOR_NOT_OPENED);
}
if (cursor < resultJsonArray.length()) {
Tuple tuple = new Tuple(ATERIX_SOURCE_SCHEMA, IDField.newRandomID(), new TextField(resultJsonArray.getJSONObject(cursor).get("ds").toString()));
cursor++;
return tuple;
}
return null;
}
Aggregations