Search in sources :

Example 1 with AbstractUnaryInputUnaryOutputOperatorNodePushable

use of org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable in project asterixdb by apache.

the class ExternalLookupOperatorDescriptor method createPushRuntime.

@Override
public IOperatorNodePushable createPushRuntime(final IHyracksTaskContext ctx, final IRecordDescriptorProvider recordDescProvider, final int partition, int nPartitions) throws HyracksDataException {
    // Create a file index accessor to be used for files lookup operations
    final ExternalFileIndexAccessor snapshotAccessor = new ExternalFileIndexAccessor(dataflowHelperFactory.create(ctx, partition), searchOpCallbackFactory, version);
    return new AbstractUnaryInputUnaryOutputOperatorNodePushable() {

        // The adapter that uses the file index along with the coming tuples to access files in HDFS
        private LookupAdapter<?> adapter;

        private boolean indexOpen = false;

        @Override
        public void open() throws HyracksDataException {
            try {
                adapter = adapterFactory.createAdapter(ctx, partition, recordDescProvider.getInputRecordDescriptor(getActivityId(), 0), snapshotAccessor, writer);
                // Open the file index accessor here
                snapshotAccessor.open();
                indexOpen = true;
                adapter.open();
            } catch (Throwable th) {
                throw new HyracksDataException(th);
            }
        }

        @Override
        public void close() throws HyracksDataException {
            HyracksDataException hde = null;
            if (indexOpen) {
                try {
                    snapshotAccessor.close();
                } catch (Throwable th) {
                    hde = new HyracksDataException(th);
                }
                try {
                    adapter.close();
                } catch (Throwable th) {
                    if (hde == null) {
                        hde = new HyracksDataException(th);
                    } else {
                        hde.addSuppressed(th);
                    }
                }
            }
        }

        @Override
        public void fail() throws HyracksDataException {
            try {
                adapter.fail();
            } catch (Throwable th) {
                throw new HyracksDataException(th);
            }
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            try {
                adapter.nextFrame(buffer);
            } catch (Throwable th) {
                throw new HyracksDataException(th);
            }
        }

        @Override
        public void flush() throws HyracksDataException {
            adapter.flush();
        }
    };
}
Also used : ExternalFileIndexAccessor(org.apache.asterix.external.indexing.ExternalFileIndexAccessor) AbstractUnaryInputUnaryOutputOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable) LookupAdapter(org.apache.asterix.external.dataset.adapter.LookupAdapter) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 2 with AbstractUnaryInputUnaryOutputOperatorNodePushable

use of org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable in project asterixdb by apache.

the class LimitOperatorDescriptor method createPushRuntime.

@Override
public IOperatorNodePushable createPushRuntime(final IHyracksTaskContext ctx, final IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
    return new AbstractUnaryInputUnaryOutputOperatorNodePushable() {

        private FrameTupleAccessor fta;

        private int currentSize;

        private boolean finished;

        @Override
        public void open() throws HyracksDataException {
            fta = new FrameTupleAccessor(outRecDescs[0]);
            currentSize = 0;
            finished = false;
            writer.open();
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            if (!finished) {
                fta.reset(buffer);
                int count = fta.getTupleCount();
                if ((currentSize + count) > outputLimit) {
                    FrameTupleAppender partialAppender = new FrameTupleAppender(new VSizeFrame(ctx));
                    int copyCount = outputLimit - currentSize;
                    for (int i = 0; i < copyCount; i++) {
                        FrameUtils.appendToWriter(writer, partialAppender, fta, i);
                        currentSize++;
                    }
                    partialAppender.write(writer, false);
                    finished = true;
                } else {
                    FrameUtils.flushFrame(buffer, writer);
                    currentSize += count;
                }
            }
        }

        @Override
        public void fail() throws HyracksDataException {
            writer.fail();
        }

        @Override
        public void close() throws HyracksDataException {
            writer.close();
        }

        @Override
        public void flush() throws HyracksDataException {
            writer.flush();
        }
    };
}
Also used : FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) AbstractUnaryInputUnaryOutputOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable) ByteBuffer(java.nio.ByteBuffer) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)

Example 3 with AbstractUnaryInputUnaryOutputOperatorNodePushable

use of org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable in project asterixdb by apache.

the class AlgebricksMetaOperatorDescriptor method createOneInputOneOutputPushRuntime.

private IOperatorNodePushable createOneInputOneOutputPushRuntime(final IHyracksTaskContext ctx, final IRecordDescriptorProvider recordDescProvider) {
    return new AbstractUnaryInputUnaryOutputOperatorNodePushable() {

        private IFrameWriter startOfPipeline;

        @Override
        public void open() throws HyracksDataException {
            if (startOfPipeline == null) {
                RecordDescriptor pipelineOutputRecordDescriptor = outputArity > 0 ? AlgebricksMetaOperatorDescriptor.this.outRecDescs[0] : null;
                RecordDescriptor pipelineInputRecordDescriptor = recordDescProvider.getInputRecordDescriptor(AlgebricksMetaOperatorDescriptor.this.getActivityId(), 0);
                PipelineAssembler pa = new PipelineAssembler(pipeline, inputArity, outputArity, pipelineInputRecordDescriptor, pipelineOutputRecordDescriptor);
                startOfPipeline = pa.assemblePipeline(writer, ctx);
            }
            startOfPipeline.open();
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            startOfPipeline.nextFrame(buffer);
        }

        @Override
        public void close() throws HyracksDataException {
            startOfPipeline.close();
        }

        @Override
        public void fail() throws HyracksDataException {
            startOfPipeline.fail();
        }

        @Override
        public void flush() throws HyracksDataException {
            startOfPipeline.flush();
        }

        @Override
        public String toString() {
            return AlgebricksMetaOperatorDescriptor.this.toString();
        }
    };
}
Also used : IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) AbstractUnaryInputUnaryOutputOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable) ByteBuffer(java.nio.ByteBuffer)

Aggregations

ByteBuffer (java.nio.ByteBuffer)3 AbstractUnaryInputUnaryOutputOperatorNodePushable (org.apache.hyracks.dataflow.std.base.AbstractUnaryInputUnaryOutputOperatorNodePushable)3 LookupAdapter (org.apache.asterix.external.dataset.adapter.LookupAdapter)1 ExternalFileIndexAccessor (org.apache.asterix.external.indexing.ExternalFileIndexAccessor)1 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)1 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)1 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)1 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)1