Search in sources :

Example 6 with AbstractCollectionType

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

the class TypeTranslator method secondPass.

private static void secondPass(MetadataTransactionContext mdTxnCtx, Map<TypeSignature, IAType> typeMap, Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes, Map<TypeSignature, List<TypeSignature>> incompleteTopLevelTypeReferences, String typeDataverse) throws AlgebricksException {
    // solve remaining top level references
    for (TypeSignature typeSignature : incompleteTopLevelTypeReferences.keySet()) {
        IAType t;
        Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeSignature.getNamespace(), typeSignature.getName());
        if (dt == null) {
            throw new AlgebricksException("Could not resolve type " + typeSignature);
        } else {
            t = dt.getDatatype();
        }
        for (TypeSignature sign : incompleteTopLevelTypeReferences.get(typeSignature)) {
            typeMap.put(sign, t);
        }
    }
    // solve remaining field type references
    for (String trefName : incompleteFieldTypes.keySet()) {
        IAType t;
        Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeDataverse, trefName);
        if (dt == null) {
            dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, MetadataConstants.METADATA_DATAVERSE_NAME, trefName);
        }
        if (dt == null) {
            throw new AlgebricksException("Could not resolve type " + trefName);
        } else {
            t = dt.getDatatype();
        }
        Map<ARecordType, List<Integer>> fieldsToFix = incompleteFieldTypes.get(trefName);
        for (ARecordType recType : fieldsToFix.keySet()) {
            List<Integer> positions = fieldsToFix.get(recType);
            IAType[] fldTypes = recType.getFieldTypes();
            for (Integer pos : positions) {
                if (fldTypes[pos] == null) {
                    fldTypes[pos] = t;
                } else {
                    // nullable
                    AUnionType nullableUnion = (AUnionType) fldTypes[pos];
                    nullableUnion.setActualType(t);
                }
            }
        }
    }
    // solve remaining item type references
    for (TypeSignature typeSignature : incompleteItemTypes.keySet()) {
        IAType t;
        Datatype dt;
        if (MetadataManager.INSTANCE != null) {
            dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeSignature.getNamespace(), typeSignature.getName());
            if (dt == null) {
                throw new AlgebricksException("Could not resolve type " + typeSignature);
            }
            t = dt.getDatatype();
        } else {
            t = typeMap.get(typeSignature);
        }
        for (AbstractCollectionType act : incompleteItemTypes.get(typeSignature)) {
            act.setItemType(t);
        }
    }
}
Also used : AUnionType(org.apache.asterix.om.types.AUnionType) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) Datatype(org.apache.asterix.metadata.entities.Datatype) TypeSignature(org.apache.asterix.om.types.TypeSignature) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType)

Example 7 with AbstractCollectionType

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

the class CollectionToSequenceTypeComputer method getResultType.

@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
    IAType argType = strippedInputTypes[0];
    ATypeTag argTypeTag = argType.getTypeTag();
    if (argTypeTag == ATypeTag.ARRAY || argTypeTag == ATypeTag.MULTISET) {
        /** if the input is a singleton list, return it's item type if any */
        AbstractCollectionType collectionType = (AbstractCollectionType) argType;
        return collectionType.getItemType();
    } else {
        /** if the input is not a singleton list, return the original input type */
        return argType;
    }
}
Also used : ATypeTag(org.apache.asterix.om.types.ATypeTag) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType) IAType(org.apache.asterix.om.types.IAType)

Example 8 with AbstractCollectionType

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

the class DatatypeTupleTranslator method writeCollectionType.

private void writeCollectionType(Datatype instance, AbstractComplexType type, DataOutput out) throws HyracksDataException {
    AbstractCollectionType listType = (AbstractCollectionType) type;
    IAType itemType = listType.getItemType();
    if (itemType.getTypeTag().isDerivedType()) {
        handleNestedDerivedType(itemType.getTypeName(), (AbstractComplexType) itemType, instance, instance.getDataverseName(), instance.getDatatypeName());
    }
    aString.setValue(listType.getItemType().getTypeName());
    stringSerde.serialize(aString, out);
}
Also used : AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType) IAType(org.apache.asterix.om.types.IAType)

Example 9 with AbstractCollectionType

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

the class ScalarVersionOfAggregateResultType method getResultType.

@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
    ATypeTag tag = strippedInputTypes[0].getTypeTag();
    if (tag == ATypeTag.ANY) {
        return BuiltinType.ANY;
    }
    if (tag != ATypeTag.ARRAY && tag != ATypeTag.MULTISET) {
        return strippedInputTypes[0];
    }
    AbstractCollectionType act = (AbstractCollectionType) strippedInputTypes[0];
    IAType t = act.getItemType();
    return AUnionType.createUnknownableType(t);
}
Also used : ATypeTag(org.apache.asterix.om.types.ATypeTag) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType) IAType(org.apache.asterix.om.types.IAType)

Example 10 with AbstractCollectionType

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

the class SubsetCollectionTypeComputer method computeType.

@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> mp) throws AlgebricksException {
    AbstractFunctionCallExpression fun = (AbstractFunctionCallExpression) expression;
    String funcName = fun.getFunctionIdentifier().getName();
    IAType t = (IAType) env.getType(fun.getArguments().get(0).getValue());
    ATypeTag actualTypeTag = t.getTypeTag();
    switch(actualTypeTag) {
        case MULTISET:
        case ARRAY:
            {
                AbstractCollectionType act = (AbstractCollectionType) t;
                return act.getItemType();
            }
        case UNION:
            {
                AUnionType ut = (AUnionType) t;
                if (!ut.isUnknownableType()) {
                    throw new TypeMismatchException(funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY);
                }
                IAType t2 = ut.getActualType();
                ATypeTag tag2 = t2.getTypeTag();
                if (tag2 == ATypeTag.MULTISET || tag2 == ATypeTag.ARRAY) {
                    AbstractCollectionType act = (AbstractCollectionType) t2;
                    return act.getItemType();
                }
                throw new TypeMismatchException(funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY);
            }
        case ANY:
            return BuiltinType.ANY;
        default:
            throw new TypeMismatchException(funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY);
    }
}
Also used : ATypeTag(org.apache.asterix.om.types.ATypeTag) AUnionType(org.apache.asterix.om.types.AUnionType) AbstractFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression) TypeMismatchException(org.apache.asterix.om.exceptions.TypeMismatchException) AbstractCollectionType(org.apache.asterix.om.types.AbstractCollectionType) IAType(org.apache.asterix.om.types.IAType)

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