Search in sources :

Example 11 with OrderedListBuilder

use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.

the class ExternalDatasetDetails method writeDatasetDetailsRecordType.

@SuppressWarnings("unchecked")
@Override
public void writeDatasetDetailsRecordType(DataOutput out) throws HyracksDataException {
    IARecordBuilder externalRecordBuilder = new RecordBuilder();
    OrderedListBuilder listBuilder = new OrderedListBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
    externalRecordBuilder.reset(MetadataRecordTypes.EXTERNAL_DETAILS_RECORDTYPE);
    AMutableString aString = new AMutableString("");
    ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    ISerializerDeserializer<ADateTime> dateTimeSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ADATETIME);
    ISerializerDeserializer<AInt32> intSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.AINT32);
    // write field 0
    fieldValue.reset();
    aString.setValue(this.getAdapter());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_DATASOURCE_ADAPTER_FIELD_INDEX, fieldValue);
    // write field 1
    listBuilder.reset((AOrderedListType) MetadataRecordTypes.EXTERNAL_DETAILS_RECORDTYPE.getFieldTypes()[1]);
    for (Map.Entry<String, String> property : this.properties.entrySet()) {
        String name = property.getKey();
        String value = property.getValue();
        itemValue.reset();
        DatasetUtil.writePropertyTypeRecord(name, value, itemValue.getDataOutput(), MetadataRecordTypes.DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE);
        listBuilder.addItem(itemValue);
    }
    fieldValue.reset();
    listBuilder.write(fieldValue.getDataOutput(), true);
    externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_PROPERTIES_FIELD_INDEX, fieldValue);
    // write field 2
    fieldValue.reset();
    dateTimeSerde.serialize(new ADateTime(lastRefreshTime.getTime()), fieldValue.getDataOutput());
    externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_LAST_REFRESH_TIME_FIELD_INDEX, fieldValue);
    // write field 3
    fieldValue.reset();
    intSerde.serialize(new AInt32(state.ordinal()), fieldValue.getDataOutput());
    externalRecordBuilder.addField(MetadataRecordTypes.EXTERNAL_DETAILS_ARECORD_TRANSACTION_STATE_FIELD_INDEX, fieldValue);
    externalRecordBuilder.write(out, true);
}
Also used : OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) ADateTime(org.apache.asterix.om.base.ADateTime) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) AInt32(org.apache.asterix.om.base.AInt32) ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) AString(org.apache.asterix.om.base.AString) HashMap(java.util.HashMap) Map(java.util.Map)

Example 12 with OrderedListBuilder

use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.

the class FunctionTupleTranslator method getTupleFromMetadataEntity.

@Override
public ITupleReference getTupleFromMetadataEntity(Function function) throws HyracksDataException, MetadataException {
    // write the key in the first 2 fields of the tuple
    tupleBuilder.reset();
    aString.setValue(function.getDataverseName());
    stringSerde.serialize(aString, tupleBuilder.getDataOutput());
    tupleBuilder.addFieldEndOffset();
    aString.setValue(function.getName());
    stringSerde.serialize(aString, tupleBuilder.getDataOutput());
    tupleBuilder.addFieldEndOffset();
    aString.setValue(function.getArity() + "");
    stringSerde.serialize(aString, tupleBuilder.getDataOutput());
    tupleBuilder.addFieldEndOffset();
    // write the pay-load in the fourth field of the tuple
    recordBuilder.reset(MetadataRecordTypes.FUNCTION_RECORDTYPE);
    // write field 0
    fieldValue.reset();
    aString.setValue(function.getDataverseName());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_DATAVERSENAME_FIELD_INDEX, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(function.getName());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTIONNAME_FIELD_INDEX, fieldValue);
    // write field 2
    fieldValue.reset();
    aString.setValue(function.getArity() + "");
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_ARITY_FIELD_INDEX, fieldValue);
    // write field 3
    OrderedListBuilder listBuilder = new OrderedListBuilder();
    ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
    listBuilder.reset((AOrderedListType) MetadataRecordTypes.FUNCTION_RECORDTYPE.getFieldTypes()[MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_PARAM_LIST_FIELD_INDEX]);
    for (String param : function.getParams()) {
        itemValue.reset();
        aString.setValue(param);
        stringSerde.serialize(aString, itemValue.getDataOutput());
        listBuilder.addItem(itemValue);
    }
    fieldValue.reset();
    listBuilder.write(fieldValue.getDataOutput(), true);
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_PARAM_LIST_FIELD_INDEX, fieldValue);
    // write field 4
    fieldValue.reset();
    aString.setValue(function.getReturnType());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_RETURN_TYPE_FIELD_INDEX, fieldValue);
    // write field 5
    fieldValue.reset();
    aString.setValue(function.getFunctionBody());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_DEFINITION_FIELD_INDEX, fieldValue);
    // write field 6
    fieldValue.reset();
    aString.setValue(function.getLanguage());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_LANGUAGE_FIELD_INDEX, fieldValue);
    // write field 7
    fieldValue.reset();
    aString.setValue(function.getKind());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_KIND_FIELD_INDEX, fieldValue);
    // write field 8
    fieldValue.reset();
    aString.setValue(Integer.toString(function.getReferenceCount()));
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    recordBuilder.addField(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_REFERENCE_COUNT_INDEX, fieldValue);
    // write record
    recordBuilder.write(tupleBuilder.getDataOutput(), true);
    tupleBuilder.addFieldEndOffset();
    tuple.reset(tupleBuilder.getFieldEndOffsets(), tupleBuilder.getByteArray());
    return tuple;
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) AString(org.apache.asterix.om.base.AString)

Example 13 with OrderedListBuilder

use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.

the class ListifyAggregateFunctionEvalFactory method createAggregateEvaluator.

@Override
public IAggregateEvaluator createAggregateEvaluator(final IHyracksTaskContext ctx) throws HyracksDataException {
    return new IAggregateEvaluator() {

        private IPointable inputVal = new VoidPointable();

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

        private ArrayBackedValueStorage resultStorage = new ArrayBackedValueStorage();

        private OrderedListBuilder builder = new OrderedListBuilder();

        @Override
        public void init() throws HyracksDataException {
            builder.reset(orderedlistType);
        }

        @Override
        public void step(IFrameTupleReference tuple) throws HyracksDataException {
            try {
                eval.evaluate(tuple, inputVal);
                builder.addItem(inputVal);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
        }

        @Override
        public void finish(IPointable result) throws HyracksDataException {
            resultStorage.reset();
            try {
                builder.write(resultStorage.getDataOutput(), true);
            } catch (IOException e) {
                throw new HyracksDataException(e);
            }
            result.set(resultStorage);
        }

        @Override
        public void finishPartial(IPointable result) throws HyracksDataException {
            finish(result);
        }
    };
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) VoidPointable(org.apache.hyracks.data.std.primitive.VoidPointable) IFrameTupleReference(org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference) IAggregateEvaluator(org.apache.hyracks.algebricks.runtime.base.IAggregateEvaluator) 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)

Example 14 with OrderedListBuilder

use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.

the class LangRecordParseUtil method parseList.

private static void parseList(ListConstructor valueExpr, ArrayBackedValueStorage serialized) throws HyracksDataException {
    if (valueExpr.getType() != ListConstructor.Type.ORDERED_LIST_CONSTRUCTOR) {
        throw new HyracksDataException(ErrorCode.ASTERIX, ErrorCode.PARSE_ERROR, "JSON List can't be of type %1$s", valueExpr.getType());
    }
    ArrayBackedValueStorage serializedValue = new ArrayBackedValueStorage();
    OrderedListBuilder listBuilder = new OrderedListBuilder();
    listBuilder.reset(null);
    for (Expression expr : valueExpr.getExprList()) {
        serializedValue.reset();
        parseExpression(expr, serializedValue);
        listBuilder.addItem(serializedValue);
    }
    listBuilder.write(serialized.getDataOutput(), true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) Expression(org.apache.asterix.lang.common.base.Expression) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 15 with OrderedListBuilder

use of org.apache.asterix.builders.OrderedListBuilder in project asterixdb by apache.

the class AOrderedListSerializerDeserializer method serialize.

@SuppressWarnings("unchecked")
@Override
public void serialize(AOrderedList instance, DataOutput out) throws HyracksDataException {
    // TODO: schemaless ordered list serializer
    OrderedListBuilder listBuilder = new OrderedListBuilder();
    listBuilder.reset(orderedlistType);
    ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
    for (int i = 0; i < instance.size(); i++) {
        itemValue.reset();
        serializer.serialize(instance.getItem(i), itemValue.getDataOutput());
        listBuilder.addItem(itemValue);
    }
    listBuilder.write(out, false);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder)

Aggregations

OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)20 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)18 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)7 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 IOException (java.io.IOException)6 AString (org.apache.asterix.om.base.AString)6 IAType (org.apache.asterix.om.types.IAType)6 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)6 IPointable (org.apache.hyracks.data.std.api.IPointable)6 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)6 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)6 DataOutput (java.io.DataOutput)5 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)5 TypeMismatchException (org.apache.asterix.runtime.exceptions.TypeMismatchException)5 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)5 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)5 RecordBuilder (org.apache.asterix.builders.RecordBuilder)4 AMutableString (org.apache.asterix.om.base.AMutableString)3 ISerializerDeserializer (org.apache.hyracks.api.dataflow.value.ISerializerDeserializer)3 HashMap (java.util.HashMap)2