Search in sources :

Example 16 with RecordBuilder

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

the class FeedPolicyTupleTranslator method writePropertyTypeRecord.

public void writePropertyTypeRecord(String name, String value, DataOutput out) throws HyracksDataException {
    IARecordBuilder propertyRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    propertyRecordBuilder.reset(MetadataRecordTypes.POLICY_PARAMS_RECORDTYPE);
    AMutableString aString = new AMutableString("");
    ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    // write field 0
    fieldValue.reset();
    aString.setValue(name);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(0, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(value);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(1, fieldValue);
    propertyRecordBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString)

Example 17 with RecordBuilder

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

the class FeedTupleTranslator method writePropertyTypeRecord.

@SuppressWarnings("unchecked")
public void writePropertyTypeRecord(String name, String value, DataOutput out) throws HyracksDataException {
    IARecordBuilder propertyRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    propertyRecordBuilder.reset(MetadataRecordTypes.DATASOURCE_ADAPTER_PROPERTIES_RECORDTYPE);
    AMutableString aString = new AMutableString("");
    ISerializerDeserializer<AString> stringSerde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(BuiltinType.ASTRING);
    // write field 0
    fieldValue.reset();
    aString.setValue(name);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(0, fieldValue);
    // write field 1
    fieldValue.reset();
    aString.setValue(value);
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    propertyRecordBuilder.addField(1, fieldValue);
    propertyRecordBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder) AMutableString(org.apache.asterix.om.base.AMutableString) AString(org.apache.asterix.om.base.AString)

Example 18 with RecordBuilder

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

the class DatatypeTupleTranslator method writeDerivedTypeRecord.

private void writeDerivedTypeRecord(Datatype type, AbstractComplexType derivedDatatype, DataOutput out) throws HyracksDataException {
    DerivedTypeTag tag = null;
    IARecordBuilder derivedRecordBuilder = new RecordBuilder();
    ArrayBackedValueStorage fieldValue = new ArrayBackedValueStorage();
    switch(derivedDatatype.getTypeTag()) {
        case ARRAY:
            tag = DerivedTypeTag.ORDEREDLIST;
            break;
        case MULTISET:
            tag = DerivedTypeTag.UNORDEREDLIST;
            break;
        case OBJECT:
            tag = DerivedTypeTag.RECORD;
            break;
        default:
            throw new UnsupportedOperationException("No metadata record Type for " + derivedDatatype.getDisplayName());
    }
    derivedRecordBuilder.reset(MetadataRecordTypes.DERIVEDTYPE_RECORDTYPE);
    // write field 0
    fieldValue.reset();
    aString.setValue(tag.toString());
    stringSerde.serialize(aString, fieldValue.getDataOutput());
    derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_TAG_FIELD_INDEX, fieldValue);
    // write field 1
    fieldValue.reset();
    booleanSerde.serialize(type.getIsAnonymous() ? ABoolean.TRUE : ABoolean.FALSE, fieldValue.getDataOutput());
    derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_ISANONYMOUS_FIELD_INDEX, fieldValue);
    switch(tag) {
        case RECORD:
            fieldValue.reset();
            writeRecordType(type, derivedDatatype, fieldValue.getDataOutput());
            derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_RECORD_FIELD_INDEX, fieldValue);
            break;
        case UNORDEREDLIST:
            fieldValue.reset();
            writeCollectionType(type, derivedDatatype, fieldValue.getDataOutput());
            derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_UNORDEREDLIST_FIELD_INDEX, fieldValue);
            break;
        case ORDEREDLIST:
            fieldValue.reset();
            writeCollectionType(type, derivedDatatype, fieldValue.getDataOutput());
            derivedRecordBuilder.addField(MetadataRecordTypes.DERIVEDTYPE_ARECORD_ORDEREDLIST_FIELD_INDEX, fieldValue);
            break;
    }
    derivedRecordBuilder.write(out, true);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) RecordBuilder(org.apache.asterix.builders.RecordBuilder)

Aggregations

RecordBuilder (org.apache.asterix.builders.RecordBuilder)18 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)18 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)12 AString (org.apache.asterix.om.base.AString)11 AMutableString (org.apache.asterix.om.base.AMutableString)8 DataOutput (java.io.DataOutput)5 IScalarEvaluator (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluator)5 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)5 IPointable (org.apache.hyracks.data.std.api.IPointable)5 VoidPointable (org.apache.hyracks.data.std.primitive.VoidPointable)5 IFrameTupleReference (org.apache.hyracks.dataflow.common.data.accessors.IFrameTupleReference)5 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)4 ARecordVisitablePointable (org.apache.asterix.om.pointables.ARecordVisitablePointable)4 IVisitablePointable (org.apache.asterix.om.pointables.base.IVisitablePointable)4 IScalarEvaluatorFactory (org.apache.hyracks.algebricks.runtime.base.IScalarEvaluatorFactory)4 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)4 IOException (java.io.IOException)3 AsterixException (org.apache.asterix.common.exceptions.AsterixException)3 PointableAllocator (org.apache.asterix.om.pointables.PointableAllocator)3 ARecordType (org.apache.asterix.om.types.ARecordType)3