Search in sources :

Example 1 with AbstractComplexType

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

the class MetadataNode method confirmDatatypeIsUnusedByDatatypes.

private void confirmDatatypeIsUnusedByDatatypes(JobId jobId, String dataverseName, String datatypeName) throws MetadataException, RemoteException {
    //If any datatype uses this type, throw an error
    //TODO: Currently this loads all types into memory. This will need to be fixed for large numbers of types
    Datatype dataTypeToBeDropped = getDatatype(jobId, dataverseName, datatypeName);
    assert dataTypeToBeDropped != null;
    IAType typeToBeDropped = dataTypeToBeDropped.getDatatype();
    List<Datatype> datatypes = getAllDatatypes(jobId);
    for (Datatype dataType : datatypes) {
        //skip types in different dataverses as well as the type to be dropped itself
        if (!dataType.getDataverseName().equals(dataverseName) || dataType.getDatatype().getTypeName().equals(datatypeName)) {
            continue;
        }
        AbstractComplexType recType = (AbstractComplexType) dataType.getDatatype();
        if (recType.containsType(typeToBeDropped)) {
            throw new MetadataException("Cannot drop type " + dataverseName + "." + datatypeName + " being used by type " + dataverseName + "." + recType.getTypeName());
        }
    }
}
Also used : AbstractComplexType(org.apache.asterix.om.types.AbstractComplexType) Datatype(org.apache.asterix.metadata.entities.Datatype) IAType(org.apache.asterix.om.types.IAType)

Example 2 with AbstractComplexType

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

the class TypeTranslator method computeTypes.

public static Map<TypeSignature, IAType> computeTypes(MetadataTransactionContext mdTxnCtx, TypeExpression typeExpr, String typeName, String typeDataverse, Map<TypeSignature, IAType> typeMap) throws AlgebricksException {
    Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes = new HashMap<>();
    Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes = new HashMap<>();
    Map<TypeSignature, List<TypeSignature>> incompleteTopLevelTypeReferences = new HashMap<>();
    firstPass(typeExpr, typeName, typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences, typeDataverse);
    secondPass(mdTxnCtx, typeMap, incompleteFieldTypes, incompleteItemTypes, incompleteTopLevelTypeReferences, typeDataverse);
    for (IAType type : typeMap.values()) {
        if (type.getTypeTag().isDerivedType()) {
            ((AbstractComplexType) type).generateNestedDerivedTypeNames();
        }
    }
    return typeMap;
}
Also used : TypeSignature(org.apache.asterix.om.types.TypeSignature) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) AbstractComplexType(org.apache.asterix.om.types.AbstractComplexType) HashMap(java.util.HashMap) Map(java.util.Map) BuiltinTypeMap(org.apache.asterix.metadata.entities.BuiltinTypeMap) IAType(org.apache.asterix.om.types.IAType)

Aggregations

AbstractComplexType (org.apache.asterix.om.types.AbstractComplexType)2 IAType (org.apache.asterix.om.types.IAType)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 BuiltinTypeMap (org.apache.asterix.metadata.entities.BuiltinTypeMap)1 Datatype (org.apache.asterix.metadata.entities.Datatype)1 TypeSignature (org.apache.asterix.om.types.TypeSignature)1