Search in sources :

Example 1 with IAggregateEvaluator

use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator in project asterixdb by apache.

the class FirstElementEvalFactory method createAggregateEvaluator.

@Override
public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
    return new IAggregateEvaluator() {

        private boolean first = true;

        // Needs to copy the bytes from inputVal to outputVal because the byte space of inputVal could be re-used
        // by consequent tuples.
        private ArrayBackedValueStorage outputVal = new ArrayBackedValueStorage();

        private IPointable inputVal = new VoidPointable();

        private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);

        private final byte[] nullBytes = new byte[] { ATypeTag.SERIALIZED_NULL_TYPE_TAG };

        private final byte[] systemNullBytes = new byte[] { ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG };

        @Override
        public void init() throws HyracksDataException {
            first = true;
        }

        @Override
        public void step(IFrameTupleReference tuple) throws HyracksDataException {
            if (!first) {
                return;
            }
            eval.evaluate(tuple, inputVal);
            byte typeTagByte = inputVal.getByteArray()[inputVal.getStartOffset()];
            if (typeTagByte == ATypeTag.SERIALIZED_SYSTEM_NULL_TYPE_TAG) {
                // Ignores SYSTEM_NULLs generated by local-first-element.
                return;
            }
            outputVal.assign(inputVal);
            first = false;
        }

        @Override
        public void finish(IPointable result) throws HyracksDataException {
            if (first) {
                result.set(isLocal ? systemNullBytes : nullBytes, 0, 1);
                return;
            }
            result.set(outputVal);
        }

        @Override
        public void finishPartial(IPointable result) throws HyracksDataException {
            finish(result);
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) 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) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)

Example 2 with IAggregateEvaluator

use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator in project asterixdb by apache.

the class NonEmptyStreamAggregateDescriptor method createAggregateEvaluatorFactory.

@Override
public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(IScalarEvaluatorFactory[] args) {
    return new IAggregateEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IAggregateEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                @SuppressWarnings("rawtypes")
                private ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);

                boolean res = false;

                @Override
                public void init() throws HyracksDataException {
                    res = false;
                }

                @Override
                public void step(IFrameTupleReference tuple) throws HyracksDataException {
                    res = true;
                }

                @SuppressWarnings("unchecked")
                @Override
                public void finish(IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    ABoolean b = res ? ABoolean.TRUE : ABoolean.FALSE;
                    serde.serialize(b, resultStorage.getDataOutput());
                    result.set(resultStorage);
                }

                @Override
                public void finishPartial(IPointable result) throws HyracksDataException {
                    finish(result);
                }
            };
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) ABoolean(org.apache.asterix.om.base.ABoolean) 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) IAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Example 3 with IAggregateEvaluator

use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator 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 4 with IAggregateEvaluator

use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator in project asterixdb by apache.

the class ListifyAggregateFunctionEvalFactory method createAggregateEvaluator.

@Override
public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
    return new IAggregateEvaluator() {

        private IPointable inputVal = new VoidPointable();

        private IScalarEvaluator eval = args[0].createScalarEvaluator(ctx);

        private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

        private OrderedListBuilder builder = new OrderedListBuilder();

        @Override
        public void init() throws HyracksDataException {
            builder.reset(orderedlistType);
        }

        @Override
        public void step(IFrameTupleReference tuple) throws HyracksDataException {
            try {
                eval.evaluate(tuple, inputVal);
                builder.addItem(inputVal);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void finish(IPointable result) throws HyracksDataException {
            resultStorage.reset();
            try {
                builder.write(resultStorage.getDataOutput(), true);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
            result.set(resultStorage);
        }

        @Override
        public void finishPartial(IPointable result) throws HyracksDataException {
            finish(result);
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) 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) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 5 with IAggregateEvaluator

use of org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator in project asterixdb by apache.

the class EmptyStreamAggregateDescriptor method createAggregateEvaluatorFactory.

@Override
public IAggregateEvaluatorFactory createAggregateEvaluatorFactory(IScalarEvaluatorFactory[] args) {
    return new IAggregateEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
            return new IAggregateEvaluator() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                @SuppressWarnings("rawtypes")
                private ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);

                boolean res = true;

                @Override
                public void init() throws HyracksDataException {
                    res = true;
                }

                @Override
                public void step(IFrameTupleReference tuple) throws HyracksDataException {
                    res = false;
                }

                @SuppressWarnings("unchecked")
                @Override
                public void finish(IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    ABoolean b = res ? ABoolean.TRUE : ABoolean.FALSE;
                    serde.serialize(b, resultStorage.getDataOutput());
                    result.set(resultStorage);
                }

                @Override
                public void finishPartial(IPointable result) throws HyracksDataException {
                    finish(result);
                }
            };
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) ABoolean(org.apache.asterix.om.base.ABoolean) 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) IAggregateEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)

Aggregations

IAggregateEvaluator (org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator)6 IPointable (org.apache.hyracks.data.std.api.IPointable)6 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)5 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)5 IOException (java.io.IOException)2 ABoolean (org.apache.asterix.om.base.ABoolean)2 IAggregateEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluatorFactory)2 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)2 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)2 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)2 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)1 IFrameTupleAccessor (org.apache.hyracks.api.comm.IFrameTupleAccessor)1 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)1 FrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.FrameTupleReference)1 AggregateState (org.apache.hyracks.dataflow.std.group.AggregateState)1 IAggregatorDescriptor (org.apache.hyracks.dataflow.std.group.IAggregatorDescriptor)1