use of org.apache.asterix.builders.UnorderedListBuilder in project asterixdb by apache.
the class ADMDataParser method parseUnorderedList.
private void parseUnorderedList(AUnorderedListType uoltype, DataOutput out) throws IOException {
ArrayBackedValueStorage itemBuffer = getTempBuffer();
UnorderedListBuilder unorderedListBuilder = (UnorderedListBuilder) getUnorderedListBuilder();
IAType itemType = null;
if (uoltype != null) {
itemType = uoltype.getItemType();
}
unorderedListBuilder.reset(uoltype);
int token;
boolean inList = true;
boolean expectingListItem = false;
boolean first = true;
do {
token = admLexer.next();
if (token == AdmLexer.TOKEN_END_RECORD) {
if (admLexer.next() == AdmLexer.TOKEN_END_RECORD) {
if (expectingListItem) {
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_END_COLLECTION);
} else {
inList = false;
}
} else {
throw new ParseException(ErrorCode.PARSER_ADM_DATA_PARSER_LIST_FOUND_END_RECOD);
}
} 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());
unorderedListBuilder.addItem(itemBuffer);
}
first = false;
} while (inList);
unorderedListBuilder.write(out, true);
}
use of org.apache.asterix.builders.UnorderedListBuilder in project asterixdb by apache.
the class AUnorderedListSerializerDeserializer method serialize.
@SuppressWarnings("unchecked")
@Override
public void serialize(AUnorderedList instance, DataOutput out) throws HyracksDataException {
// TODO: schemaless ordered list serializer
UnorderedListBuilder listBuilder = new UnorderedListBuilder();
ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
listBuilder.reset(unorderedlistType);
IACursor cursor = instance.getCursor();
while (cursor.next()) {
itemValue.reset();
serializer.serialize(cursor.get(), itemValue.getDataOutput());
listBuilder.addItem(itemValue);
}
listBuilder.write(out, false);
}
use of org.apache.asterix.builders.UnorderedListBuilder in project asterixdb by apache.
the class HiveRecordParser method parseUnorderedList.
private void parseUnorderedList(AUnorderedListType uoltype, Object obj, ListObjectInspector oi) throws IOException {
UnorderedListBuilder unorderedListBuilder = getUnorderedListBuilder();
IAType itemType = null;
if (uoltype != null)
itemType = uoltype.getItemType();
byte tagByte = itemType.getTypeTag().serialize();
unorderedListBuilder.reset(uoltype);
int n = oi.getListLength(obj);
for (int i = 0; i < n; i++) {
Object element = oi.getListElement(obj, i);
ObjectInspector eoi = oi.getListElementObjectInspector();
if (element == null) {
throw new RuntimeDataException(ErrorCode.PARSER_HIVE_NULL_VALUE_IN_LIST);
}
listItemBuffer.reset();
final DataOutput dataOutput = listItemBuffer.getDataOutput();
dataOutput.writeByte(tagByte);
parseItem(itemType, element, eoi, dataOutput, true);
unorderedListBuilder.addItem(listItemBuffer);
}
unorderedListBuilder.write(fieldValueBuffer.getDataOutput(), true);
}
Aggregations