Search in sources :

Example 11 with AbstractCollectionType

use of org.apache.asterix.om.types.AbstractCollectionType in project asterixdb by apache.

the class TypeResolverUtilTest method testUnorderedListType.

@Test
public void testUnorderedListType() {
    // Constructs input types.
    ARecordType leftRecordType = new ARecordType(null, new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, BuiltinType.AINT32 }, true, Collections.singleton("d"));
    AUnorderedListType leftListType = new AUnorderedListType(leftRecordType, null);
    AUnorderedListType rightListType = new AUnorderedListType(BuiltinType.ASTRING, null);
    // Gets the actual resolved type.
    List<IAType> inputTypes = new ArrayList<>();
    inputTypes.add(leftListType);
    inputTypes.add(rightListType);
    AbstractCollectionType resolvedType = (AbstractCollectionType) TypeResolverUtil.resolve(inputTypes);
    // Compares the resolved type and the expected type.
    Assert.assertEquals(resolvedType, new AUnorderedListType(BuiltinType.ANY, null));
}
Also used : ArrayList(java.util.ArrayList) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType) ARecordType(org.apache.asterix.om.types.ARecordType) AUnorderedListType(org.apache.asterix.om.types.AUnorderedListType) IAType(org.apache.asterix.om.types.IAType) Test(org.junit.Test)

Example 12 with AbstractCollectionType

use of org.apache.asterix.om.types.AbstractCollectionType 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);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) AListPointable(org.apache.asterix.om.pointables.nonvisitor.AListPointable) IARecordBuilder(org.apache.asterix.builders.IARecordBuilder) OrderedListBuilder(org.apache.asterix.builders.OrderedListBuilder) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType)

Aggregations

AbstractCollectionType (org.apache.asterix.om.types.AbstractCollectionType)12 IAType (org.apache.asterix.om.types.IAType)10 ATypeTag (org.apache.asterix.om.types.ATypeTag)4 ArrayList (java.util.ArrayList)3 ARecordType (org.apache.asterix.om.types.ARecordType)3 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)3 AUnionType (org.apache.asterix.om.types.AUnionType)2 TypeSignature (org.apache.asterix.om.types.TypeSignature)2 AbstractFunctionCallExpression (org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression)2 Test (org.junit.Test)2 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 IARecordBuilder (org.apache.asterix.builders.IARecordBuilder)1 OrderedListBuilder (org.apache.asterix.builders.OrderedListBuilder)1 Datatype (org.apache.asterix.metadata.entities.Datatype)1 TypeMismatchException (org.apache.asterix.om.exceptions.TypeMismatchException)1 AListPointable (org.apache.asterix.om.pointables.nonvisitor.AListPointable)1 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)1 AUnorderedListType (org.apache.asterix.om.types.AUnorderedListType)1