Search in sources :

Example 76 with IPointable

use of org.apache.hyracks.data.std.api.IPointable in project asterixdb by apache.

the class IntegerAddEvalFactory method createScalarEvaluator.

@Override
public IScalarEvaluator createScalarEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
    return new IScalarEvaluator() {

        private IPointable p = VoidPointable.FACTORY.createPointable();

        private ArrayBackedValueStorage argOut = new ArrayBackedValueStorage();

        private IScalarEvaluator evalLeft = evalLeftFactory.createScalarEvaluator(ctx);

        private IScalarEvaluator evalRight = evalRightFactory.createScalarEvaluator(ctx);

        @Override
        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            evalLeft.evaluate(tuple, p);
            int v1 = IntegerPointable.getInteger(p.getByteArray(), p.getStartOffset());
            evalRight.evaluate(tuple, p);
            int v2 = IntegerPointable.getInteger(p.getByteArray(), p.getStartOffset());
            try {
                argOut.reset();
                argOut.getDataOutput().writeInt(v1 + v2);
                result.set(argOut);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 77 with IPointable

use of org.apache.hyracks.data.std.api.IPointable in project asterixdb by apache.

the class TupleCountAggregateFunctionFactory method createAggregateEvaluator.

@Override
public IAggregateEvaluator createAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
    final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    return new IAggregateEvaluator() {

        int cnt;

        @Override
        public void step(IFrameTupleReference tuple) throws HyracksDataException {
            ++cnt;
        }

        @Override
        public void init() throws HyracksDataException {
            cnt = 0;
        }

        @Override
        public void finish(IPointable result) throws HyracksDataException {
            try {
                abvs.reset();
                abvs.getDataOutput().writeInt(cnt);
                result.set(abvs);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void finishPartial(IPointable result) throws HyracksDataException {
            finish(result);
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 78 with IPointable

use of org.apache.hyracks.data.std.api.IPointable in project asterixdb by apache.

the class TupleCountRunningAggregateFunctionFactory method createRunningAggregateEvaluator.

@Override
public IRunningAggregateEvaluator createRunningAggregateEvaluator(IHyracksTaskContext ctx) throws HyracksDataException {
    final ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    return new IRunningAggregateEvaluator() {

        int cnt;

        @Override
        public void step(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            try {
                ++cnt;
                abvs.reset();
                abvs.getDataOutput().writeInt(cnt);
                result.set(abvs);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void init() throws HyracksDataException {
            cnt = 0;
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IRunningAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IRunningAggregateEvaluator) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 79 with IPointable

use of org.apache.hyracks.data.std.api.IPointable in project asterixdb by apache.

the class StreamLimitRuntimeFactory method createOneOutputPushRuntime.

@Override
public AbstractOneInputOneOutputOneFramePushRuntime createOneOutputPushRuntime(final IHyracksTaskContext ctx) {
    final IBinaryIntegerInspector bii = binaryIntegerInspectorFactory.createBinaryIntegerInspector(ctx);
    return new AbstractOneInputOneOutputOneFramePushRuntime() {

        private final IPointable p = VoidPointable.FACTORY.createPointable();

        private IScalarEvaluator evalMaxObjects;

        private IScalarEvaluator evalOffset = null;

        // how many tuples still to write
        private int toWrite = 0;

        // how many tuples still to skip
        private int toSkip = 0;

        private boolean firstTuple = true;

        private boolean afterLastTuple = false;

        @Override
        public void open() throws HyracksDataException {
            writer.open();
            if (evalMaxObjects == null) {
                initAccessAppendRef(ctx);
                evalMaxObjects = maxObjectsEvalFactory.createScalarEvaluator(ctx);
                if (offsetEvalFactory != null) {
                    evalOffset = offsetEvalFactory.createScalarEvaluator(ctx);
                }
            }
            afterLastTuple = false;
        }

        @Override
        public void nextFrame(ByteBuffer buffer) throws HyracksDataException {
            if (afterLastTuple) {
                return;
            }
            tAccess.reset(buffer);
            int nTuple = tAccess.getTupleCount();
            int start = 0;
            if (nTuple <= toSkip) {
                toSkip -= nTuple;
                return;
            } else if (toSkip > 0) {
                start = toSkip;
                toSkip = 0;
            }
            for (int t = start; t < nTuple; t++) {
                if (firstTuple) {
                    firstTuple = false;
                    toWrite = evaluateInteger(evalMaxObjects, t);
                    if (evalOffset != null) {
                        toSkip = evaluateInteger(evalOffset, t);
                    }
                }
                if (toSkip > 0) {
                    toSkip--;
                } else if (toWrite > 0) {
                    toWrite--;
                    if (projectionList != null) {
                        appendProjectionToFrame(t, projectionList);
                    } else {
                        appendTupleToFrame(t);
                    }
                } else {
                    afterLastTuple = true;
                    break;
                }
            }
        }

        @Override
        public void close() throws HyracksDataException {
            // how many tuples still to write
            toWrite = 0;
            // how many tuples still to skip
            toSkip = 0;
            firstTuple = true;
            afterLastTuple = false;
            super.close();
        }

        private int evaluateInteger(IScalarEvaluator eval, int tIdx) throws HyracksDataException {
            tRef.reset(tAccess, tIdx);
            eval.evaluate(tRef, p);
            int lim = bii.getIntegerValue(p.getByteArray(), p.getStartOffset(), p.getLength());
            return lim;
        }

        @Override
        public void flush() throws HyracksDataException {
            appender.flush(writer);
        }
    };
}
Also used : AbstractOneInputOneOutputOneFramePushRuntime(org.apache.hyracks.algebricks.runtime.operators.base.AbstractOneInputOneOutputOneFramePushRuntime) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ByteBuffer(java.nio.ByteBuffer) IBinaryIntegerInspector(org.apache.hyracks.algebricks.data.IBinaryIntegerInspector)

Example 80 with IPointable

use of org.apache.hyracks.data.std.api.IPointable in project asterixdb by apache.

the class RangeMap method getFieldSplit.

@Override
public IPointable getFieldSplit(int columnIndex, int splitIndex) {
    IPointable p = VoidPointable.FACTORY.createPointable();
    int index = getFieldIndex(columnIndex, splitIndex);
    p.set(bytes, getFieldStart(index), getFieldLength(index));
    return p;
}
Also used : IPointable(org.apache.hyracks.data.std.api.IPointable)

Aggregations

IPointable (org.apache.hyracks.data.std.api.IPointable)165 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)153 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)147 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)144 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)141 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)136 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)136 DataOutput (java.io.DataOutput)135 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)117 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)112 IOException (java.io.IOException)91 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)73 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)37 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)26 ATypeTag (org.apache.asterix.om.types.ATypeTag)25 AsterixException (org.apache.asterix.common.exceptions.AsterixException)15 GregorianCalendarSystem (org.apache.asterix.om.base.temporal.GregorianCalendarSystem)13 AMutableDateTime (org.apache.asterix.om.base.AMutableDateTime)11 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)11