Search in sources :

Example 21 with FrameTupleAppender

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

the class IndexSearchOperatorNodePushable method open.

@Override
public void open() throws HyracksDataException {
    writer.open();
    indexHelper.open();
    index = indexHelper.getIndexInstance();
    accessor = new FrameTupleAccessor(inputRecDesc);
    if (retainMissing) {
        int fieldCount = getFieldCount();
        nonMatchTupleBuild = new ArrayTupleBuilder(fieldCount);
        buildMissingTuple(fieldCount, nonMatchTupleBuild, nonMatchWriter);
    } else {
        nonMatchTupleBuild = null;
    }
    if (appendIndexFilter) {
        int numIndexFilterFields = index.getNumOfFilterFields();
        nonFilterTupleBuild = new ArrayTupleBuilder(numIndexFilterFields);
        buildMissingTuple(numIndexFilterFields, nonFilterTupleBuild, nonMatchWriter);
    }
    try {
        searchPred = createSearchPredicate();
        tb = new ArrayTupleBuilder(recordDesc.getFieldCount());
        dos = tb.getDataOutput();
        appender = new FrameTupleAppender(new VSizeFrame(ctx), true);
        ISearchOperationCallback searchCallback = searchCallbackFactory.createSearchOperationCallback(indexHelper.getResource().getId(), ctx, null);
        indexAccessor = index.createAccessor(NoOpOperationCallback.INSTANCE, searchCallback);
        cursor = createCursor();
        if (retainInput) {
            frameTuple = new FrameTupleReference();
        }
    } catch (Exception e) {
        throw new HyracksDataException(e);
    }
}
Also used : FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) FrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference) PermutingFrameTupleReference(org.apache.hyracks.storage.am.common.tuples.PermutingFrameTupleReference) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) ISearchOperationCallback(org.apache.hyracks.storage.common.ISearchOperationCallback) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)

Example 22 with FrameTupleAppender

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

the class FramewriterTest method setUp.

@Before
public void setUp() throws Exception {
    // Mock static methods
    PowerMockito.mockStatic(BTreeUtils.class);
    PowerMockito.when(BTreeUtils.getSearchMultiComparator(Matchers.any(), Matchers.any())).thenReturn(mockMultiComparator());
    PowerMockito.mockStatic(FrameUtils.class);
    // Custom implementation for FrameUtils that push to next frame immediately
    PowerMockito.when(FrameUtils.appendToWriter(Matchers.any(IFrameWriter.class), Matchers.any(IFrameTupleAppender.class), Matchers.any(IFrameTupleAccessor.class), Matchers.anyInt(), Matchers.anyInt())).thenAnswer(new Answer<Integer>() {

        @Override
        public Integer answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            IFrameWriter writer = (IFrameWriter) args[0];
            writer.nextFrame(EMPTY_BUFFER);
            return BUFFER_SIZE;
        }
    });
    // create global mock for FrameTupleAccessor, ArrayTupleBuilder
    FrameTupleAccessor frameAccessor = Mockito.mock(FrameTupleAccessor.class);
    Mockito.when(frameAccessor.getTupleCount()).thenReturn(RECORDS_PER_FRAME);
    // Global custom implementations for FrameTupleAppender
    // since we have two appenders, then we need to test each test twice
    FrameTupleAppender[] appenders = mockAppenders();
    // Mock all instances of a class <Note that you need to prepare the class calling this constructor as well>
    PowerMockito.whenNew(FrameTupleAccessor.class).withAnyArguments().thenReturn(frameAccessor);
    PowerMockito.whenNew(FrameTupleAppender.class).withAnyArguments().thenAnswer(new Answer<FrameTupleAppender>() {

        @Override
        public FrameTupleAppender answer(InvocationOnMock invocation) throws Throwable {
            counter++;
            if (counter % 2 == 1) {
                return appenders[0];
            }
            return appenders[1];
        }
    });
}
Also used : IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) IFrameTupleAppender(org.apache.hyracks.api.comm.IFrameTupleAppender) IFrameTupleAppender(org.apache.hyracks.api.comm.IFrameTupleAppender) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) Before(org.junit.Before)

Example 23 with FrameTupleAppender

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

the class AbstractTupleMemoryManagerTest method prepareFixedSizeTuples.

protected Map<Integer, Integer> prepareFixedSizeTuples(int tuplePerFrame, int extraMetaBytePerFrame, int extraMetaBytePerRecord) throws HyracksDataException {
    Map<Integer, Integer> dataSet = new HashMap<>();
    ByteBuffer buffer = ByteBuffer.allocate(Common.BUDGET);
    FixedSizeFrame frame = new FixedSizeFrame(buffer);
    FrameTupleAppender appender = new FrameTupleAppender();
    appender.reset(frame, true);
    int sizePerTuple = (Common.MIN_FRAME_SIZE - 1 - tuplePerFrame * 4 - 4 - extraMetaBytePerFrame) / tuplePerFrame;
    int sizeChar = //2byte to write str length
    sizePerTuple - extraMetaBytePerRecord - fieldsSerDer.length * 4 - 4 - 2;
    assert (sizeChar > 0);
    for (int i = 0; i < Common.NUM_MIN_FRAME * tuplePerFrame; i++) {
        tupleBuilder.reset();
        tupleBuilder.addField(fieldsSerDer[0], i);
        tupleBuilder.addField(fieldsSerDer[1], Utility.repeatString('a', sizeChar));
        if (!appender.append(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray(), 0, tupleBuilder.getSize())) {
            assert false;
        }
        dataSet.put(i, tupleBuilder.getSize() + tupleBuilder.getFieldEndOffsets().length * 4);
    }
    inFTA.reset(buffer);
    return dataSet;
}
Also used : HashMap(java.util.HashMap) FixedSizeFrame(org.apache.hyracks.api.comm.FixedSizeFrame) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) ByteBuffer(java.nio.ByteBuffer)

Example 24 with FrameTupleAppender

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

the class LSMPrimaryUpsertOperatorNodePushable method open.

// we have the permutation which has [pk locations, record location, optional:filter-location]
// the index -> we don't need anymore data?
// we need to use the primary index opTracker and secondary indexes callbacks for insert/delete since the lock would
// have been obtained through searchForUpsert operation
@Override
public void open() throws HyracksDataException {
    accessor = new FrameTupleAccessor(inputRecDesc);
    writeBuffer = new VSizeFrame(ctx);
    writer.open();
    indexHelper.open();
    index = indexHelper.getIndexInstance();
    try {
        if (ctx.getSharedObject() != null) {
            PrimaryIndexLogMarkerCallback callback = new PrimaryIndexLogMarkerCallback((AbstractLSMIndex) index);
            TaskUtil.putInSharedMap(ILogMarkerCallback.KEY_MARKER_CALLBACK, callback, ctx);
        }
        missingTupleBuilder = new ArrayTupleBuilder(1);
        DataOutput out = missingTupleBuilder.getDataOutput();
        try {
            missingWriter.writeMissing(out);
        } catch (IOException e) {
            throw new HyracksDataException(e);
        }
        missingTupleBuilder.addFieldEndOffset();
        searchPred = createSearchPredicate();
        tb = new ArrayTupleBuilder(recordDesc.getFieldCount());
        dos = tb.getDataOutput();
        appender = new FrameTupleAppender(new VSizeFrame(ctx), true);
        modCallback = modOpCallbackFactory.createModificationOperationCallback(indexHelper.getResource(), ctx, this);
        abstractModCallback = (AbstractIndexModificationOperationCallback) modCallback;
        searchCallback = (LockThenSearchOperationCallback) searchCallbackFactory.createSearchOperationCallback(indexHelper.getResource().getId(), ctx, this);
        indexAccessor = index.createAccessor(abstractModCallback, searchCallback);
        lsmAccessor = (LSMTreeIndexAccessor) indexAccessor;
        cursor = indexAccessor.createSearchCursor(false);
        frameTuple = new FrameTupleReference();
        INcApplicationContext appCtx = (INcApplicationContext) ctx.getJobletContext().getServiceContext().getApplicationContext();
        LSMIndexUtil.checkAndSetFirstLSN((AbstractLSMIndex) index, appCtx.getTransactionSubsystem().getLogManager());
        frameOpCallback = new IFrameOperationCallback() {

            IFrameOperationCallback callback = frameOpCallbackFactory.createFrameOperationCallback(ctx, (ILSMIndexAccessor) indexAccessor);

            @Override
            public void frameCompleted() throws HyracksDataException {
                callback.frameCompleted();
                appender.write(writer, true);
            }
        };
    } catch (Exception e) {
        indexHelper.close();
        throw new HyracksDataException(e);
    }
}
Also used : DataOutput(java.io.DataOutput) INcApplicationContext(org.apache.asterix.common.api.INcApplicationContext) FrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference) PermutingFrameTupleReference(org.apache.hyracks.storage.am.common.tuples.PermutingFrameTupleReference) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) IOException(java.io.IOException) PrimaryIndexLogMarkerCallback(org.apache.asterix.common.transactions.PrimaryIndexLogMarkerCallback) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ACIDException(org.apache.asterix.common.exceptions.ACIDException) IOException(java.io.IOException) IFrameOperationCallback(org.apache.hyracks.storage.am.lsm.common.api.IFrameOperationCallback) FrameTupleAppender(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender) FrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)

Example 25 with FrameTupleAppender

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

the class EmptyTupleSourceRuntimeFactory method createPushRuntime.

@Override
public IPushRuntime createPushRuntime(final IHyracksTaskContext ctx) throws HyracksDataException {
    return new AbstractOneInputSourcePushRuntime() {

        private final ArrayTupleBuilder tb = new ArrayTupleBuilder(0);

        private final FrameTupleAppender appender = new FrameTupleAppender(new VSizeFrame(ctx));

        @Override
        public void open() throws HyracksDataException {
            writer.open();
            if (!appender.append(tb.getFieldEndOffsets(), tb.getByteArray(), 0, tb.getSize())) {
                throw new IllegalStateException();
            }
            appender.write(writer, true);
        }

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

        @Override
        public void flush() throws HyracksDataException {
            appender.flush(writer);
        }
    };
}
Also used : AbstractOneInputSourcePushRuntime(org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputSourcePushRuntime) 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)

Aggregations

FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)42 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)32 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)17 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)15 FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)14 DataOutput (java.io.DataOutput)10 IFrame (org.apache.hyracks.api.comm.IFrame)8 ByteBuffer (java.nio.ByteBuffer)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 FixedSizeFrame (org.apache.hyracks.api.comm.FixedSizeFrame)6 IFrameTupleAppender (org.apache.hyracks.api.comm.IFrameTupleAppender)6 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)6 FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)6 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)5 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)5 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)4