Search in sources :

Example 21 with FrameTupleAccessor

use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.

the class SubplanRuntimeFactory method createOneOutputPushRuntime.

@Override
public AbstractOneInputOneOutputPushRuntime createOneOutputPushRuntime(final IHyracksTaskContext ctx) throws HyracksDataException {
    RecordDescriptor pipelineOutputRecordDescriptor = null;
    final PipelineAssembler pa = new PipelineAssembler(pipeline, 1, 1, inputRecordDesc, pipelineOutputRecordDescriptor);
    final IMissingWriter[] nullWriters = new IMissingWriter[missingWriterFactories.length];
    for (int i = 0; i < missingWriterFactories.length; i++) {
        nullWriters[i] = missingWriterFactories[i].createMissingWriter();
    }
    return new AbstractOneInputOneOutputOneFramePushRuntime() {

        /**
             * Computes the outer product between a given tuple and the frames
             * passed.
             */
        class TupleOuterProduct implements IFrameWriter {

            private boolean smthWasWritten = false;

            private FrameTupleAccessor ta = new FrameTupleAccessor(pipeline.getRecordDescriptors()[pipeline.getRecordDescriptors().length - 1]);

            private ArrayTupleBuilder tb = new ArrayTupleBuilder(nullWriters.length);

            @Override
            public void open() throws HyracksDataException {
                smthWasWritten = false;
            }

            @Override
            public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
                ta.reset(buffer);
                int nTuple = ta.getTupleCount();
                for (int t = 0; t < nTuple; t++) {
                    appendConcat(tRef.getFrameTupleAccessor(), tRef.getTupleIndex(), ta, t);
                }
                smthWasWritten = true;
            }

            @Override
            public void close() throws HyracksDataException {
                if (!smthWasWritten) {
                    // the case when we need to write nulls
                    appendNullsToTuple();
                    appendToFrameFromTupleBuilder(tb);
                }
            }

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

            private void appendNullsToTuple() throws HyracksDataException {
                tb.reset();
                int n0 = tRef.getFieldCount();
                for (int f = 0; f < n0; f++) {
                    tb.addField(tRef.getFrameTupleAccessor(), tRef.getTupleIndex(), f);
                }
                DataOutput dos = tb.getDataOutput();
                for (int i = 0; i < nullWriters.length; i++) {
                    nullWriters[i].writeMissing(dos);
                    tb.addFieldEndOffset();
                }
            }
        }

        IFrameWriter endPipe = new TupleOuterProduct();

        NestedTupleSourceRuntime startOfPipeline = (NestedTupleSourceRuntime) pa.assemblePipeline(endPipe, ctx);

        boolean first = true;

        @Override
        public void open() throws HyracksDataException {
            writer.open();
            if (first) {
                first = false;
                initAccessAppendRef(ctx);
            }
        }

        @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);
                startOfPipeline.writeTuple(buffer, t);
                try {
                    startOfPipeline.open();
                } catch (Exception e) {
                    startOfPipeline.fail();
                    throw e;
                } finally {
                    startOfPipeline.close();
                }
            }
        }

        @Override
        public void flush() throws HyracksDataException {
            writer.flush();
        }
    };
}
Also used : DataOutput(java.io.DataOutput) IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) RecordDescriptor(org.apache.hyracks.api.dataflow.value.RecordDescriptor) AbstractOneInputOneOutputOneFramePushRuntime(org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputOneFramePushRuntime) NestedTupleSourceRuntime(org.apache.hyracks.algebricks.runtime.operators.std.NestedTupleSourceRuntimeFactory.NestedTupleSourceRuntime) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) ByteBuffer(java.nio.ByteBuffer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) NotImplementedException(org.apache.hyracks.algebricks.common.exceptions.NotImplementedException) IMissingWriter(org.apache.hyracks.api.dataflow.value.IMissingWriter) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)

Example 22 with FrameTupleAccessor

use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.

the class AbstractOneInputOneOutputOneFieldFramePushRuntime method initAccessAppendFieldRef.

protected final void initAccessAppendFieldRef(IHyracksTaskContext ctx) throws HyracksDataException {
    frame = new VSizeFrame(ctx);
    appender = new FrameFixedFieldTupleAppender(inputRecordDesc.getFieldCount());
    appender.reset(frame, true);
    tAccess = new FrameTupleAccessor(inputRecordDesc);
    tRef = new FrameTupleReference();
}
Also used : FrameFixedFieldTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameFixedFieldTupleAppender) FrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor)

Example 23 with FrameTupleAccessor

use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.

the class AbstractOneInputOneOutputOneFramePushRuntime method initAccessAppend.

protected final void initAccessAppend(IHyracksTaskContext ctx) throws HyracksDataException {
    frame = new VSizeFrame(ctx);
    appender = new FrameTupleAppender(frame);
    tAccess = new FrameTupleAccessor(inputRecordDesc);
}
Also used : FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) IFrameTupleAppender(org.apache.hyracks.api.comm.IFrameTupleAppender) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor)

Example 24 with FrameTupleAccessor

use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.

the class RunMergingFrameReaderTest method assertFrameIsSorted.

private void assertFrameIsSorted(IFrame frame, List<Map<Integer, String>> keyValueMapList) throws HyracksDataException {
    FrameTupleAccessor fta = new FrameTupleAccessor(RecordDesc);
    ByteBufferInputStream bbis = new ByteBufferInputStream();
    DataInputStream di = new DataInputStream(bbis);
    fta.reset(frame.getBuffer());
    //        fta.prettyPrint();
    int preKey = Integer.MIN_VALUE;
    for (int i = 0; i < fta.getTupleCount(); i++) {
        bbis.setByteBuffer(fta.getBuffer(), fta.getTupleStartOffset(i) + fta.getFieldStartOffset(i, 0) + fta.getFieldSlotsLength());
        int key = (int) RecordDesc.getFields()[0].deserialize(di);
        bbis.setByteBuffer(fta.getBuffer(), fta.getTupleStartOffset(i) + fta.getFieldStartOffset(i, 1) + fta.getFieldSlotsLength());
        String value = (String) RecordDesc.getFields()[1].deserialize(di);
        boolean found = false;
        for (Map<Integer, String> map : keyValueMapList) {
            if (map.containsKey(key) && map.get(key).equals(value)) {
                found = true;
                map.remove(key);
                break;
            }
        }
        assertTrue(found);
        assertTrue(preKey <= key);
        preKey = key;
    }
}
Also used : ByteBufferInputStream(org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream) DataInputStream(java.io.DataInputStream) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)

Example 25 with FrameTupleAccessor

use of org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor in project asterixdb by apache.

the class BinaryTokenizerOperatorNodePushable method open.

@Override
public void open() throws HyracksDataException {
    writer.open();
    accessor = new FrameTupleAccessor(inputRecDesc);
    builder = new ArrayTupleBuilder(outputRecDesc.getFieldCount());
    builderData = builder.getFieldData();
    appender = new FrameTupleAppender(new VSizeFrame(ctx), true);
}
Also used : FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)

Aggregations

FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)35 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)18 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)15 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)14 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)12 FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)11 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)8 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)7 DataOutput (java.io.DataOutput)6 IOException (java.io.IOException)6 ByteBuffer (java.nio.ByteBuffer)6 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)6 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 FeedRuntimeInputHandler (org.apache.asterix.external.feed.dataflow.FeedRuntimeInputHandler)4 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)4 ITuplePartitionComputerFactory (org.apache.hyracks.api.dataflow.value.ITuplePartitionComputerFactory)4 IConnectorDescriptorRegistry (org.apache.hyracks.api.job.IConnectorDescriptorRegistry)4 TestFrameWriter (org.apache.hyracks.api.test.TestFrameWriter)4