Search in sources :

Example 6 with Tuple

use of edu.uci.ics.texera.workflow.common.tuple.Tuple in project textdb by TextDB.

the class PythonUDFOpExec method processTexeraTuple.

@Override
public Iterator<Tuple> processTexeraTuple(Either<Tuple, InputExhausted> tuple, LinkIdentity input) {
    if (tuple.isLeft()) {
        Tuple inputTuple = tuple.left().get();
        if (globalInputSchema == null) {
            try {
                globalInputSchema = ArrowUtils.fromTexeraSchema(inputTuple.getSchema());
            } catch (RuntimeException exception) {
                closeAndThrow(flightClient, exception);
            }
        }
        inputTupleBuffer.add(inputTuple);
        if (inputTupleBuffer.size() == batchSize) {
            // This batch is full, execute the UDF.
            return processOneBatch(false);
        } else {
            return JavaConverters.asScalaIterator(Collections.emptyIterator());
        }
    } else {
        // There might be some unprocessed tuples, finish them.
        return processOneBatch(true);
    }
}
Also used : Tuple(edu.uci.ics.texera.workflow.common.tuple.Tuple)

Example 7 with Tuple

use of edu.uci.ics.texera.workflow.common.tuple.Tuple in project textdb by TextDB.

the class PieChartOpPartialExec method processTexeraTuple.

@Override
public Iterator<Tuple> processTexeraTuple(Either<Tuple, InputExhausted> tuple, LinkIdentity input) {
    if (tuple.isLeft()) {
        Tuple inputTuple = tuple.left().get();
        String name = inputTuple.getField(nameColumn);
        Double data;
        if (inputTuple.getSchema().getAttribute(dataColumn).getType() == AttributeType.STRING) {
            data = Double.parseDouble(inputTuple.getField(dataColumn));
        } else if (inputTuple.getSchema().getAttribute(dataColumn).getType() == AttributeType.INTEGER) {
            data = Double.parseDouble(Integer.toString(inputTuple.getField(dataColumn)));
        } else {
            data = inputTuple.getField(dataColumn);
        }
        Schema oldSchema = tuple.left().get().getSchema();
        Attribute dataAttribute = new Attribute(oldSchema.getAttribute(dataColumn).getName(), oldSchema.getAttribute(dataColumn).getType());
        Schema newSchema = new Schema(Arrays.asList(oldSchema.getAttribute(nameColumn), dataAttribute));
        if (noDataCol) {
            result.add(Tuple.newBuilder(newSchema).addSequentially(new Object[] { name, data.intValue() }).build());
        } else {
            result.add(Tuple.newBuilder(newSchema).addSequentially(new Object[] { name, data }).build());
        }
        return JavaConverters.asScalaIterator(Collections.emptyIterator());
    } else {
        result.sort((left, right) -> {
            double leftValue;
            double rightValue;
            if (noDataCol) {
                leftValue = left.getInt(1);
                rightValue = right.getInt(1);
            } else {
                leftValue = left.getDouble(1);
                rightValue = right.getDouble(1);
            }
            return Double.compare(rightValue, leftValue);
        });
        return JavaConverters.asScalaIterator(result.iterator());
    }
}
Also used : Attribute(edu.uci.ics.texera.workflow.common.tuple.schema.Attribute) Schema(edu.uci.ics.texera.workflow.common.tuple.schema.Schema) Tuple(edu.uci.ics.texera.workflow.common.tuple.Tuple)

Aggregations

Tuple (edu.uci.ics.texera.workflow.common.tuple.Tuple)7 Attribute (edu.uci.ics.texera.workflow.common.tuple.schema.Attribute)3 Schema (edu.uci.ics.texera.workflow.common.tuple.schema.Schema)3 StringReader (java.io.StringReader)1 TokenStream (org.apache.lucene.analysis.TokenStream)1 OffsetAttribute (org.apache.lucene.analysis.tokenattributes.OffsetAttribute)1