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());
}
}
}
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;
}
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));
}
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;
}
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();
}
}
Aggregations