Search in sources :

Example 6 with FunctionSignature

use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.

the class ExternalLibraryUtils method uninstallLibrary.

/**
     * Remove the library from metadata completely.
     * TODO Currently, external libraries only include functions and adapters. we need to extend this to include:
     * 1. external data source
     * 2. data parser
     *
     * @param dataverse
     * @param libraryName
     * @return true if the library was found and removed, false otherwise
     * @throws AsterixException
     * @throws RemoteException
     * @throws ACIDException
     */
protected static boolean uninstallLibrary(String dataverse, String libraryName) throws AsterixException, RemoteException, ACIDException {
    MetadataTransactionContext mdTxnCtx = null;
    try {
        // begin transaction
        mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
        // make sure dataverse exists
        Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dataverse);
        if (dv == null) {
            return false;
        }
        // make sure library exists
        Library library = MetadataManager.INSTANCE.getLibrary(mdTxnCtx, dataverse, libraryName);
        if (library == null) {
            return false;
        }
        // get dataverse functions
        List<Function> functions = MetadataManager.INSTANCE.getDataverseFunctions(mdTxnCtx, dataverse);
        for (Function function : functions) {
            // does function belong to library?
            if (function.getName().startsWith(libraryName + "#")) {
                // drop the function
                MetadataManager.INSTANCE.dropFunction(mdTxnCtx, new FunctionSignature(dataverse, function.getName(), function.getArity()));
            }
        }
        // get the dataverse adapters
        List<DatasourceAdapter> adapters = MetadataManager.INSTANCE.getDataverseAdapters(mdTxnCtx, dataverse);
        for (DatasourceAdapter adapter : adapters) {
            // belong to the library?
            if (adapter.getAdapterIdentifier().getName().startsWith(libraryName + "#")) {
                // remove adapter <! we didn't check if there are feeds which use this adapter>
                MetadataManager.INSTANCE.dropAdapter(mdTxnCtx, dataverse, adapter.getAdapterIdentifier().getName());
            }
        }
        // drop the library itself
        MetadataManager.INSTANCE.dropLibrary(mdTxnCtx, dataverse, libraryName);
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
    } catch (Exception e) {
        MetadataManager.INSTANCE.abortTransaction(mdTxnCtx);
        throw new AsterixException(e);
    }
    return true;
}
Also used : Function(org.apache.asterix.metadata.entities.Function) LibraryFunction(org.apache.asterix.external.library.LibraryFunction) DatasourceAdapter(org.apache.asterix.metadata.entities.DatasourceAdapter) AsterixException(org.apache.asterix.common.exceptions.AsterixException) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) Library(org.apache.asterix.metadata.entities.Library) ExternalLibrary(org.apache.asterix.external.library.ExternalLibrary) Dataverse(org.apache.asterix.metadata.entities.Dataverse) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ACIDException(org.apache.asterix.common.exceptions.ACIDException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException)

Example 7 with FunctionSignature

use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.

the class QueryTranslator method handleDisconnectFeedStatement.

protected void handleDisconnectFeedStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
    DisconnectFeedStatement cfs = (DisconnectFeedStatement) stmt;
    String dataverseName = getActiveDataverse(cfs.getDataverseName());
    String datasetName = cfs.getDatasetName().getValue();
    String feedName = cfs.getFeedName().getValue();
    MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
    metadataProvider.setMetadataTxnContext(mdTxnCtx);
    ActiveLifecycleListener activeListener = (ActiveLifecycleListener) appCtx.getActiveLifecycleListener();
    ActiveJobNotificationHandler activeEventHandler = activeListener.getNotificationHandler();
    // Check whether feed is alive
    if (activeEventHandler.getActiveEntityListener(new EntityId(Feed.EXTENSION_NAME, dataverseName, feedName)) != null) {
        throw new CompilationException(ErrorCode.FEED_CHANGE_FEED_CONNECTIVITY_ON_ALIVE_FEED, feedName);
    }
    MetadataLockManager.INSTANCE.disconnectFeedBegin(metadataProvider.getLocks(), dataverseName, dataverseName + "." + datasetName, dataverseName + "." + cfs.getFeedName());
    try {
        FeedMetadataUtil.validateIfDatasetExists(metadataProvider, dataverseName, cfs.getDatasetName().getValue(), mdTxnCtx);
        FeedMetadataUtil.validateIfFeedExists(dataverseName, cfs.getFeedName().getValue(), mdTxnCtx);
        FeedConnection fc = MetadataManager.INSTANCE.getFeedConnection(metadataProvider.getMetadataTxnContext(), dataverseName, feedName, datasetName);
        if (fc == null) {
            throw new CompilationException("Feed " + feedName + " is currently not connected to " + cfs.getDatasetName().getValue() + ". Invalid operation!");
        }
        MetadataManager.INSTANCE.dropFeedConnection(mdTxnCtx, dataverseName, feedName, datasetName);
        for (FunctionSignature functionSignature : fc.getAppliedFunctions()) {
            Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, functionSignature);
            function.dereference();
            MetadataManager.INSTANCE.updateFunction(mdTxnCtx, function);
        }
        MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
    } catch (Exception e) {
        abort(e, e, mdTxnCtx);
        throw e;
    } finally {
        metadataProvider.getLocks().unlock();
    }
}
Also used : EntityId(org.apache.asterix.active.EntityId) CompilationException(org.apache.asterix.common.exceptions.CompilationException) Function(org.apache.asterix.metadata.entities.Function) ActiveLifecycleListener(org.apache.asterix.active.ActiveLifecycleListener) FeedConnection(org.apache.asterix.metadata.entities.FeedConnection) DisconnectFeedStatement(org.apache.asterix.lang.common.statement.DisconnectFeedStatement) MetadataTransactionContext(org.apache.asterix.metadata.MetadataTransactionContext) ActiveJobNotificationHandler(org.apache.asterix.active.ActiveJobNotificationHandler) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) 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)

Example 8 with FunctionSignature

use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.

the class AqlBuiltinFunctionRewriteVisitor method visit.

@Override
public Expression visit(CallExpr callExpr, ILangExpression arg) throws CompilationException {
    FunctionSignature functionSignature = callExpr.getFunctionSignature();
    callExpr.setFunctionSignature(CommonFunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature));
    List<Expression> newExprList = new ArrayList<>();
    for (Expression expr : callExpr.getExprList()) {
        newExprList.add(expr.accept(this, arg));
    }
    callExpr.setExprList(newExprList);
    return callExpr;
}
Also used : Expression(org.apache.asterix.lang.common.base.Expression) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) ArrayList(java.util.ArrayList) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Example 9 with FunctionSignature

use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.

the class SqlppDeleteRewriteVisitor method visit.

@Override
public Void visit(DeleteStatement deleteStmt, Void visitArg) {
    List<Expression> arguments = new ArrayList<>();
    Identifier dataverseName = deleteStmt.getDataverseName();
    Identifier datasetName = deleteStmt.getDatasetName();
    String arg = dataverseName == null ? datasetName.getValue() : dataverseName.getValue() + "." + datasetName.getValue();
    LiteralExpr argumentLiteral = new LiteralExpr(new StringLiteral(arg));
    arguments.add(argumentLiteral);
    CallExpr callExpression = new CallExpr(new FunctionSignature(FunctionConstants.ASTERIX_NS, "dataset", 1), arguments);
    // From clause.
    VariableExpr var = deleteStmt.getVariableExpr();
    FromTerm fromTerm = new FromTerm(callExpression, var, null, null);
    @SuppressWarnings("unchecked") FromClause fromClause = new FromClause(Collections.singletonList(fromTerm));
    // Where clause.
    WhereClause whereClause = null;
    Expression condition = deleteStmt.getCondition();
    if (condition != null) {
        whereClause = new WhereClause(condition);
    }
    // Select clause.
    VariableExpr returnExpr = new VariableExpr(var.getVar());
    returnExpr.setIsNewVar(false);
    SelectElement selectElement = new SelectElement(returnExpr);
    SelectClause selectClause = new SelectClause(selectElement, null, false);
    // Construct the select expression.
    SelectBlock selectBlock = new SelectBlock(selectClause, fromClause, null, whereClause, null, null, null);
    SelectSetOperation selectSetOperation = new SelectSetOperation(new SetOperationInput(selectBlock, null), null);
    SelectExpression selectExpression = new SelectExpression(null, selectSetOperation, null, null, false);
    Query query = new Query(false, false, selectExpression, 0);
    query.setBody(selectExpression);
    // return the delete statement.
    deleteStmt.setQuery(query);
    return null;
}
Also used : SelectElement(org.apache.asterix.lang.sqlpp.clause.SelectElement) SelectClause(org.apache.asterix.lang.sqlpp.clause.SelectClause) Query(org.apache.asterix.lang.common.statement.Query) ArrayList(java.util.ArrayList) WhereClause(org.apache.asterix.lang.common.clause.WhereClause) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature) Identifier(org.apache.asterix.lang.common.struct.Identifier) StringLiteral(org.apache.asterix.lang.common.literal.StringLiteral) SelectBlock(org.apache.asterix.lang.sqlpp.clause.SelectBlock) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) FromClause(org.apache.asterix.lang.sqlpp.clause.FromClause) SetOperationInput(org.apache.asterix.lang.sqlpp.struct.SetOperationInput) SelectSetOperation(org.apache.asterix.lang.sqlpp.clause.SelectSetOperation) LiteralExpr(org.apache.asterix.lang.common.expression.LiteralExpr) CallExpr(org.apache.asterix.lang.common.expression.CallExpr) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm)

Example 10 with FunctionSignature

use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.

the class SqlppAstPrintVisitor method visit.

@Override
public Void visit(CallExpr pf, Integer step) throws CompilationException {
    FunctionSignature functionSignature = pf.getFunctionSignature();
    FunctionSignature normalizedFunctionSignature = FunctionMapUtil.normalizeBuiltinFunctionSignature(functionSignature, false);
    if (BuiltinFunctions.isBuiltinCompilerFunction(normalizedFunctionSignature, true)) {
        functionSignature = normalizedFunctionSignature;
    }
    out.println(skip(step) + "FunctionCall " + functionSignature.toString() + "[");
    for (Expression expr : pf.getExprList()) {
        expr.accept(this, step + 1);
    }
    out.println(skip(step) + "]");
    return null;
}
Also used : CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Aggregations

FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)30 ArrayList (java.util.ArrayList)11 Expression (org.apache.asterix.lang.common.base.Expression)11 Function (org.apache.asterix.metadata.entities.Function)9 CompilationException (org.apache.asterix.common.exceptions.CompilationException)8 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)6 ACIDException (org.apache.asterix.common.exceptions.ACIDException)5 IOException (java.io.IOException)4 RemoteException (java.rmi.RemoteException)4 AsterixException (org.apache.asterix.common.exceptions.AsterixException)4 CallExpr (org.apache.asterix.lang.common.expression.CallExpr)4 LiteralExpr (org.apache.asterix.lang.common.expression.LiteralExpr)4 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)4 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)4 MetadataException (org.apache.asterix.metadata.MetadataException)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 EntityId (org.apache.asterix.active.EntityId)3 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)3 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)3 FeedConnection (org.apache.asterix.metadata.entities.FeedConnection)3