use of org.apache.asterix.builders.IARecordBuilder 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);
}
use of org.apache.asterix.builders.IARecordBuilder 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);
}
use of org.apache.asterix.builders.IARecordBuilder 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);
}
use of org.apache.asterix.builders.IARecordBuilder in project asterixdb by apache.
the class RecordFieldsUtil method processListValue.
public void processListValue(IValueReference listArg, IAType fieldType, DataOutput out, int level) throws AsterixException, IOException {
ArrayBackedValueStorage itemValue = getTempBuffer();
IARecordBuilder listRecordBuilder = getRecordBuilder();
AListPointable list = getListPointable();
list.set(listArg);
OrderedListBuilder innerListBuilder = getOrderedListBuilder();
innerListBuilder.reset(listType);
listRecordBuilder.reset(null);
AbstractCollectionType act = (AbstractCollectionType) fieldType;
int itemCount = list.getItemCount();
for (int l = 0; l < itemCount; l++) {
itemValue.reset();
listRecordBuilder.init();
byte tagId = list.getItemTag(act, l);
addFieldType(tagId, listRecordBuilder);
if (tagId == ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
ArrayBackedValueStorage tmpAbvs = getTempBuffer();
list.getItemValue(act, l, tmpAbvs.getDataOutput());
addNestedField(tmpAbvs, act.getItemType(), listRecordBuilder, level + 1);
}
listRecordBuilder.write(itemValue.getDataOutput(), true);
innerListBuilder.addItem(itemValue);
}
innerListBuilder.write(out, true);
}
use of org.apache.asterix.builders.IARecordBuilder in project asterixdb by apache.
the class RecordFieldsUtil method processRecord.
public void processRecord(ARecordPointable recordAccessor, ARecordType recType, DataOutput out, int level) throws IOException, AsterixException {
if (level == 0) {
// Resets pools for recycling objects before processing a top-level record.
resetPools();
}
ArrayBackedValueStorage itemValue = getTempBuffer();
ArrayBackedValueStorage fieldName = getTempBuffer();
OrderedListBuilder orderedListBuilder = getOrderedListBuilder();
orderedListBuilder.reset(listType);
IARecordBuilder fieldRecordBuilder = getRecordBuilder();
fieldRecordBuilder.reset(null);
int schemeFieldCount = recordAccessor.getSchemeFieldCount(recType);
for (int i = 0; i < schemeFieldCount; ++i) {
itemValue.reset();
fieldRecordBuilder.init();
// write name
fieldName.reset();
recordAccessor.getClosedFieldName(recType, i, fieldName.getDataOutput());
addNameField(fieldName, fieldRecordBuilder);
// write type
byte tag = recordAccessor.getClosedFieldTag(recType, i);
addFieldType(tag, fieldRecordBuilder);
// write open
addIsOpenField(false, fieldRecordBuilder);
// write nested or list types
if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG || tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
if (!recordAccessor.isClosedFieldNull(recType, i)) {
IAType fieldType = recordAccessor.getClosedFieldType(recType, i);
ArrayBackedValueStorage tmpValue = getTempBuffer();
tmpValue.reset();
recordAccessor.getClosedFieldValue(recType, i, tmpValue.getDataOutput());
if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
addNestedField(tmpValue, fieldType, fieldRecordBuilder, level + 1);
} else if (tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
addListField(tmpValue, fieldType, fieldRecordBuilder, level + 1);
}
}
}
// write record
fieldRecordBuilder.write(itemValue.getDataOutput(), true);
// add item to the list of fields
orderedListBuilder.addItem(itemValue);
}
for (int i = recordAccessor.getOpenFieldCount(recType) - 1; i >= 0; --i) {
itemValue.reset();
fieldRecordBuilder.init();
// write name
fieldName.reset();
recordAccessor.getOpenFieldName(recType, i, fieldName.getDataOutput());
addNameField(fieldName, fieldRecordBuilder);
// write type
byte tag = recordAccessor.getOpenFieldTag(recType, i);
addFieldType(tag, fieldRecordBuilder);
// write open
addIsOpenField(true, fieldRecordBuilder);
// write nested or list types
if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG || tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
IAType fieldType = null;
ArrayBackedValueStorage tmpValue = getTempBuffer();
tmpValue.reset();
recordAccessor.getOpenFieldValue(recType, i, tmpValue.getDataOutput());
if (tag == ATypeTag.SERIALIZED_RECORD_TYPE_TAG) {
addNestedField(tmpValue, fieldType, fieldRecordBuilder, level + 1);
} else if (tag == ATypeTag.SERIALIZED_ORDEREDLIST_TYPE_TAG || tag == ATypeTag.SERIALIZED_UNORDEREDLIST_TYPE_TAG) {
addListField(tmpValue, fieldType, fieldRecordBuilder, level + 1);
}
}
// write record
fieldRecordBuilder.write(itemValue.getDataOutput(), true);
// add item to the list of fields
orderedListBuilder.addItem(itemValue);
}
orderedListBuilder.write(out, true);
}
Aggregations