use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class NlpSentimentOperator 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;
// setup NLP sentiment analysis pipeline
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
sentimentPipeline = new StanfordCoreNLP(props);
}
use of edu.uci.ics.texera.api.exception.TexeraException 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.TexeraException 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.TexeraException in project textdb by TextDB.
the class PlanStoreTest method assertPlanEquivalence.
/**
* This function checks whether the two given logical plan JSON strings are equivalent
* @param plan1 - The first Logical Plan JSON
* @param plan2 - The second Logical Plan JSON
*/
public static void assertPlanEquivalence(String plan1, String plan2) {
Assert.assertNotNull(plan1);
Assert.assertNotNull(plan2);
try {
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode1 = objectMapper.readValue(plan1, JsonNode.class);
JsonNode jsonNode2 = objectMapper.readValue(plan2, JsonNode.class);
Assert.assertEquals(jsonNode1, jsonNode2);
} catch (IOException e) {
throw new TexeraException(e);
}
}
use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class PlanStoreResource method addQueryPlan.
@POST
public TexeraWebResponse addQueryPlan(String queryPlanBeanJson) {
try {
QueryPlanBean queryPlanBean = new ObjectMapper().readValue(queryPlanBeanJson, QueryPlanBean.class);
// Adding the query plan to the PlanStore
planStore.addPlan(queryPlanBean.getName(), queryPlanBean.getDescription(), mapper.writeValueAsString(queryPlanBean.getQueryPlan()));
} catch (TexeraException e) {
throw new TexeraWebException(e.getMessage());
} catch (IOException e) {
throw new TexeraWebException(e.getMessage());
}
return new TexeraWebResponse(0, "Success");
}
Aggregations