Search in sources :

Example 96 with IPointable

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

the class Substring2Descriptor 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() {

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable argString = new VoidPointable();

                private IPointable argStart = new VoidPointable();

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

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

                private final GrowableArray array = new GrowableArray();

                private final UTF8StringBuilder builder = new UTF8StringBuilder();

                private final UTF8StringPointable string = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    evalString.evaluate(tuple, argString);
                    evalStart.evaluate(tuple, argStart);
                    byte[] bytes = argStart.getByteArray();
                    int offset = argStart.getStartOffset();
                    int start = ATypeHierarchy.getIntegerValue(getIdentifier().getName(), 1, bytes, offset) - 1;
                    bytes = argString.getByteArray();
                    offset = argString.getStartOffset();
                    int len = argString.getLength();
                    if (bytes[offset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                    }
                    string.set(bytes, offset + 1, len - 1);
                    array.reset();
                    try {
                        UTF8StringPointable.substr(string, start, Integer.MAX_VALUE, builder, array);
                    } catch (StringIndexOutOfBoundsException e) {
                        throw new RuntimeDataException(ErrorCode.OUT_OF_BOUND, getIdentifier(), 1, start);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    try {
                        out.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        out.write(array.getByteArray(), 0, array.getLength());
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) GrowableArray(org.apache.hyracks.data.std.util.GrowableArray) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) UTF8StringBuilder(org.apache.hyracks.data.std.util.UTF8StringBuilder) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 97 with IPointable

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

the class LenDescriptor 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() {

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput out = resultStorage.getDataOutput();

                private final IPointable inputVal = new VoidPointable();

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

                // result
                private final AMutableInt64 res = new AMutableInt64(0);

                @SuppressWarnings("unchecked")
                private final ISerializerDeserializer<AInt64> int64Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT64);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    evalList.evaluate(tuple, inputVal);
                    byte[] serList = inputVal.getByteArray();
                    int offset = inputVal.getStartOffset();
                    if (serList[offset] != ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG && serList[offset] != ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, serList[offset], ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG, ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG);
                    }
                    int numberOfitems = 0;
                    if (serList[offset] == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG) {
                        numberOfitems = AOrderedListSerializerDeserializer.getNumberOfItems(serList, offset);
                    } else {
                        numberOfitems = AUnorderedListSerializerDeserializer.getNumberOfItems(serList, offset);
                    }
                    res.setValue(numberOfitems);
                    try {
                        int64Serde.serialize(res, out);
                    } catch (IOException e) {
                        throw new HyracksDataException(e);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) IPointable(org.apache.hyracks.data.std.api.IPointable) IOException(java.io.IOException) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) AMutableInt64(org.apache.asterix.om.base.AMutableInt64)

Example 98 with IPointable

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

the class InjectFailureDescriptor 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 {
            final IPointable argPtr = new VoidPointable();
            final IScalarEvaluator[] evals = new IScalarEvaluator[args.length];
            evals[0] = args[0].createScalarEvaluator(ctx);
            evals[1] = args[1].createScalarEvaluator(ctx);
            return new IScalarEvaluator() {

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    evals[1].evaluate(tuple, argPtr);
                    ATypeTag typeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(argPtr.getByteArray()[argPtr.getStartOffset()]);
                    if (typeTag == ATypeTag.BOOLEAN) {
                        boolean argResult = ABooleanSerializerDeserializer.getBoolean(argPtr.getByteArray(), argPtr.getStartOffset() + 1);
                        if (argResult) {
                            LOGGER.log(Level.SEVERE, ctx.getTaskAttemptId() + " injecting failure");
                            throw new RuntimeDataException(ErrorCode.INJECTED_FAILURE, getIdentifier());
                        }
                    }
                    // evaluate the real evaluator
                    evals[0].evaluate(tuple, argPtr);
                    result.set(argPtr.getByteArray(), argPtr.getStartOffset(), argPtr.getLength());
                }
            };
        }
    };
}
Also used : ATypeTag(org.apache.asterix.om.types.ATypeTag) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Example 99 with IPointable

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

the class PointablePrimitiveValueProviderFactory method createPrimitiveValueProvider.

@Override
public IPrimitiveValueProvider createPrimitiveValueProvider() {
    final IPointable p = pf.createPointable();
    ITypeTraits traits = pf.getTypeTraits();
    assert traits.isFixedLength();
    final int length = traits.getFixedLength();
    return new IPrimitiveValueProvider() {

        @Override
        public double getValue(byte[] bytes, int offset) {
            p.set(bytes, offset, length);
            return ((INumeric) p).doubleValue();
        }
    };
}
Also used : ITypeTraits(org.apache.hyracks.api.dataflow.value.ITypeTraits) INumeric(org.apache.hyracks.data.std.api.INumeric) IPrimitiveValueProvider(org.apache.hyracks.storage.am.common.api.IPrimitiveValueProvider) IPointable(org.apache.hyracks.data.std.api.IPointable)

Example 100 with IPointable

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

the class IntegerEqFunctionEvaluatorFactory method createScalarEvaluator.

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

        private IPointable out1 = new VoidPointable();

        private IPointable out2 = new VoidPointable();

        private IScalarEvaluator eval1 = arg1Factory.createScalarEvaluator(ctx);

        private IScalarEvaluator eval2 = arg2Factory.createScalarEvaluator(ctx);

        private byte[] resultData = new byte[1];

        @Override
        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            eval1.evaluate(tuple, out1);
            eval2.evaluate(tuple, out2);
            int v1 = IntegerPointable.getInteger(out1.getByteArray(), out1.getStartOffset());
            int v2 = IntegerPointable.getInteger(out2.getByteArray(), out2.getStartOffset());
            boolean r = v1 == v2;
            resultData[0] = r ? (byte) 1 : (byte) 0;
            result.set(resultData, 0, 1);
        }
    };
}
Also used : VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IPointable(org.apache.hyracks.data.std.api.IPointable) IScalarEvaluator(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)

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