Search in sources :

Example 6 with UnorderedListBuilder

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);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder) IAType(org.apache.asterix.om.types.IAType)

Example 7 with UnorderedListBuilder

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);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IACursor(org.apache.asterix.om.base.IACursor) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder)

Example 8 with UnorderedListBuilder

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);
}
Also used : DataOutput(java.io.DataOutput) ListObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector) IntObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.IntObjectInspector) BooleanObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector) ShortObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.ShortObjectInspector) ObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector) LongObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.LongObjectInspector) StructObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector) FloatObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.FloatObjectInspector) StringObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.StringObjectInspector) ByteObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector) DoubleObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector) TimestampObjectInspector(org.apache.hadoop.hive.serde2.objectinspector.primitive.TimestampObjectInspector) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder) IAType(org.apache.asterix.om.types.IAType) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Aggregations

UnorderedListBuilder (org.apache.asterix.builders.UnorderedListBuilder)8 ArrayBackedValueStorage (org.apache.hyracks.data.std.util.ArrayBackedValueStorage)7 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AMutableString (org.apache.asterix.om.base.AMutableString)3 AString (org.apache.asterix.om.base.AString)3 IAType (org.apache.asterix.om.types.IAType)3 DataOutput (java.io.DataOutput)1 LinkedHashMap (java.util.LinkedHashMap)1 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)1 RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)1 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)1 ExprTree (org.apache.asterix.external.classad.ExprTree)1 IACursor (org.apache.asterix.om.base.IACursor)1 ListObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector)1 ObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector)1 StructObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector)1 BooleanObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.BooleanObjectInspector)1 ByteObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.ByteObjectInspector)1 DoubleObjectInspector (org.apache.hadoop.hive.serde2.objectinspector.primitive.DoubleObjectInspector)1