Search in sources :

Example 1 with TaggedValuePointable

use of org.apache.hyracks.data.std.primitive.TaggedValuePointable in project asterixdb by apache.

the class AbstractIntervalLogicFuncDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

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

                protected final IntervalLogic il = new IntervalLogic();

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private TaggedValuePointable argPtr0 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

                private TaggedValuePointable argPtr1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

                private AIntervalPointable interval0 = (AIntervalPointable) AIntervalPointable.FACTORY.createPointable();

                private AIntervalPointable interval1 = (AIntervalPointable) AIntervalPointable.FACTORY.createPointable();

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

                private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);

                // possible output types
                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ABoolean> booleanSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ABOOLEAN);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval0.evaluate(tuple, argPtr0);
                    eval1.evaluate(tuple, argPtr1);
                    byte typeTag0 = argPtr0.getTag();
                    if (typeTag0 != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, typeTag0, ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
                    }
                    byte typeTag1 = argPtr0.getTag();
                    if (typeTag1 != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, typeTag1, ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
                    }
                    argPtr0.getValue(interval0);
                    argPtr1.getValue(interval1);
                    if (typeTag0 != typeTag1) {
                        throw new IncompatibleTypeException(getIdentifier(), typeTag0, typeTag1);
                    }
                    ABoolean res = compareIntervals(il, interval0, interval1) ? ABoolean.TRUE : ABoolean.FALSE;
                    booleanSerde.serialize(res, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TaggedValuePointable(org.apache.hyracks.data.std.primitive.TaggedValuePointable) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) ABoolean(org.apache.asterix.om.base.ABoolean) AIntervalPointable(org.apache.asterix.om.pointables.nonvisitor.AIntervalPointable) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IncompatibleTypeException(org.apache.asterix.runtime.exceptions.IncompatibleTypeException)

Example 2 with TaggedValuePointable

use of org.apache.hyracks.data.std.primitive.TaggedValuePointable in project asterixdb by apache.

the class GetOverlappingIntervalDescriptor method createEvaluatorFactory.

@Override
public IScalarEvaluatorFactory createEvaluatorFactory(final IScalarEvaluatorFactory[] args) {
    return new IScalarEvaluatorFactory() {

        private static final long serialVersionUID = 1L;

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

                protected final IntervalLogic il = new IntervalLogic();

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private TaggedValuePointable argPtr0 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

                private TaggedValuePointable argPtr1 = (TaggedValuePointable) TaggedValuePointable.FACTORY.createPointable();

                private AIntervalPointable interval0 = (AIntervalPointable) AIntervalPointable.FACTORY.createPointable();

                private AIntervalPointable interval1 = (AIntervalPointable) AIntervalPointable.FACTORY.createPointable();

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

                private IScalarEvaluator eval1 = args[1].createScalarEvaluator(ctx);

                private final AMutableInterval aInterval = new AMutableInterval(0, 0, (byte) -1);

                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<ANull> nullSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ANULL);

                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<AInterval> intervalSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINTERVAL);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval0.evaluate(tuple, argPtr0);
                    eval1.evaluate(tuple, argPtr1);
                    byte type0 = argPtr0.getTag();
                    byte type1 = argPtr1.getTag();
                    if (type0 == ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG && type0 == type1) {
                        argPtr0.getValue(interval0);
                        argPtr1.getValue(interval1);
                        byte intervalType0 = interval0.getType();
                        byte intervalType1 = interval1.getType();
                        if (intervalType0 != intervalType1) {
                            throw new IncompatibleTypeException(getIdentifier(), intervalType0, intervalType1);
                        }
                        if (il.overlaps(interval0, interval1) || il.overlappedBy(interval0, interval1) || il.covers(interval0, interval1) || il.coveredBy(interval0, interval1)) {
                            long start = Math.max(interval0.getStartValue(), interval1.getStartValue());
                            long end = Math.min(interval0.getEndValue(), interval1.getEndValue());
                            aInterval.setValue(start, end, intervalType0);
                            intervalSerde.serialize(aInterval, out);
                        } else {
                            nullSerde.serialize(ANull.NULL, out);
                        }
                        result.set(resultStorage);
                        return;
                    } else if (type0 != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, type0, ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
                    } else {
                        throw new IncompatibleTypeException(getIdentifier(), type0, type1);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TaggedValuePointable(org.apache.hyracks.data.std.primitive.TaggedValuePointable) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) AIntervalPointable(org.apache.asterix.om.pointables.nonvisitor.AIntervalPointable) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IncompatibleTypeException(org.apache.asterix.runtime.exceptions.IncompatibleTypeException) AMutableInterval(org.apache.asterix.om.base.AMutableInterval)

Aggregations

DataOutput (java.io.DataOutput)2 AIntervalPointable (org.apache.asterix.om.pointables.nonvisitor.AIntervalPointable)2 IncompatibleTypeException (org.apache.asterix.runtime.exceptions.IncompatibleTypeException)2 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)2 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)2 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)2 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)2 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)2 IPointable (org.apache.hyracks.data.std.api.IPointable)2 TaggedValuePointable (org.apache.hyracks.data.std.primitive.TaggedValuePointable)2 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)2 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)2 ABoolean (org.apache.asterix.om.base.ABoolean)1 AMutableInterval (org.apache.asterix.om.base.AMutableInterval)1