Search in sources :

Example 6 with Datatype

use of org.apache.asterix.metadata.entities.Datatype 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 7 with Datatype

use of org.apache.asterix.metadata.entities.Datatype in project asterixdb by apache.

the class MetadataNode method getNestedComplexDatatypeNamesForThisDatatype.

private List<String> getNestedComplexDatatypeNamesForThisDatatype(JobId jobId, String dataverseName, String datatypeName) throws MetadataException, RemoteException {
    //Return all field types that aren't builtin types
    Datatype parentType = getDatatype(jobId, dataverseName, datatypeName);
    List<IAType> subTypes = null;
    if (parentType.getDatatype().getTypeTag() == ATypeTag.OBJECT) {
        ARecordType recType = (ARecordType) parentType.getDatatype();
        subTypes = Arrays.asList(recType.getFieldTypes());
    } else if (parentType.getDatatype().getTypeTag() == ATypeTag.UNION) {
        AUnionType recType = (AUnionType) parentType.getDatatype();
        subTypes = recType.getUnionList();
    }
    List<String> nestedTypes = new ArrayList<>();
    if (subTypes != null) {
        for (IAType subType : subTypes) {
            if (!(subType instanceof BuiltinType)) {
                nestedTypes.add(subType.getTypeName());
            }
        }
    }
    return nestedTypes;
}
Also used : BuiltinType(org.apache.asterix.om.types.BuiltinType) AUnionType(org.apache.asterix.om.types.AUnionType) ArrayList(java.util.ArrayList) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) ARecordType(org.apache.asterix.om.types.ARecordType) Datatype(org.apache.asterix.metadata.entities.Datatype) IAType(org.apache.asterix.om.types.IAType)

Example 8 with Datatype

use of org.apache.asterix.metadata.entities.Datatype in project asterixdb by apache.

the class MetadataTransactionContext method dropDataDatatype.

public void dropDataDatatype(String dataverseName, String datatypeName) {
    Datatype datatype = new Datatype(dataverseName, datatypeName, null, false);
    droppedCache.addDatatypeIfNotExists(datatype);
    logAndApply(new MetadataLogicalOperation(datatype, false));
}
Also used : Datatype(org.apache.asterix.metadata.entities.Datatype)

Example 9 with Datatype

use of org.apache.asterix.metadata.entities.Datatype in project asterixdb by apache.

the class MetadataManager method getDatatype.

@Override
public Datatype getDatatype(MetadataTransactionContext ctx, String dataverseName, String datatypeName) throws MetadataException {
    // First look in the context to see if this transaction created the
    // requested datatype itself (but the datatype is still uncommitted).
    Datatype datatype = ctx.getDatatype(dataverseName, datatypeName);
    if (datatype != null) {
        // uncommitted.
        return datatype;
    }
    if (ctx.datatypeIsDropped(dataverseName, datatypeName)) {
        // in the cache.
        return null;
    }
    datatype = cache.getDatatype(dataverseName, datatypeName);
    if (datatype != null) {
        // Datatype is already in the cache, don't add it again.
        //create a new Datatype object with a new ARecordType object in order to avoid
        //concurrent access to UTF8StringPointable comparator in ARecordType object.
        //see issue 510
        ARecordType aRecType = (ARecordType) datatype.getDatatype();
        return new Datatype(datatype.getDataverseName(), datatype.getDatatypeName(), new ARecordType(aRecType.getTypeName(), aRecType.getFieldNames(), aRecType.getFieldTypes(), aRecType.isOpen()), datatype.getIsAnonymous());
    }
    try {
        datatype = metadataNode.getDatatype(ctx.getJobId(), dataverseName, datatypeName);
    } catch (RemoteException e) {
        throw new MetadataException(e);
    }
    // when this transaction commits.
    if (datatype != null) {
        ctx.addDatatype(datatype);
    }
    return datatype;
}
Also used : RemoteException(java.rmi.RemoteException) ARecordType(org.apache.asterix.om.types.ARecordType) Datatype(org.apache.asterix.metadata.entities.Datatype)

Example 10 with Datatype

use of org.apache.asterix.metadata.entities.Datatype in project asterixdb by apache.

the class QueryTranslator method handleTypeDropStatement.

protected void handleTypeDropStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
    TypeDropStatement stmtTypeDrop = (TypeDropStatement) stmt;
    String dataverseName = getActiveDataverse(stmtTypeDrop.getDataverseName());
    String typeName = stmtTypeDrop.getTypeName().getValue();
    MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
    metadataProvider.setMetadataTxnContext(mdTxnCtx);
    MetadataLockManager.INSTANCE.dropTypeBegin(metadataProvider.getLocks(), dataverseName, dataverseName + "." + typeName);
    try {
        Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, dataverseName, typeName);
        if (dt == null) {
            if (!stmtTypeDrop.getIfExists()) {
                throw new AlgebricksException("There is no datatype with this name " + typeName + ".");
            }
        } else {
            MetadataManager.INSTANCE.dropDatatype(mdTxnCtx, dataverseName, typeName);
        }
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
    } catch (Exception e) {
        abort(e, e, mdTxnCtx);
        throw e;
    } finally {
        metadataProvider.getLocks().unlock();
    }
}
Also used : AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) TypeDropStatement(org.apache.asterix.lang.common.statement.TypeDropStatement) ACIDException(org.apache.asterix.common.exceptions.ACIDException) MetadataException(org.apache.asterix.metadata.MetadataException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) CompilationException(org.apache.asterix.common.exceptions.CompilationException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) Datatype(org.apache.asterix.metadata.entities.Datatype)

Aggregations

Datatype (org.apache.asterix.metadata.entities.Datatype)18 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)9 ArrayList (java.util.ArrayList)8 ARecordType (org.apache.asterix.om.types.ARecordType)8 IAType (org.apache.asterix.om.types.IAType)8 ACIDException (org.apache.asterix.common.exceptions.ACIDException)7 RemoteException (java.rmi.RemoteException)6 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)6 MetadataException (org.apache.asterix.metadata.MetadataException)5 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)5 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)5 IOException (java.io.IOException)4 AsterixException (org.apache.asterix.common.exceptions.AsterixException)4 CompilationException (org.apache.asterix.common.exceptions.CompilationException)4 Dataset (org.apache.asterix.metadata.entities.Dataset)4 List (java.util.List)3 DatatypeTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.DatatypeTupleTranslator)3 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)3 Date (java.util.Date)2 IDataset (org.apache.asterix.common.metadata.IDataset)2