Search in sources :

Example 1 with IFrameTupleAccessor

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

the class FieldHashPartitionComputerFamily method createPartitioner.

@Override
public ITuplePartitionComputer createPartitioner(int seed) {
    final IBinaryHashFunction[] hashFunctions = new IBinaryHashFunction[hashFunctionGeneratorFactories.length];
    for (int i = 0; i < hashFunctionGeneratorFactories.length; ++i) {
        hashFunctions[i] = hashFunctionGeneratorFactories[i].createBinaryHashFunction(seed);
    }
    return new ITuplePartitionComputer() {

        @Override
        public int partition(IFrameTupleAccessor accessor, int tIndex, int nParts) throws HyracksDataException {
            int h = 0;
            int startOffset = accessor.getTupleStartOffset(tIndex);
            int slotLength = accessor.getFieldSlotsLength();
            for (int j = 0; j < hashFields.length; ++j) {
                int fIdx = hashFields[j];
                IBinaryHashFunction hashFn = hashFunctions[j];
                int fStart = accessor.getFieldStartOffset(tIndex, fIdx);
                int fEnd = accessor.getFieldEndOffset(tIndex, fIdx);
                int fh = hashFn.hash(accessor.getBuffer().array(), startOffset + slotLength + fStart, fEnd - fStart);
                h += fh;
            }
            if (h < 0) {
                h = -(h + 1);
            }
            return h % nParts;
        }
    };
}
Also used : IBinaryHashFunction(org.apache.hyracks.api.dataflow.value.IBinaryHashFunction) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) ITuplePartitionComputer(org.apache.hyracks.api.dataflow.value.ITuplePartitionComputer)

Example 2 with IFrameTupleAccessor

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

the class FrameFixedFieldTupleAppenderTest method testAppendLargeFieldShouldSucceed.

@Test
public void testAppendLargeFieldShouldSucceed() throws HyracksDataException {
    IFrameTupleAccessor accessor = prepareData(DATA_TYPE.ONE_FIELD_LONG);
    testProcess(accessor);
}
Also used : IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) Test(org.junit.Test)

Example 3 with IFrameTupleAccessor

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

the class AbstractIntegrationTest method readResults.

protected List<String> readResults(JobSpecification spec, JobId jobId, ResultSetId resultSetId) throws Exception {
    int nReaders = 1;
    IFrameTupleAccessor frameTupleAccessor = new ResultFrameTupleAccessor();
    IHyracksDataset hyracksDataset = new HyracksDataset(hcc, spec.getFrameSize(), nReaders);
    IHyracksDatasetReader reader = hyracksDataset.createReader(jobId, resultSetId);
    List<String> resultRecords = new ArrayList<>();
    ByteBufferInputStream bbis = new ByteBufferInputStream();
    FrameManager resultDisplayFrameMgr = new FrameManager(spec.getFrameSize());
    VSizeFrame frame = new VSizeFrame(resultDisplayFrameMgr);
    int readSize = reader.read(frame);
    while (readSize > 0) {
        try {
            frameTupleAccessor.reset(frame.getBuffer());
            for (int tIndex = 0; tIndex < frameTupleAccessor.getTupleCount(); tIndex++) {
                int start = frameTupleAccessor.getTupleStartOffset(tIndex);
                int length = frameTupleAccessor.getTupleEndOffset(tIndex) - start;
                bbis.setByteBuffer(frame.getBuffer(), start);
                byte[] recordBytes = new byte[length];
                bbis.read(recordBytes, 0, length);
                resultRecords.add(new String(recordBytes, 0, length));
            }
        } finally {
            bbis.close();
        }
        readSize = reader.read(frame);
    }
    return resultRecords;
}
Also used : ArrayList(java.util.ArrayList) ByteBufferInputStream(org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream) VSizeFrame(org.apache.hyracks.api.comm.VSizeFrame) HyracksDataset(org.apache.hyracks.client.dataset.HyracksDataset) IHyracksDataset(org.apache.hyracks.api.dataset.IHyracksDataset) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) FrameManager(org.apache.hyracks.control.nc.resources.memory.FrameManager) ResultFrameTupleAccessor(org.apache.hyracks.dataflow.common.comm.io.ResultFrameTupleAccessor) IHyracksDatasetReader(org.apache.hyracks.api.dataset.IHyracksDatasetReader) IHyracksDataset(org.apache.hyracks.api.dataset.IHyracksDataset)

Example 4 with IFrameTupleAccessor

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

the class RunMergingFrameReader method createEntryComparator.

private Comparator<ReferenceEntry> createEntryComparator(final IBinaryComparator[] comparators) {
    return new Comparator<ReferenceEntry>() {

        public int compare(ReferenceEntry tp1, ReferenceEntry tp2) {
            int nmk1 = tp1.getNormalizedKey();
            int nmk2 = tp2.getNormalizedKey();
            if (nmk1 != nmk2) {
                return ((((long) nmk1) & 0xffffffffL) < (((long) nmk2) & 0xffffffffL)) ? -1 : 1;
            }
            IFrameTupleAccessor fta1 = tp1.getAccessor();
            IFrameTupleAccessor fta2 = tp2.getAccessor();
            byte[] b1 = fta1.getBuffer().array();
            byte[] b2 = fta2.getBuffer().array();
            int[] tPointers1 = tp1.getTPointers();
            int[] tPointers2 = tp2.getTPointers();
            for (int f = 0; f < sortFields.length; ++f) {
                int c;
                try {
                    c = comparators[f].compare(b1, tPointers1[2 * f + 1], tPointers1[2 * f + 2], b2, tPointers2[2 * f + 1], tPointers2[2 * f + 2]);
                    if (c != 0) {
                        return c;
                    }
                } catch (HyracksDataException e) {
                    throw new IllegalArgumentException(e);
                }
            }
            int runid1 = tp1.getRunid();
            int runid2 = tp2.getRunid();
            return runid1 < runid2 ? -1 : (runid1 == runid2 ? 0 : 1);
        }
    };
}
Also used : ReferenceEntry(org.apache.hyracks.dataflow.std.util.ReferenceEntry) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) Comparator(java.util.Comparator) IBinaryComparator(org.apache.hyracks.api.dataflow.value.IBinaryComparator)

Example 5 with IFrameTupleAccessor

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

the class RunMergingFrameReader method nextFrame.

@Override
public boolean nextFrame(IFrame outFrame) throws HyracksDataException {
    outFrameAppender.reset(outFrame, true);
    while (!topTuples.areRunsExhausted() && tupleCount < topK) {
        ReferenceEntry top = topTuples.peek();
        int runIndex = top.getRunid();
        IFrameTupleAccessor fta = top.getAccessor();
        int tupleIndex = top.getTupleIndex();
        if (!outFrameAppender.append(fta, tupleIndex)) {
            return true;
        } else {
            tupleCount++;
        }
        ++tupleIndexes[runIndex];
        setNextTopTuple(runIndex, tupleIndexes, runCursors, inFrames, tupleAccessors, topTuples);
    }
    if (outFrameAppender.getTupleCount() > 0) {
        return true;
    }
    return false;
}
Also used : ReferenceEntry(org.apache.hyracks.dataflow.std.util.ReferenceEntry) IFrameTupleAccessor(org.apache.hyracks.api.comm.IFrameTupleAccessor)

Aggregations

IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)31 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)12 AggregateState (org.apache.hyracks.dataflow.std.group.AggregateState)11 DataOutput (java.io.DataOutput)10 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)10 IOException (java.io.IOException)8 ByteBuffer (java.nio.ByteBuffer)8 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)7 IFieldAggregateDescriptor (org.apache.hyracks.dataflow.std.group.IFieldAggregateDescriptor)7 FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)6 IAggregatorDescriptor (org.apache.hyracks.dataflow.std.group.IAggregatorDescriptor)5 FrameTupleAccessor (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAccessor)4 FrameTupleAppender (org.apache.hyracks.dataflow.common.comm.io.FrameTupleAppender)4 IFrame (org.apache.hyracks.api.comm.IFrame)3 ITuplePartitionComputer (org.apache.hyracks.api.dataflow.value.ITuplePartitionComputer)3 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)3 FrameManager (org.apache.hyracks.control.nc.resources.memory.FrameManager)3 IPointable (org.apache.hyracks.data.std.api.IPointable)3 ByteBufferInputStream (org.apache.hyracks.dataflow.common.comm.util.ByteBufferInputStream)3 Test (org.junit.Test)3