Search in sources :

Example 1 with VoidPointable

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

the class CalendarDurationFromDateTimeDescriptor 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<ADuration> durationSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADURATION);

                private AMutableDuration aDuration = new AMutableDuration(0, 0);

                private GregorianCalendarSystem calInstanct = GregorianCalendarSystem.getInstance();

                @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_DATETIME_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 0, bytes0[offset0], ATypeTag.SERIALIZED_DATETIME_TYPE_TAG);
                    }
                    if (bytes1[offset1] != ATypeTag.SERIALIZED_DURATION_TYPE_TAG) {
                        throw new TypeMismatchException(getIdentifier(), 1, bytes1[offset1], ATypeTag.SERIALIZED_DURATION_TYPE_TAG);
                    }
                    int yearMonthDurationInMonths = ADurationSerializerDeserializer.getYearMonth(bytes1, offset1 + 1);
                    long dayTimeDurationInMs = ADurationSerializerDeserializer.getDayTime(bytes1, offset1 + 1);
                    long startingTimePoint = ADateTimeSerializerDeserializer.getChronon(bytes0, offset0 + 1);
                    long endingTimePoint = DurationArithmeticOperations.addDuration(startingTimePoint, yearMonthDurationInMonths, dayTimeDurationInMs, false);
                    if (startingTimePoint == endingTimePoint) {
                        aDuration.setValue(0, 0);
                    } else {
                        boolean negative = false;
                        if (endingTimePoint < startingTimePoint) {
                            negative = true;
                            // swap the starting and ending time, so that ending time is always larger than the
                            // starting time.
                            long tmpTime = endingTimePoint;
                            endingTimePoint = startingTimePoint;
                            startingTimePoint = tmpTime;
                        }
                        int year0 = calInstanct.getYear(startingTimePoint);
                        int month0 = calInstanct.getMonthOfYear(startingTimePoint, year0);
                        int year1 = calInstanct.getYear(endingTimePoint);
                        int month1 = calInstanct.getMonthOfYear(endingTimePoint, year1);
                        int year = year1 - year0;
                        int month = month1 - month0;
                        int day = calInstanct.getDayOfMonthYear(endingTimePoint, year1, month1) - calInstanct.getDayOfMonthYear(startingTimePoint, year0, month0);
                        int hour = calInstanct.getHourOfDay(endingTimePoint) - calInstanct.getHourOfDay(startingTimePoint);
                        int min = calInstanct.getMinOfHour(endingTimePoint) - calInstanct.getMinOfHour(startingTimePoint);
                        int sec = calInstanct.getSecOfMin(endingTimePoint) - calInstanct.getSecOfMin(startingTimePoint);
                        int ms = calInstanct.getMillisOfSec(endingTimePoint) - calInstanct.getMillisOfSec(startingTimePoint);
                        if (ms < 0) {
                            ms += GregorianCalendarSystem.CHRONON_OF_SECOND;
                            sec -= 1;
                        }
                        if (sec < 0) {
                            sec += GregorianCalendarSystem.CHRONON_OF_MINUTE / GregorianCalendarSystem.CHRONON_OF_SECOND;
                            min -= 1;
                        }
                        if (min < 0) {
                            min += GregorianCalendarSystem.CHRONON_OF_HOUR / GregorianCalendarSystem.CHRONON_OF_MINUTE;
                            hour -= 1;
                        }
                        if (hour < 0) {
                            hour += GregorianCalendarSystem.CHRONON_OF_DAY / GregorianCalendarSystem.CHRONON_OF_HOUR;
                            day -= 1;
                        }
                        if (day < 0) {
                            boolean isLeapYear = calInstanct.isLeapYear(year1);
                            // need to "borrow" the days in previous month to make the day positive; when month is
                            // 1 (Jan), Dec will be borrowed
                            day += isLeapYear ? (GregorianCalendarSystem.DAYS_OF_MONTH_LEAP[(12 + month1 - 2) % 12]) : (GregorianCalendarSystem.DAYS_OF_MONTH_ORDI[(12 + month1 - 2) % 12]);
                            month -= 1;
                        }
                        if (month < 0) {
                            month += GregorianCalendarSystem.MONTHS_IN_A_YEAR;
                            year -= 1;
                        }
                        if (negative) {
                            aDuration.setValue(-1 * (year * GregorianCalendarSystem.MONTHS_IN_A_YEAR + month), -1 * (day * GregorianCalendarSystem.CHRONON_OF_DAY + hour * GregorianCalendarSystem.CHRONON_OF_HOUR + min * GregorianCalendarSystem.CHRONON_OF_MINUTE + sec * GregorianCalendarSystem.CHRONON_OF_SECOND + ms));
                        } else {
                            aDuration.setValue(year * GregorianCalendarSystem.MONTHS_IN_A_YEAR + month, day * GregorianCalendarSystem.CHRONON_OF_DAY + hour * GregorianCalendarSystem.CHRONON_OF_HOUR + min * GregorianCalendarSystem.CHRONON_OF_MINUTE + sec * GregorianCalendarSystem.CHRONON_OF_SECOND + ms);
                        }
                    }
                    durationSerde.serialize(aDuration, out);
                    result.set(resultStorage);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) AMutableDuration(org.apache.asterix.om.base.AMutableDuration) GregorianCalendarSystem(org.apache.asterix.om.base.temporal.GregorianCalendarSystem) 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)

Example 2 with VoidPointable

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

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

                // Argument evaluators.
                private final IScalarEvaluator stringEval = args[0].createScalarEvaluator(ctx);

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

                // Argument pointers.
                private final IPointable argString = new VoidPointable();

                private final IPointable argPattern = new VoidPointable();

                private final UTF8StringPointable argStrPtr = new UTF8StringPointable();

                private final UTF8StringPointable argPatternPtr = new UTF8StringPointable();

                // For an output string item.
                private final ArrayBackedValueStorage itemStorge = new ArrayBackedValueStorage();

                private final DataOutput itemOut = itemStorge.getDataOutput();

                private final byte[] tempLengthArray = new byte[5];

                // For the output list of strings.
                private final AOrderedListType intListType = new AOrderedListType(BuiltinType.ASTRING, null);

                private final OrderedListBuilder listBuilder = new OrderedListBuilder();

                private final ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private final DataOutput out = resultStorage.getDataOutput();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        // Calls argument evaluators.
                        stringEval.evaluate(tuple, argString);
                        patternEval.evaluate(tuple, argPattern);
                        // Gets the bytes of the source string.
                        byte[] srcString = argString.getByteArray();
                        int srcOffset = argString.getStartOffset();
                        int srcLen = argString.getLength();
                        // Type check for the first argument.
                        if (srcString[srcOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            throw new TypeMismatchException(getIdentifier(), 0, srcString[srcOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        // Gets the bytes of the pattern string.
                        byte[] patternString = argPattern.getByteArray();
                        int patternOffset = argPattern.getStartOffset();
                        int patternLen = argPattern.getLength();
                        // Type check for the second argument.
                        if (patternString[patternOffset] != ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            throw new TypeMismatchException(getIdentifier(), 1, patternString[patternOffset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        // Sets the UTF8 String pointables.
                        argStrPtr.set(srcString, srcOffset + 1, srcLen - 1);
                        argPatternPtr.set(patternString, patternOffset + 1, patternLen - 1);
                        // Gets the string length of the source string.
                        int inputStringLen = UTF8StringUtil.getUTFLength(srcString, srcOffset + 1);
                        int inputStringStart = srcOffset + 1 + UTF8StringUtil.getNumBytesToStoreLength(inputStringLen);
                        // Gets the string length of the pattern string.
                        int inputPatternLen = UTF8StringUtil.getUTFLength(patternString, patternOffset + 1);
                        // Handles the case that the pattern is "".
                        boolean emptyStringPattern = inputPatternLen == 0;
                        // Builds a list of strings.
                        listBuilder.reset(intListType);
                        int itemStrStart = 0;
                        int nextMatchStart;
                        while (itemStrStart < inputStringLen && (nextMatchStart = UTF8StringPointable.find(argStrPtr, argPatternPtr, false, itemStrStart)) >= 0) {
                            // Adds an item string.
                            addItemString(srcString, inputStringStart, itemStrStart, emptyStringPattern ? nextMatchStart + 1 : nextMatchStart);
                            itemStrStart = nextMatchStart + (emptyStringPattern ? 1 : inputPatternLen);
                        }
                        if (!emptyStringPattern) {
                            addItemString(srcString, inputStringStart, itemStrStart, inputStringLen);
                        }
                        listBuilder.write(out, true);
                        result.set(resultStorage);
                    } catch (IOException e1) {
                        throw new HyracksDataException(e1);
                    }
                }

                private void addItemString(byte[] srcString, int inputStringStart, int itemStartOffset, int nextMatchStart) throws IOException {
                    int itemLen = nextMatchStart - itemStartOffset;
                    int cbytes = UTF8StringUtil.encodeUTF8Length(itemLen, tempLengthArray, 0);
                    itemStorge.reset();
                    itemOut.writeByte(ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                    itemOut.write(tempLengthArray, 0, cbytes);
                    if (itemLen > 0) {
                        itemOut.write(srcString, inputStringStart + itemStartOffset, itemLen);
                    }
                    listBuilder.addItem(itemStorge);
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) 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) 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)

Example 3 with VoidPointable

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

the class StringToCodePointDescriptor 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 ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                protected final DataOutput out = resultStorage.getDataOutput();

                protected final IPointable argPtr = new VoidPointable();

                protected final IScalarEvaluator stringEval = args[0].createScalarEvaluator(ctx);

                protected final AOrderedListType intListType = new AOrderedListType(BuiltinType.AINT64, null);

                private OrderedListBuilder listBuilder = new OrderedListBuilder();

                private ArrayBackedValueStorage inputVal = new ArrayBackedValueStorage();

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

                private final AMutableInt64 aInt64 = new AMutableInt64(0);

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        stringEval.evaluate(tuple, argPtr);
                        byte[] serString = argPtr.getByteArray();
                        int offset = argPtr.getStartOffset();
                        if (serString[offset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            int len = UTF8StringUtil.getUTFLength(serString, offset + 1);
                            int start = offset + 1 + UTF8StringUtil.getNumBytesToStoreLength(len);
                            int pos = 0;
                            listBuilder.reset(intListType);
                            while (pos < len) {
                                int codePoint = UTF8StringUtil.UTF8ToCodePoint(serString, start + pos);
                                pos += UTF8StringUtil.charSize(serString, start + pos);
                                inputVal.reset();
                                aInt64.setValue(codePoint);
                                int64Serde.serialize(aInt64, inputVal.getDataOutput());
                                listBuilder.addItem(inputVal);
                            }
                            listBuilder.write(out, true);
                        } else {
                            throw new TypeMismatchException(getIdentifier(), 0, serString[offset], ATypeTag.SERIALIZED_STRING_TYPE_TAG);
                        }
                        result.set(resultStorage);
                    } catch (IOException e1) {
                        throw new HyracksDataException(e1);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) 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 4 with VoidPointable

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

the class FieldAccessByIndexEvalFactory method createScalarEvaluator.

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

        private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

        private DataOutput out = resultStorage.getDataOutput();

        private IPointable inputArg0 = new VoidPointable();

        private IPointable inputArg1 = new VoidPointable();

        private IScalarEvaluator eval0 = recordEvalFactory.createScalarEvaluator(ctx);

        private IScalarEvaluator eval1 = fieldIndexEvalFactory.createScalarEvaluator(ctx);

        private int fieldIndex;

        private int fieldValueOffset;

        private int fieldValueLength;

        private IAType fieldValueType;

        private ATypeTag fieldValueTypeTag;

        /*
             * inputArg0: the record
             * inputArg1: the index
             *
             * This method outputs into IHyracksTaskContext context [field type tag (1 byte)][the field data]
             */
        @Override
        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            try {
                resultStorage.reset();
                eval0.evaluate(tuple, inputArg0);
                byte[] serRecord = inputArg0.getByteArray();
                int offset = inputArg0.getStartOffset();
                if (serRecord[offset] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
                    throw new TypeMismatchException(BuiltinFunctions.FIELD_ACCESS_BY_INDEX, 0, serRecord[offset], ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
                }
                eval1.evaluate(tuple, inputArg1);
                byte[] indexBytes = inputArg1.getByteArray();
                int indexOffset = inputArg1.getStartOffset();
                if (indexBytes[indexOffset] != ATypeTag.SERIALIZED_INT32_TYPE_TAG) {
                    throw new TypeMismatchException(BuiltinFunctions.FIELD_ACCESS_BY_INDEX, 1, indexBytes[offset], ATypeTag.SERIALIZED_INT32_TYPE_TAG);
                }
                fieldIndex = IntegerPointable.getInteger(indexBytes, indexOffset + 1);
                fieldValueType = recordType.getFieldTypes()[fieldIndex];
                fieldValueOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord, offset, fieldIndex, nullBitmapSize, recordType.isOpen());
                if (fieldValueOffset == 0) {
                    // the field is null, we checked the null bit map
                    out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
                    result.set(resultStorage);
                    return;
                }
                if (fieldValueOffset < 0) {
                    // the field is missing, we checked the missing bit map
                    out.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
                    result.set(resultStorage);
                    return;
                }
                if (fieldValueType.getTypeTag().equals(ATypeTag.UNION)) {
                    if (((AUnionType) fieldValueType).isUnknownableType()) {
                        fieldValueTypeTag = ((AUnionType) fieldValueType).getActualType().getTypeTag();
                        fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, fieldValueOffset, fieldValueTypeTag, false);
                        out.writeByte(fieldValueTypeTag.serialize());
                    } else {
                        // union .. the general case
                        throw new NotImplementedException();
                    }
                } else {
                    fieldValueTypeTag = fieldValueType.getTypeTag();
                    fieldValueLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, fieldValueOffset, fieldValueTypeTag, false);
                    out.writeByte(fieldValueTypeTag.serialize());
                }
                out.write(serRecord, fieldValueOffset, fieldValueLength);
                result.set(resultStorage);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            } catch (AsterixException e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
Also used : DataOutput(java.io.DataOutput) AUnionType(org.apache.asterix.om.types.AUnionType) TypeMismatchException(org.apache.asterix.runtime.exceptions.TypeMismatchException) NotImplementedException(org.apache.hyracks.algebricks.common.exceptions.NotImplementedException) 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) ATypeTag(org.apache.asterix.om.types.ATypeTag) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IAType(org.apache.asterix.om.types.IAType)

Example 5 with VoidPointable

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

the class GetRecordFieldValueEvalFactory method createScalarEvaluator.

@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 inputArg0 = new VoidPointable();

        private final IPointable inputArg1 = new VoidPointable();

        private final IScalarEvaluator recordEval = recordEvalFactory.createScalarEvaluator(ctx);

        private final IScalarEvaluator fieldNameEval = fldNameEvalFactory.createScalarEvaluator(ctx);

        private final RuntimeRecordTypeInfo recTypeInfo = new RuntimeRecordTypeInfo();

        {
            recTypeInfo.reset(recordType);
        }

        @Override
        public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
            try {
                resultStorage.reset();
                fieldNameEval.evaluate(tuple, inputArg1);
                byte[] serFldName = inputArg1.getByteArray();
                int serFldNameOffset = inputArg1.getStartOffset();
                int serFldNameLen = inputArg1.getLength();
                recordEval.evaluate(tuple, inputArg0);
                byte[] serRecord = inputArg0.getByteArray();
                int serRecordOffset = inputArg0.getStartOffset();
                int serRecordLen = inputArg0.getLength();
                if (serRecord[serRecordOffset] != ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
                    throw new TypeMismatchException(BuiltinFunctions.GET_RECORD_FIELD_VALUE, 0, serRecord[serRecordOffset], ATypeTag.SERIALIZED_RECORD_TYPE_TAG);
                }
                int subFieldOffset = -1;
                int subFieldLength = -1;
                // Look at closed fields first.
                int subFieldIndex = recTypeInfo.getFieldIndex(serFldName, serFldNameOffset + 1, serFldNameLen - 1);
                if (subFieldIndex >= 0) {
                    int nullBitmapSize = RecordUtil.computeNullBitmapSize(recordType);
                    subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetById(serRecord, serRecordOffset, subFieldIndex, nullBitmapSize, recordType.isOpen());
                    if (subFieldOffset == 0) {
                        // the field is null, we checked the null bit map
                        out.writeByte(ATypeTag.SERIALIZED_NULL_TYPE_TAG);
                        result.set(resultStorage);
                        return;
                    }
                    ATypeTag fieldTypeTag = recordType.getFieldTypes()[subFieldIndex].getTypeTag();
                    subFieldLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, subFieldOffset, fieldTypeTag, false);
                    // write result.
                    out.writeByte(fieldTypeTag.serialize());
                    out.write(serRecord, subFieldOffset, subFieldLength);
                    result.set(resultStorage);
                    return;
                }
                // Look at open fields.
                subFieldOffset = ARecordSerializerDeserializer.getFieldOffsetByName(serRecord, serRecordOffset, serRecordLen, serFldName, serFldNameOffset);
                if (subFieldOffset < 0) {
                    out.writeByte(ATypeTag.SERIALIZED_MISSING_TYPE_TAG);
                    result.set(resultStorage);
                    return;
                }
                // Get the field length.
                ATypeTag fieldValueTypeTag = EnumDeserializer.ATYPETAGDESERIALIZER.deserialize(serRecord[subFieldOffset]);
                subFieldLength = NonTaggedFormatUtil.getFieldValueLength(serRecord, subFieldOffset, fieldValueTypeTag, true) + 1;
                // write result.
                result.set(serRecord, subFieldOffset, subFieldLength);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            } catch (AsterixException e) {
                throw new HyracksDataException(e);
            }
        }
    };
}
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) ATypeTag(org.apache.asterix.om.types.ATypeTag) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) RuntimeRecordTypeInfo(org.apache.asterix.om.types.runtime.RuntimeRecordTypeInfo)

Aggregations

IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)136 IPointable (org.apache.hyracks.data.std.api.IPointable)136 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)136 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)134 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)129 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)126 DataOutput (java.io.DataOutput)125 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)124 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)114 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)98 IOException (java.io.IOException)84 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)64 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)35 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)24 ATypeTag (org.apache.asterix.om.types.ATypeTag)21 AsterixException (org.apache.asterix.common.exceptions.AsterixException)14 GregorianCalendarSystem (org.apache.asterix.om.base.temporal.GregorianCalendarSystem)13 AMutableDouble (org.apache.asterix.om.base.AMutableDouble)11 AMutablePoint (org.apache.asterix.om.base.AMutablePoint)11