use of org.apache.asterix.lang.common.statement.TypeDecl in project asterixdb by apache.
the class QueryTranslator method handleCreateTypeStatement.
protected void handleCreateTypeStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
TypeDecl stmtCreateType = (TypeDecl) stmt;
String dataverseName = getActiveDataverse(stmtCreateType.getDataverseName());
String typeName = stmtCreateType.getIdent().getValue();
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
MetadataLockManager.INSTANCE.createTypeBegin(metadataProvider.getLocks(), dataverseName, dataverseName + "." + typeName);
try {
Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dataverseName);
if (dv == null) {
throw new AlgebricksException("Unknown dataverse " + dataverseName);
}
Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, dataverseName, typeName);
if (dt != null) {
if (!stmtCreateType.getIfNotExists()) {
throw new AlgebricksException("A datatype with this name " + typeName + " already exists.");
}
} else {
if (BuiltinTypeMap.getBuiltinType(typeName) != null) {
throw new AlgebricksException("Cannot redefine builtin type " + typeName + ".");
} else {
Map<TypeSignature, IAType> typeMap = TypeTranslator.computeTypes(mdTxnCtx, stmtCreateType.getTypeDef(), stmtCreateType.getIdent().getValue(), dataverseName);
TypeSignature typeSignature = new TypeSignature(dataverseName, typeName);
IAType type = typeMap.get(typeSignature);
MetadataManager.INSTANCE.addDatatype(mdTxnCtx, new Datatype(dataverseName, typeName, type, false));
}
}
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
} catch (Exception e) {
abort(e, e, mdTxnCtx);
throw e;
} finally {
metadataProvider.getLocks().unlock();
}
}
use of org.apache.asterix.lang.common.statement.TypeDecl in project asterixdb by apache.
the class ADGenDmlTranslator method translate.
public void translate() throws AsterixException, MetadataException, AlgebricksException {
String defaultDataverse = getDefaultDataverse();
types = new HashMap<TypeSignature, IAType>();
typeDataGenMap = new HashMap<TypeSignature, TypeDataGen>();
for (Statement stmt : aqlStatements) {
if (stmt.getKind() == Statement.Kind.TYPE_DECL) {
TypeDecl td = (TypeDecl) stmt;
String typeDataverse = td.getDataverseName() == null ? defaultDataverse : td.getDataverseName().getValue();
Map<TypeSignature, IAType> typeInStmt = TypeTranslator.computeTypes(mdTxnCtx, td.getTypeDef(), td.getIdent().getValue(), typeDataverse, types);
types.putAll(typeInStmt);
TypeSignature signature = new TypeSignature(typeDataverse, td.getIdent().getValue());
TypeDataGen tdg = td.getDatagenAnnotation();
if (tdg != null) {
typeDataGenMap.put(signature, tdg);
}
}
}
}
Aggregations