Search in sources :

Example 86 with TypeMismatchException

use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.

the class GetRecordFieldsEvalFactory method createScalarEvaluator.

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

        private final ARecordPointable recordPointable = (ARecordPointable) ARecordPointable.FACTORY.createPointable();

        private IPointable inputArg0 = new VoidPointable();

        private IScalarEvaluator eval0 = recordEvalFactory.createScalarEvaluator(ctx);

        private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

        private DataOutput out = resultStorage.getDataOutput();

        private RecordFieldsUtil rfu = new RecordFieldsUtil();

        @Override
        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            resultStorage.reset();
            eval0.evaluate(tuple, inputArg0);
            byte[] data = inputArg0.getByteArray();
            int offset = inputArg0.getStartOffset();
            int len = inputArg0.getLength();
            if (data[offset] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
                throw new TypeMismatchException(BuiltinFunctions.GET_RECORD_FIELDS, 0, data[offset], ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
            }
            recordPointable.set(data, offset, len);
            try {
                rfu.processRecord(recordPointable, recordType, out, 0);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            } catch (AsterixException 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) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AsterixException(org.apache.asterix.common.exceptions.AsterixException) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) ARecordPointable(org.apache.asterix.om.pointables.nonvisitor.ARecordPointable)

Example 87 with TypeMismatchException

use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.

the class DayTimeDurationComparatorDescriptor 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 argPtr0 = new VoidPointable();

                private IPointable argPtr1 = new VoidPointable();

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

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

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ABoolean> boolSerde = 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[] bytes0 = argPtr0.getByteArray();
                    int offset0 = argPtr0.getStartOffset();
                    byte[] bytes1 = argPtr1.getByteArray();
                    int offset1 = argPtr1.getStartOffset();
                    if (bytes0[offset0] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
                    }
                    if (bytes1[offset1] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
                    }
                    if ((ADurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1) != 0) || (ADurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1) != 0)) {
                        throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_YEAR_MONTH_DURATION_TYPE_TAG);
                    }
                    if (ADurationSerializerDeserializer.getDayTime(bytes0, offset0 + 1) > ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1)) {
                        boolSerde.serialize(isGreaterThan ? ABoolean.TRUE : ABoolean.FALSE, out);
                    } else {
                        boolSerde.serialize(isGreaterThan ? ABoolean.FALSE : ABoolean.TRUE, out);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) 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) InvalidDataFormatException(org.apache.asterix.runtime.exceptions.InvalidDataFormatException) 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)

Example 88 with TypeMismatchException

use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.

the class DurationEqualDescriptor 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 argPtr0 = new VoidPointable();

                private IPointable argPtr1 = new VoidPointable();

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

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

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ABoolean> boolSerde = 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[] bytes0 = argPtr0.getByteArray();
                    int offset0 = argPtr0.getStartOffset();
                    byte[] bytes1 = argPtr1.getByteArray();
                    int offset1 = argPtr1.getStartOffset();
                    if (bytes0[offset0] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
                    }
                    if (bytes1[offset1] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
                    }
                    if ((ADurationSerializerDeserializer.getDayTime(bytes0, offset0 + 1) == ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1)) && (ADurationSerializerDeserializer.getYearMonth(bytes0, offset0 + 1) == ADurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1))) {
                        boolSerde.serialize(ABoolean.TRUE, out);
                    } else {
                        boolSerde.serialize(ABoolean.FALSE, out);
                    }
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) 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) ISerializerDeserializer(org.apache.hyracks.api.dataflow.value.ISerializerDeserializer) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)

Example 89 with TypeMismatchException

use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.

the class DurationFromIntervalDescriptor 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 argPtr = new VoidPointable();

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

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ADayTimeDuration> dayTimeDurationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADAYTIMEDURATION);

                private AMutableDayTimeDuration aDayTimeDuration = new AMutableDayTimeDuration(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval.evaluate(tuple, argPtr);
                    byte[] bytes = argPtr.getByteArray();
                    int offset = argPtr.getStartOffset();
                    if (bytes[offset] != ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes[offset], ATypeTag.SERIALIZED_INTERVAL_TYPE_TAG);
                    }
                    long chrononStart = AIntervalSerializerDeserializer.getIntervalStart(bytes, offset + 1);
                    long chrononEnd = AIntervalSerializerDeserializer.getIntervalEnd(bytes, offset + 1);
                    byte intervalTypeTag = AIntervalSerializerDeserializer.getIntervalTimeType(bytes, offset + 1);
                    if (intervalTypeTag == ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
                        chrononStart *= GregorianCalendarSystem.CHRONON_OF_DAY;
                        chrononEnd *= GregorianCalendarSystem.CHRONON_OF_DAY;
                    }
                    aDayTimeDuration.setMilliseconds(chrononEnd - chrononStart);
                    dayTimeDurationSerde.serialize(aDayTimeDuration, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) 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) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) AMutableDayTimeDuration(org.apache.asterix.om.base.AMutableDayTimeDuration)

Example 90 with TypeMismatchException

use of org.apache.asterix.runtime.exceptions.TypeMismatchException in project asterixdb by apache.

the class DatetimeFromDateAndTimeDescriptor method createEvaluatorFactory.

/* (non-Javadoc)
     * @see org.apache.asterix.runtime.base.IScalarFunctionDynamicDescriptor#createEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.ICopyEvaluatorFactory[])
     */
@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 argPtr0 = new VoidPointable();

                private IPointable argPtr1 = new VoidPointable();

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

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

                // possible returning types
                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<ADateTime> datetimeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);

                private AMutableDateTime aDateTime = new AMutableDateTime(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    resultStorage.reset();
                    eval0.evaluate(tuple, argPtr0);
                    eval1.evaluate(tuple, argPtr1);
                    byte[] bytes0 = argPtr0.getByteArray();
                    int offset0 = argPtr0.getStartOffset();
                    byte[] bytes1 = argPtr1.getByteArray();
                    int offset1 = argPtr1.getStartOffset();
                    if (bytes0[offset0] != ATypeTag.SERIALIZED_DATE_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_DATE_TYPE_TAG);
                    }
                    if (bytes1[offset1] != ATypeTag.SERIALIZED_TIME_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_TIME_TYPE_TAG);
                    }
                    long datetimeChronon = ADateSerializerDeserializer.getChronon(bytes0, offset0 + 1) * GregorianCalendarSystem.CHRONON_OF_DAY + ATimeSerializerDeserializer.getChronon(bytes1, offset1 + 1);
                    aDateTime.setValue(datetimeChronon);
                    datetimeSerde.serialize(aDateTime, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) 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) AMutableDateTime(org.apache.asterix.om.base.AMutableDateTime) 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)

Aggregations

TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)127 IPointable (org.apache.hyracks.data.std.api.IPointable)117 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)117 DataOutput (java.io.DataOutput)116 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)116 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)116 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)114 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)110 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)110 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)93 IOException (java.io.IOException)84 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)67 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)44 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)33 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)22 ATypeTag (org.apache.asterix.om.types.ATypeTag)18 AsterixException (org.apache.asterix.common.exceptions.AsterixException)14 GregorianCalendarSystem (org.apache.asterix.om.base.temporal.GregorianCalendarSystem)13 AMutablePoint (org.apache.asterix.om.base.AMutablePoint)11 AMutableDateTime (org.apache.asterix.om.base.AMutableDateTime)10