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);
}
}
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());
}
}
Aggregations