Search in sources :

Example 66 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class NonTaggedDataFormat method createMBRFactory.

@SuppressWarnings("unchecked")
@Override
public IScalarEvaluatorFactory[] createMBRFactory(ARecordType recType, List<String> fldName, int recordColumn, int dimension, List<String> filterFieldName, boolean isPointMBR) throws AlgebricksException {
    IScalarEvaluatorFactory evalFactory = getFieldAccessEvaluatorFactory(recType, fldName, recordColumn);
    int numOfFields = isPointMBR ? dimension : dimension * 2;
    IScalarEvaluatorFactory[] evalFactories = new IScalarEvaluatorFactory[numOfFields + (filterFieldName == null ? 0 : 1)];
    ArrayBackedValueStorage abvs1 = new ArrayBackedValueStorage();
    DataOutput dos1 = abvs1.getDataOutput();
    try {
        AInt32 ai = new AInt32(dimension);
        SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(ai.getType()).serialize(ai, dos1);
    } catch (HyracksDataException e) {
        throw new AlgebricksException(e);
    }
    IScalarEvaluatorFactory dimensionEvalFactory = new ConstantEvalFactory(Arrays.copyOf(abvs1.getByteArray(), abvs1.getLength()));
    for (int i = 0; i < numOfFields; i++) {
        ArrayBackedValueStorage abvs2 = new ArrayBackedValueStorage();
        DataOutput dos2 = abvs2.getDataOutput();
        try {
            AInt32 ai = new AInt32(i);
            SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(ai.getType()).serialize(ai, dos2);
        } catch (HyracksDataException e) {
            throw new AlgebricksException(e);
        }
        IScalarEvaluatorFactory coordinateEvalFactory = new ConstantEvalFactory(Arrays.copyOf(abvs2.getByteArray(), abvs2.getLength()));
        evalFactories[i] = new CreateMBREvalFactory(evalFactory, dimensionEvalFactory, coordinateEvalFactory);
    }
    if (filterFieldName != null) {
        evalFactories[numOfFields] = getFieldAccessEvaluatorFactory(recType, filterFieldName, recordColumn);
    }
    return evalFactories;
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) AInt32(org.apache.asterix.om.base.AInt32) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IScalarEvaluatorFactory(org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory) CreateMBREvalFactory(org.apache.asterix.runtime.evaluators.common.CreateMBREvalFactory)

Example 67 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class NonTaggedDataFormat method getConstantEvalFactory.

@SuppressWarnings("unchecked")
@Override
public IScalarEvaluatorFactory getConstantEvalFactory(IAlgebricksConstantValue value) throws AlgebricksException {
    IAObject obj = null;
    if (value.isMissing()) {
        obj = AMissing.MISSING;
    } else if (value.isTrue()) {
        obj = ABoolean.TRUE;
    } else if (value.isFalse()) {
        obj = ABoolean.FALSE;
    } else {
        AsterixConstantValue acv = (AsterixConstantValue) value;
        obj = acv.getObject();
    }
    ArrayBackedValueStorage abvs = new ArrayBackedValueStorage();
    DataOutput dos = abvs.getDataOutput();
    try {
        SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(obj.getType()).serialize(obj, dos);
    } catch (HyracksDataException e) {
        throw new AlgebricksException(e);
    }
    return new ConstantEvalFactory(Arrays.copyOf(abvs.getByteArray(), abvs.getLength()));
}
Also used : DataOutput(java.io.DataOutput) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AsterixConstantValue(org.apache.asterix.om.constants.AsterixConstantValue) IAObject(org.apache.asterix.om.base.IAObject) ConstantEvalFactory(org.apache.hyracks.algebricks.runtime.evaluators.ConstantEvalFactory) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 68 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class ADMDataParser method parseRecord.

private void parseRecord(ARecordType recType, DataOutput out) throws IOException {
    ArrayBackedValueStorage fieldValueBuffer = getTempBuffer();
    ArrayBackedValueStorage fieldNameBuffer = getTempBuffer();
    IARecordBuilder recBuilder = getRecordBuilder();
    BitSet nulls = null;
    if (recType != null) {
        // TODO: use BitSet Pool
        nulls = new BitSet(recType.getFieldNames().length);
        recBuilder.reset(recType);
    } else {
        recBuilder.reset(null);
    }
    recBuilder.init();
    int token;
    boolean inRecord = true;
    boolean expectingRecordField = false;
    boolean first = true;
    Boolean openRecordField = false;
    int fieldId = 0;
    IAType fieldType = null;
    do {
        token = admLexer.next();
        switch(token) {
            case AdmLexer.TOKEN_END_RECORD:
                if (expectingRecordField) {
                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_RECORD_END_UNEXPECTED);
                }
                inRecord = false;
                break;
            case AdmLexer.TOKEN_STRING_LITERAL:
                // we've read the name of the field
                // now read the content
                fieldNameBuffer.reset();
                fieldValueBuffer.reset();
                expectingRecordField = false;
                if (recType != null) {
                    String fldName = admLexer.getLastTokenImage().substring(1, admLexer.getLastTokenImage().length() - 1);
                    fieldId = recBuilder.getFieldId(fldName);
                    if ((fieldId < 0) && !recType.isOpen()) {
                        throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_EXTRA_FIELD_IN_CLOSED_RECORD, fldName);
                    } else if ((fieldId < 0) && recType.isOpen()) {
                        aStringFieldName.setValue(admLexer.getLastTokenImage().substring(1, admLexer.getLastTokenImage().length() - 1));
                        stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput());
                        openRecordField = true;
                        fieldType = null;
                    } else {
                        // a closed field
                        nulls.set(fieldId);
                        fieldType = recType.getFieldTypes()[fieldId];
                        openRecordField = false;
                    }
                } else {
                    aStringFieldName.setValue(admLexer.getLastTokenImage().substring(1, admLexer.getLastTokenImage().length() - 1));
                    stringSerde.serialize(aStringFieldName, fieldNameBuffer.getDataOutput());
                    openRecordField = true;
                    fieldType = null;
                }
                token = admLexer.next();
                if (token != AdmLexer.TOKEN_COLON) {
                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_UNEXPECTED_TOKEN_WHEN_EXPECT_COMMA, AdmLexer.tokenKindToString(token));
                }
                token = admLexer.next();
                this.admFromLexerStream(token, fieldType, fieldValueBuffer.getDataOutput());
                if (openRecordField) {
                    recBuilder.addField(fieldNameBuffer, fieldValueBuffer);
                } else {
                    recBuilder.addField(fieldId, fieldValueBuffer);
                }
                break;
            case AdmLexer.TOKEN_COMMA:
                if (first) {
                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_FOUND_COMMA_WHEN, "before any");
                }
                if (expectingRecordField) {
                    throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_FOUND_COMMA_WHEN, "expecting a");
                }
                expectingRecordField = true;
                break;
            default:
                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_UNEXPECTED_TOKEN_KIND, AdmLexer.tokenKindToString(token));
        }
        first = false;
    } while (inRecord);
    if (recType != null) {
        final int nullableFieldId = checkOptionalConstraints(recType, nulls);
        if (nullableFieldId != -1) {
            throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_FIELD_NOT_NULL, recType.getFieldNames()[nullableFieldId]);
        }
    }
    recBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) BitSet(java.util.BitSet) ABoolean(org.apache.asterix.om.base.ABoolean) IAType(org.apache.asterix.om.types.IAType)

Example 69 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class ADMDataParser method parseOrderedList.

private void parseOrderedList(AOrderedListType oltype, DataOutput out) throws IOException {
    ArrayBackedValueStorage itemBuffer = getTempBuffer();
    OrderedListBuilder orderedListBuilder = (OrderedListBuilder) getOrderedListBuilder();
    IAType itemType = null;
    if (oltype != null) {
        itemType = oltype.getItemType();
    }
    orderedListBuilder.reset(oltype);
    int token;
    boolean inList = true;
    boolean expectingListItem = false;
    boolean first = true;
    do {
        token = admLexer.next();
        if (token == AdmLexer.TOKEN_END_ORDERED_LIST) {
            if (expectingListItem) {
                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_END_COLLECTION);
            }
            inList = false;
        } else if (token == AdmLexer.TOKEN_COMMA) {
            if (first) {
                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_COMMA_BEFORE_LIST);
            }
            if (expectingListItem) {
                throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_COMMA_EXPECTING_ITEM);
            }
            expectingListItem = true;
        } else {
            expectingListItem = false;
            itemBuffer.reset();
            admFromLexerStream(token, itemType, itemBuffer.getDataOutput());
            orderedListBuilder.addItem(itemBuffer);
        }
        first = false;
    } while (inList);
    orderedListBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) IAType(org.apache.asterix.om.types.IAType)

Example 70 with ArrayBackedValueStorage

use of org.apache.hyracks.data.std.util.ArrayBackedValueStorage in project asterixdb by apache.

the class AInt8ConstructorDescriptor method createEvaluatorFactory.

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

        private static final long serialVersionUID = 1L;

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

                private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

                private DataOutput out = resultStorage.getDataOutput();

                private IPointable inputArg = new VoidPointable();

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

                private byte value;

                private int offset;

                private boolean positive;

                private AMutableInt8 aInt8 = new AMutableInt8((byte) 0);

                @SuppressWarnings("unchecked")
                private ISerializerDeserializer<AInt8> int8Serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT8);

                private final UTF8StringPointable utf8Ptr = new UTF8StringPointable();

                @Override
                public void evaluate(IFrameTupleReference tuple, IPointable result) throws HyracksDataException {
                    try {
                        resultStorage.reset();
                        eval.evaluate(tuple, inputArg);
                        byte[] serString = inputArg.getByteArray();
                        int startOffset = inputArg.getStartOffset();
                        int len = inputArg.getLength();
                        if (serString[startOffset] == ATypeTag.SERIALIZED_STRING_TYPE_TAG) {
                            utf8Ptr.set(serString, startOffset + 1, len - 1);
                            offset = utf8Ptr.getCharStartOffset();
                            //accumulating value in negative domain
                            //otherwise Byte.MIN_VALUE = -(Byte.MAX_VALUE + 1) would have caused overflow
                            value = 0;
                            positive = true;
                            byte limit = -Byte.MAX_VALUE;
                            if (serString[offset] == '+') {
                                offset++;
                            } else if (serString[offset] == '-') {
                                offset++;
                                positive = false;
                                limit = Byte.MIN_VALUE;
                            }
                            int end = startOffset + len;
                            for (; offset < end; offset++) {
                                int digit;
                                if (serString[offset] >= '0' && serString[offset] <= '9') {
                                    value = (byte) (value * 10);
                                    digit = serString[offset] - '0';
                                } else if (serString[offset] == 'i' && serString[offset + 1] == '8' && offset + 2 == end) {
                                    break;
                                } else {
                                    throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG);
                                }
                                if (value < limit + digit) {
                                    throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG);
                                }
                                value = (byte) (value - digit);
                            }
                            if (value > 0) {
                                throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG);
                            }
                            if (value < 0 && positive) {
                                value *= -1;
                            }
                            aInt8.setValue(value);
                            int8Serde.serialize(aInt8, out);
                        } else {
                            throw new InvalidDataFormatException(getIdentifier(), ATypeTag.SERIALIZED_INT8_TYPE_TAG);
                        }
                        result.set(resultStorage);
                    } catch (IOException e1) {
                        throw new InvalidDataFormatException(getIdentifier(), e1, ATypeTag.SERIALIZED_INT8_TYPE_TAG);
                    }
                }
            };
        }
    };
}
Also used : DataOutput(java.io.DataOutput) UTF8StringPointable(org.apache.hyracks.data.std.primitive.UTF8StringPointable) AMutableInt8(org.apache.asterix.om.base.AMutableInt8) 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) 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)

Aggregations

ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)190 IPointable (org.apache.hyracks.data.std.api.IPointable)144 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)144 DataOutput (java.io.DataOutput)140 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)138 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)131 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)129 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)129 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)116 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)110 IOException (java.io.IOException)90 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)78 InvalidDataFormatException (org.apache.asterix.runtime.exceptions.InvalidDataFormatException)48 UTF8StringPointable (org.apache.hyracks.data.std.primitive.UTF8StringPointable)35 AMutableInt64 (org.apache.asterix.om.base.AMutableInt64)25 ATypeTag (org.apache.asterix.om.types.ATypeTag)23 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)18 RecordBuilder (org.apache.asterix.builders.RecordBuilder)18 AString (org.apache.asterix.om.base.AString)18 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)17