use of org.apache.hyracks.algebricks.data.IBinaryBooleanInspector in project asterixdb by apache.
the class StreamSelectRuntimeFactory method createOneOutputPushRuntime.
@Override
public AbstractOneInputOneOutputOneFramePushRuntime createOneOutputPushRuntime(final IHyracksTaskContext ctx) {
final IBinaryBooleanInspector bbi = binaryBooleanInspectorFactory.createBinaryBooleanInspector(ctx);
return new AbstractOneInputOneOutputOneFieldFramePushRuntime() {
private IPointable p = VoidPointable.FACTORY.createPointable();
private IScalarEvaluator eval;
private IMissingWriter missingWriter = null;
private ArrayTupleBuilder missingTupleBuilder = null;
private boolean isOpen = false;
@Override
public void open() throws HyracksDataException {
if (eval == null) {
initAccessAppendFieldRef(ctx);
eval = cond.createScalarEvaluator(ctx);
}
isOpen = true;
writer.open();
//prepare nullTupleBuilder
if (retainMissing && missingWriter == null) {
missingWriter = missingWriterFactory.createMissingWriter();
missingTupleBuilder = new ArrayTupleBuilder(1);
DataOutput out = missingTupleBuilder.getDataOutput();
missingWriter.writeMissing(out);
missingTupleBuilder.addFieldEndOffset();
}
}
@Override
public void fail() throws HyracksDataException {
if (isOpen) {
super.fail();
}
}
@Override
public void close() throws HyracksDataException {
if (isOpen) {
try {
flushIfNotFailed();
} finally {
writer.close();
}
}
}
@Override
public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
tAccess.reset(buffer);
int nTuple = tAccess.getTupleCount();
for (int t = 0; t < nTuple; t++) {
tRef.reset(tAccess, t);
eval.evaluate(tRef, p);
if (bbi.getBooleanValue(p.getByteArray(), p.getStartOffset(), p.getLength())) {
if (projectionList != null) {
appendProjectionToFrame(t, projectionList);
} else {
appendTupleToFrame(t);
}
} else {
if (retainMissing) {
for (int i = 0; i < tRef.getFieldCount(); i++) {
if (i == missingPlaceholderVariableIndex) {
appendField(missingTupleBuilder.getByteArray(), 0, missingTupleBuilder.getSize());
} else {
appendField(tAccess, t, i);
}
}
}
}
}
}
@Override
public void flush() throws HyracksDataException {
appender.flush(writer);
}
};
}
Aggregations