Search in sources :

Example 31 with IFrameWriter

use of org.apache.hyracks.api.comm.IFrameWriter in project asterixdb by apache.

the class FileRemoveOperatorDescriptor method createPushRuntime.

@Override
public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx, IRecordDescriptorProvider recordDescProvider, int partition, int nPartitions) throws HyracksDataException {
    final FileSplit split = fileSplitProvider.getFileSplits()[partition];
    final IIOManager ioManager = ctx.getIoManager();
    return new AbstractOperatorNodePushable() {

        @Override
        public void setOutputFrameWriter(int index, IFrameWriter writer, RecordDescriptor recordDesc) {
            throw new IllegalStateException();
        }

        @Override
        public void initialize() throws HyracksDataException {
            // will only work for files inside the io devices
            File f = split.getFile(ioManager);
            if (quietly) {
                FileUtils.deleteQuietly(f);
            } else {
                try {
                    FileUtils.deleteDirectory(f);
                } catch (IOException e) {
                    throw new HyracksDataException(e);
                }
            }
        }

        @Override
        public IFrameWriter getInputFrameWriter(int index) {
            throw new IllegalStateException();
        }

        @Override
        public int getInputArity() {
            return 0;
        }

        @Override
        public void deinitialize() throws HyracksDataException {
        }
    };
}
Also used : IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) AbstractOperatorNodePushable(org.apache.hyracks.dataflow.std.base.AbstractOperatorNodePushable) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) IOException(java.io.IOException) FileSplit(org.apache.hyracks.api.io.FileSplit) IIOManager(org.apache.hyracks.api.io.IIOManager) File(java.io.File) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 32 with IFrameWriter

use of org.apache.hyracks.api.comm.IFrameWriter in project asterixdb by apache.

the class MToNBroadcastConnectorDescriptor method createPartitioner.

@Override
public IFrameWriter createPartitioner(IHyracksTaskContext ctx, RecordDescriptor recordDesc, IPartitionWriterFactory edwFactory, int index, int nProducerPartitions, int nConsumerPartitions) throws HyracksDataException {
    final IFrameWriter[] epWriters = new IFrameWriter[nConsumerPartitions];
    final boolean[] isOpen = new boolean[nConsumerPartitions];
    for (int i = 0; i < nConsumerPartitions; ++i) {
        epWriters[i] = edwFactory.createFrameWriter(i);
    }
    return new IFrameWriter() {

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            // Record the current position, instead of using buffer.mark().
            // The latter will be problematic because epWriters[i].nextFrame(buffer)
            // can flip or clear the buffer.
            int pos = buffer.position();
            for (int i = 0; i < epWriters.length; ++i) {
                if (i != 0) {
                    buffer.position(pos);
                }
                epWriters[i].nextFrame(buffer);
            }
        }

        @Override
        public void fail() throws HyracksDataException {
            HyracksDataException failException = null;
            for (int i = 0; i < epWriters.length; ++i) {
                if (isOpen[i]) {
                    try {
                        epWriters[i].fail();
                    } catch (Throwable th) {
                        if (failException == null) {
                            failException = new HyracksDataException(th);
                        } else {
                            failException.addSuppressed(th);
                        }
                    }
                }
            }
            if (failException != null) {
                throw failException;
            }
        }

        @Override
        public void close() throws HyracksDataException {
            HyracksDataException closeException = null;
            for (int i = 0; i < epWriters.length; ++i) {
                if (isOpen[i]) {
                    try {
                        epWriters[i].close();
                    } catch (Throwable th) {
                        if (closeException == null) {
                            closeException = new HyracksDataException(th);
                        } else {
                            closeException.addSuppressed(th);
                        }
                    }
                }
            }
            if (closeException != null) {
                throw closeException;
            }
        }

        @Override
        public void open() throws HyracksDataException {
            for (int i = 0; i < epWriters.length; ++i) {
                isOpen[i] = true;
                epWriters[i].open();
            }
        }

        @Override
        public void flush() throws HyracksDataException {
            for (IFrameWriter writer : epWriters) {
                writer.flush();
            }
        }
    };
}
Also used : IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)32 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)15 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)13 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)8 ByteBuffer (java.nio.ByteBuffer)6 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)6 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)5 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)4 HyracksException (org.apache.hyracks.api.exceptions.HyracksException)4 DataOutput (java.io.DataOutput)3 InputStream (java.io.InputStream)3 IPushRuntime (org.apache.hyracks.algebricks.runtime.base.IPushRuntime)3 IFrame (org.apache.hyracks.api.comm.IFrame)3 AbstractOperatorNodePushable (org.apache.hyracks.dataflow.std.base.AbstractOperatorNodePushable)3 InputStreamReader (java.io.InputStreamReader)2 Semaphore (java.util.concurrent.Semaphore)2 ExternalFile (org.apache.asterix.external.indexing.ExternalFile)2