use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class LineChartSink method processTuples.
@Override
public void processTuples() throws TexeraException {
List<Tuple> list = new ArrayList<>();
Tuple tuple;
while ((tuple = inputOperator.getNextTuple()) != null) {
list.add(tuple);
}
result = list.stream().map(e -> {
IField[] fields = attributes.stream().map(a -> e.getField(a.getName())).toArray(IField[]::new);
return new Tuple(outputSchema, fields);
}).collect(Collectors.toList());
}
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 EmojiSentimentOperator method transformToOutputSchema.
public Schema transformToOutputSchema(Schema... inputSchema) {
if (inputSchema.length != 1)
throw new TexeraException(String.format(ErrorMessages.NUMBER_OF_ARGUMENTS_DOES_NOT_MATCH, 1, inputSchema.length));
// check if input schema is present
if (!inputSchema[0].containsAttribute(predicate.getInputAttributeName())) {
throw new TexeraException(String.format("input attribute %s is not in the input schema %s", predicate.getInputAttributeName(), inputSchema[0].getAttributeNames()));
}
// check if attribute type is valid
AttributeType inputAttributeType = inputSchema[0].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));
}
return transformSchema(inputSchema[0]);
}
use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class NlpSplitOperator method transformToOutputSchema.
/*
* adds a new field to the schema, with name resultAttributeName and type list of strings
*/
public Schema transformToOutputSchema(Schema... inputSchema) throws DataflowException {
if (inputSchema.length != 1)
throw new TexeraException(String.format(ErrorMessages.NUMBER_OF_ARGUMENTS_DOES_NOT_MATCH, 1, inputSchema.length));
Schema.checkAttributeExists(inputSchema[0], predicate.getInputAttributeName());
Schema.checkAttributeNotExists(inputSchema[0], predicate.getResultAttributeName());
if (predicate.getOutputType() == NLPOutputType.ONE_TO_ONE)
return new Schema.Builder().add(inputSchema[0]).add(predicate.getResultAttributeName(), AttributeType.LIST).build();
else
return new Schema.Builder().add(inputSchema[0]).add(predicate.getResultAttributeName(), AttributeType.TEXT).build();
}
use of edu.uci.ics.texera.api.exception.TexeraException in project textdb by TextDB.
the class LogicalPlan method getOperatorOutputSchema.
/**
* Updates the current plan and fetch the schema from an operator
* @param operatorID, the ID of an operator
* @param operatorInputSchemaMap Map of operators to their input schemas
* @return Schema, which includes the attributes setting of the operator
*/
public Optional<Schema> getOperatorOutputSchema(String operatorID, Map<String, List<Schema>> operatorInputSchemaMap) throws PlanGenException, DataflowException {
IOperator currentOperator = operatorObjectMap.get(operatorID);
Optional<Schema> outputSchema = Optional.empty();
if (currentOperator instanceof ISourceOperator) {
outputSchema = Optional.ofNullable(currentOperator.transformToOutputSchema());
} else if (operatorInputSchemaMap.containsKey(operatorID)) {
List<Schema> inputSchemaList = operatorInputSchemaMap.get(operatorID);
try {
outputSchema = Optional.ofNullable(currentOperator.transformToOutputSchema(inputSchemaList.toArray(new Schema[inputSchemaList.size()])));
} catch (TexeraException e) {
System.out.println(e.getMessage());
}
}
return outputSchema;
}
Aggregations