Search in sources :

Example 36 with TexeraException

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());
}
Also used : List(java.util.List) IField(edu.uci.ics.texera.api.field.IField) ErrorMessages(edu.uci.ics.texera.api.constants.ErrorMessages) Tuple(edu.uci.ics.texera.api.tuple.Tuple) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) VisualizationOperator(edu.uci.ics.texera.dataflow.sink.VisualizationOperator) Attribute(edu.uci.ics.texera.api.schema.Attribute) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) IField(edu.uci.ics.texera.api.field.IField) Tuple(edu.uci.ics.texera.api.tuple.Tuple)

Example 37 with TexeraException

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());
    }
}
Also used : Connection(java.sql.Connection) Tuple(edu.uci.ics.texera.api.tuple.Tuple) TexeraException(edu.uci.ics.texera.api.exception.TexeraException) PreparedStatement(java.sql.PreparedStatement) Collectors(java.util.stream.Collectors) DoubleField(edu.uci.ics.texera.api.field.DoubleField) ArrayList(java.util.ArrayList) DateField(edu.uci.ics.texera.api.field.DateField) SQLException(java.sql.SQLException) List(java.util.List) Stream(java.util.stream.Stream) SchemaConstants(edu.uci.ics.texera.api.constants.SchemaConstants) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) IField(edu.uci.ics.texera.api.field.IField) ISink(edu.uci.ics.texera.api.dataflow.ISink) ErrorMessages(edu.uci.ics.texera.api.constants.ErrorMessages) Statement(java.sql.Statement) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) AttributeType(edu.uci.ics.texera.api.schema.AttributeType) Schema(edu.uci.ics.texera.api.schema.Schema) Attribute(edu.uci.ics.texera.api.schema.Attribute) DriverManager(java.sql.DriverManager) IntegerField(edu.uci.ics.texera.api.field.IntegerField) SQLException(java.sql.SQLException) Schema(edu.uci.ics.texera.api.schema.Schema) DataflowException(edu.uci.ics.texera.api.exception.DataflowException)

Example 38 with TexeraException

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]);
}
Also used : AttributeType(edu.uci.ics.texera.api.schema.AttributeType) TexeraException(edu.uci.ics.texera.api.exception.TexeraException)

Example 39 with TexeraException

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();
}
Also used : TexeraException(edu.uci.ics.texera.api.exception.TexeraException)

Example 40 with TexeraException

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;
}
Also used : ISourceOperator(edu.uci.ics.texera.api.dataflow.ISourceOperator) IOperator(edu.uci.ics.texera.api.dataflow.IOperator) Schema(edu.uci.ics.texera.api.schema.Schema) TexeraException(edu.uci.ics.texera.api.exception.TexeraException)

Aggregations

TexeraException (edu.uci.ics.texera.api.exception.TexeraException)46 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)27 Schema (edu.uci.ics.texera.api.schema.Schema)20 IOException (java.io.IOException)20 AttributeType (edu.uci.ics.texera.api.schema.AttributeType)17 Tuple (edu.uci.ics.texera.api.tuple.Tuple)17 Attribute (edu.uci.ics.texera.api.schema.Attribute)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 ArrayList (java.util.ArrayList)10 List (java.util.List)10 ErrorMessages (edu.uci.ics.texera.api.constants.ErrorMessages)9 IField (edu.uci.ics.texera.api.field.IField)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)7 TexeraWebException (edu.uci.ics.texera.web.TexeraWebException)7 Collectors (java.util.stream.Collectors)7 SchemaConstants (edu.uci.ics.texera.api.constants.SchemaConstants)6 IOperator (edu.uci.ics.texera.api.dataflow.IOperator)6 ISink (edu.uci.ics.texera.api.dataflow.ISink)5 IntegerField (edu.uci.ics.texera.api.field.IntegerField)4 LogicalPlan (edu.uci.ics.texera.dataflow.plangen.LogicalPlan)4