Search in sources :

Example 1 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class FeedOperations method getConnectionJob.

private static JobSpecification getConnectionJob(SessionOutput sessionOutput, MetadataProvider metadataProvider, FeedConnection feedConnection, String[] locations, ILangCompilationProvider compilationProvider, IStorageComponentProvider storageComponentProvider, DefaultStatementExecutorFactory qtFactory, IHyracksClientConnection hcc) throws AlgebricksException, RemoteException, ACIDException {
    DataverseDecl dataverseDecl = new DataverseDecl(new Identifier(feedConnection.getDataverseName()));
    FeedConnectionRequest fcr = new FeedConnectionRequest(FeedRuntimeType.INTAKE, feedConnection.getAppliedFunctions(), feedConnection.getDatasetName(), feedConnection.getPolicyName(), feedConnection.getFeedId());
    SubscribeFeedStatement subscribeStmt = new SubscribeFeedStatement(locations, fcr);
    subscribeStmt.initialize(metadataProvider.getMetadataTxnContext());
    List<Statement> statements = new ArrayList<>();
    statements.add(dataverseDecl);
    statements.add(subscribeStmt);
    IStatementExecutor translator = qtFactory.create(metadataProvider.getApplicationContext(), statements, sessionOutput, compilationProvider, storageComponentProvider);
    // configure the metadata provider
    metadataProvider.getConfig().put(FunctionUtil.IMPORT_PRIVATE_FUNCTIONS, "" + Boolean.TRUE);
    metadataProvider.getConfig().put(FeedActivityDetails.FEED_POLICY_NAME, "" + subscribeStmt.getPolicy());
    metadataProvider.getConfig().put(FeedActivityDetails.COLLECT_LOCATIONS, StringUtils.join(subscribeStmt.getLocations(), ','));
    CompiledStatements.CompiledSubscribeFeedStatement csfs = new CompiledStatements.CompiledSubscribeFeedStatement(subscribeStmt.getSubscriptionRequest(), subscribeStmt.getVarCounter());
    return translator.rewriteCompileQuery(hcc, metadataProvider, subscribeStmt.getQuery(), csfs);
}
Also used : IStatementExecutor(org.apache.asterix.translator.IStatementExecutor) DataverseDecl(org.apache.asterix.lang.common.statement.DataverseDecl) Identifier(org.apache.asterix.lang.common.struct.Identifier) SubscribeFeedStatement(org.apache.asterix.lang.aql.statement.SubscribeFeedStatement) SubscribeFeedStatement(org.apache.asterix.lang.aql.statement.SubscribeFeedStatement) Statement(org.apache.asterix.lang.common.base.Statement) FeedConnectionRequest(org.apache.asterix.external.feed.management.FeedConnectionRequest) ArrayList(java.util.ArrayList) CompiledStatements(org.apache.asterix.translator.CompiledStatements)

Example 2 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier 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 3 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class SqlppAstPrintVisitor method visit.

@Override
public Void visit(GroupbyClause gc, Integer step) throws CompilationException {
    if (gc.isGroupAll()) {
        out.println(skip(step) + "Group All");
        return null;
    }
    out.println(skip(step) + "Groupby");
    for (GbyVariableExpressionPair pair : gc.getGbyPairList()) {
        if (pair.getVar() != null) {
            pair.getVar().accept(this, step + 1);
            out.println(skip(step + 1) + ":=");
        }
        pair.getExpr().accept(this, step + 1);
    }
    if (gc.hasGroupVar()) {
        out.print(skip(step + 1) + "GROUP AS ");
        gc.getGroupVar().accept(this, 0);
        if (gc.hasGroupFieldList()) {
            out.println(skip(step + 1) + "(");
            for (Pair<Expression, Identifier> field : gc.getGroupFieldList()) {
                out.print(skip(step + 2) + field.second + ":=");
                field.first.accept(this, 0);
            }
            out.println(skip(step + 1) + ")");
        }
    }
    out.println();
    return null;
}
Also used : Identifier(org.apache.asterix.lang.common.struct.Identifier) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)

Example 4 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class DeepCopyVisitor method visit.

@Override
public GroupbyClause visit(GroupbyClause gc, Void arg) throws CompilationException {
    List<GbyVariableExpressionPair> gbyPairList = new ArrayList<>();
    List<GbyVariableExpressionPair> decorPairList = new ArrayList<>();
    Map<Expression, VariableExpr> withVarMap = new HashMap<>();
    VariableExpr groupVarExpr = null;
    List<Pair<Expression, Identifier>> groupFieldList = new ArrayList<>();
    for (GbyVariableExpressionPair gbyVarExpr : gc.getGbyPairList()) {
        VariableExpr var = gbyVarExpr.getVar();
        gbyPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg), (Expression) gbyVarExpr.getExpr().accept(this, arg)));
    }
    for (GbyVariableExpressionPair gbyVarExpr : gc.getDecorPairList()) {
        VariableExpr var = gbyVarExpr.getVar();
        decorPairList.add(new GbyVariableExpressionPair(var == null ? null : (VariableExpr) var.accept(this, arg), (Expression) gbyVarExpr.getExpr().accept(this, arg)));
    }
    for (Entry<Expression, VariableExpr> entry : gc.getWithVarMap().entrySet()) {
        withVarMap.put((Expression) entry.getKey().accept(this, arg), (VariableExpr) entry.getValue().accept(this, arg));
    }
    if (gc.hasGroupVar()) {
        groupVarExpr = (VariableExpr) gc.getGroupVar().accept(this, arg);
    }
    for (Pair<Expression, Identifier> field : gc.getGroupFieldList()) {
        groupFieldList.add(new Pair<>((Expression) field.first.accept(this, arg), field.second));
    }
    return new GroupbyClause(gbyPairList, decorPairList, withVarMap, groupVarExpr, groupFieldList, gc.hasHashGroupByHint(), gc.isGroupAll());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Identifier(org.apache.asterix.lang.common.struct.Identifier) VarIdentifier(org.apache.asterix.lang.common.struct.VarIdentifier) GroupbyClause(org.apache.asterix.lang.common.clause.GroupbyClause) ILangExpression(org.apache.asterix.lang.common.base.ILangExpression) Expression(org.apache.asterix.lang.common.base.Expression) SelectExpression(org.apache.asterix.lang.sqlpp.expression.SelectExpression) CaseExpression(org.apache.asterix.lang.sqlpp.expression.CaseExpression) QuantifiedExpression(org.apache.asterix.lang.common.expression.QuantifiedExpression) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) GbyVariableExpressionPair(org.apache.asterix.lang.common.expression.GbyVariableExpressionPair) Pair(org.apache.hyracks.algebricks.common.utils.Pair) QuantifiedPair(org.apache.asterix.lang.common.struct.QuantifiedPair)

Example 5 with Identifier

use of org.apache.asterix.lang.common.struct.Identifier in project asterixdb by apache.

the class FormatPrintVisitor method visit.

@Override
public Void visit(DatasetDecl dd, Integer step) throws CompilationException {
    if (dd.getDatasetType() == DatasetType.INTERNAL) {
        String temp = dd.getDatasetDetailsDecl().isTemp() ? "temporary" : "";
        out.print(skip(step) + "create " + temp + datasetSymbol + generateFullName(dd.getDataverse(), dd.getName()) + generateIfNotExists(dd.getIfNotExists()) + "(" + dd.getQualifiedTypeName() + ")" + " primary key ");
        printDelimitedKeys(((InternalDetailsDecl) dd.getDatasetDetailsDecl()).getPartitioningExprs(), ",");
        if (((InternalDetailsDecl) dd.getDatasetDetailsDecl()).isAutogenerated()) {
            out.print(" autogenerated ");
        }
    } else if (dd.getDatasetType() == DatasetType.EXTERNAL) {
        out.print(skip(step) + "create external " + datasetSymbol + generateFullName(dd.getDataverse(), dd.getName()) + "(" + dd.getQualifiedTypeName() + ")" + generateIfNotExists(dd.getIfNotExists()));
        ExternalDetailsDecl externalDetails = (ExternalDetailsDecl) dd.getDatasetDetailsDecl();
        out.print(" using " + revertStringToQuoted(externalDetails.getAdapter()));
        printConfiguration(externalDetails.getProperties());
    }
    Identifier nodeGroupName = dd.getNodegroupName();
    if (nodeGroupName != null) {
        out.print(" on " + nodeGroupName.getValue());
    }
    Map<String, String> hints = dd.getHints();
    if (dd.getHints().size() > 0) {
        out.print(" hints ");
        printProperties(hints);
    }
    if (dd.getCompactionPolicy() != null) {
        out.print(" using compaction policy " + revertStringToQuoted(dd.getCompactionPolicy()));
        Map<String, String> compactionPolicyProperties = dd.getCompactionPolicyProperties();
        if (compactionPolicyProperties != null && compactionPolicyProperties.size() > 0) {
            printConfiguration(compactionPolicyProperties);
        }
    }
    if (dd.getDatasetType() == DatasetType.INTERNAL) {
        List<String> filterField = ((InternalDetailsDecl) dd.getDatasetDetailsDecl()).getFilterField();
        if (filterField != null && filterField.size() > 0) {
            out.print(" with filter on ");
            printNestField(filterField);
        }
    }
    out.println(SEMICOLON);
    out.println();
    return null;
}
Also used : InternalDetailsDecl(org.apache.asterix.lang.common.statement.InternalDetailsDecl) Identifier(org.apache.asterix.lang.common.struct.Identifier) ExternalDetailsDecl(org.apache.asterix.lang.common.statement.ExternalDetailsDecl)

Aggregations

Identifier (org.apache.asterix.lang.common.struct.Identifier)20 ArrayList (java.util.ArrayList)10 Expression (org.apache.asterix.lang.common.base.Expression)8 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)8 VarIdentifier (org.apache.asterix.lang.common.struct.VarIdentifier)8 GbyVariableExpressionPair (org.apache.asterix.lang.common.expression.GbyVariableExpressionPair)6 AsterixException (org.apache.asterix.common.exceptions.AsterixException)5 CompilationException (org.apache.asterix.common.exceptions.CompilationException)5 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)5 IOException (java.io.IOException)4 RemoteException (java.rmi.RemoteException)4 HashMap (java.util.HashMap)4 ACIDException (org.apache.asterix.common.exceptions.ACIDException)4 QuantifiedExpression (org.apache.asterix.lang.common.expression.QuantifiedExpression)4 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)4 MetadataException (org.apache.asterix.metadata.MetadataException)4 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)4 Pair (org.apache.hyracks.algebricks.common.utils.Pair)4 FunctionIdentifier (org.apache.hyracks.algebricks.core.algebra.functions.FunctionIdentifier)4 IDataset (org.apache.asterix.common.metadata.IDataset)3