Search in sources :

Example 1 with AbstractOneInputOneOutputOneFieldFramePushRuntime

use of org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputOneFieldFramePushRuntime 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);
        }
    };
}
Also used : IMissingWriter(org.apache.hyracks.api.dataflow.value.IMissingWriter) DataOutput(java.io.DataOutput) IBinaryBooleanInspector(org.apache.hyracks.algebricks.data.IBinaryBooleanInspector) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) IPointable(org.apache.hyracks.data.std.api.IPointable) AbstractOneInputOneOutputOneFieldFramePushRuntime(org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputOneFieldFramePushRuntime) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ByteBuffer(java.nio.ByteBuffer)

Aggregations

DataOutput (java.io.DataOutput)1 ByteBuffer (java.nio.ByteBuffer)1 IBinaryBooleanInspector (org.apache.hyracks.algebricks.data.IBinaryBooleanInspector)1 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)1 AbstractOneInputOneOutputOneFieldFramePushRuntime (org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputOneFieldFramePushRuntime)1 IMissingWriter (org.apache.hyracks.api.dataflow.value.IMissingWriter)1 IPointable (org.apache.hyracks.data.std.api.IPointable)1 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)1