Search in sources :

Example 6 with FromTerm

use of org.apache.asterix.lang.sqlpp.clause.FromTerm in project asterixdb by apache.

the class AbstractSqlppExpressionScopingVisitor method visit.

@Override
public Expression visit(FromClause fromClause, ILangExpression arg) throws CompilationException {
    Scope scopeForFromClause = scopeChecker.extendCurrentScope();
    for (FromTerm fromTerm : fromClause.getFromTerms()) {
        fromTerm.accept(this, fromClause);
        // Merges the variables defined in the current from term into the scope of the current from clause.
        Scope scopeForFromTerm = scopeChecker.removeCurrentScope();
        mergeScopes(scopeForFromClause, scopeForFromTerm);
    }
    return null;
}
Also used : Scope(org.apache.asterix.lang.common.context.Scope) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm)

Example 7 with FromTerm

use of org.apache.asterix.lang.sqlpp.clause.FromTerm in project asterixdb by apache.

the class SqlppExpressionToPlanTranslator method visit.

@Override
public Pair<ILogicalOperator, LogicalVariable> visit(FromClause fromClause, Mutable<ILogicalOperator> arg) throws CompilationException {
    Mutable<ILogicalOperator> inputSrc = arg;
    Pair<ILogicalOperator, LogicalVariable> topUnnest = null;
    for (FromTerm fromTerm : fromClause.getFromTerms()) {
        topUnnest = fromTerm.accept(this, inputSrc);
        inputSrc = new MutableObject<>(topUnnest.first);
    }
    return topUnnest;
}
Also used : LogicalVariable(org.apache.hyracks.algebricks.core.algebra.base.LogicalVariable) ILogicalOperator(org.apache.hyracks.algebricks.core.algebra.base.ILogicalOperator) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm)

Example 8 with FromTerm

use of org.apache.asterix.lang.sqlpp.clause.FromTerm in project asterixdb by apache.

the class DeepCopyVisitor method visit.

@Override
public FromTerm visit(FromTerm fromTerm, Void arg) throws CompilationException {
    // Visit the left expression of a from term.
    Expression fromExpr = (Expression) fromTerm.getLeftExpression().accept(this, arg);
    VariableExpr fromVar = (VariableExpr) fromTerm.getLeftVariable().accept(this, arg);
    VariableExpr positionVar = fromTerm.getPositionalVariable() == null ? null : (VariableExpr) fromTerm.getPositionalVariable().accept(this, arg);
    // Visits join/unnest/nest clauses.
    List<AbstractBinaryCorrelateClause> correlateClauses = new ArrayList<>();
    for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
        correlateClauses.add((AbstractBinaryCorrelateClause) correlateClause.accept(this, arg));
    }
    return new FromTerm(fromExpr, fromVar, positionVar, correlateClauses);
}
Also used : AbstractBinaryCorrelateClause(org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause) 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) ArrayList(java.util.ArrayList) VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm)

Example 9 with FromTerm

use of org.apache.asterix.lang.sqlpp.clause.FromTerm in project asterixdb by apache.

the class FreeVariableVisitor method visit.

@Override
public Void visit(FromClause fromClause, Collection<VariableExpr> freeVars) throws CompilationException {
    Collection<VariableExpr> bindingVars = new HashSet<>();
    for (FromTerm fromTerm : fromClause.getFromTerms()) {
        Collection<VariableExpr> fromTermFreeVars = new HashSet<>();
        fromTerm.accept(this, fromTermFreeVars);
        // Since a right from term can refer to variables defined in a left from term,
        // we remove binding variables from the free variables.
        fromTermFreeVars.removeAll(bindingVars);
        // Adds binding variables.
        bindingVars.addAll(SqlppVariableUtil.getBindingVariables(fromTerm));
        // Adds into freeVars.
        freeVars.addAll(fromTermFreeVars);
    }
    return null;
}
Also used : VariableExpr(org.apache.asterix.lang.common.expression.VariableExpr) FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm) HashSet(java.util.HashSet)

Example 10 with FromTerm

use of org.apache.asterix.lang.sqlpp.clause.FromTerm in project asterixdb by apache.

the class SqlppFormatPrintVisitor method visit.

@Override
public Void visit(FromClause fromClause, Integer step) throws CompilationException {
    out.print(skip(step) + "from ");
    int index = 0;
    for (FromTerm fromTerm : fromClause.getFromTerms()) {
        if (index > 0) {
            out.print(COMMA + "\n" + skip(step + 2));
        }
        fromTerm.accept(this, step + 2);
        ++index;
    }
    out.println();
    return null;
}
Also used : FromTerm(org.apache.asterix.lang.sqlpp.clause.FromTerm)

Aggregations

FromTerm (org.apache.asterix.lang.sqlpp.clause.FromTerm)11 VariableExpr (org.apache.asterix.lang.common.expression.VariableExpr)6 SelectExpression (org.apache.asterix.lang.sqlpp.expression.SelectExpression)5 ArrayList (java.util.ArrayList)4 Expression (org.apache.asterix.lang.common.base.Expression)4 ILangExpression (org.apache.asterix.lang.common.base.ILangExpression)4 FromClause (org.apache.asterix.lang.sqlpp.clause.FromClause)4 SelectBlock (org.apache.asterix.lang.sqlpp.clause.SelectBlock)3 SelectClause (org.apache.asterix.lang.sqlpp.clause.SelectClause)3 SelectElement (org.apache.asterix.lang.sqlpp.clause.SelectElement)3 SelectSetOperation (org.apache.asterix.lang.sqlpp.clause.SelectSetOperation)3 SetOperationInput (org.apache.asterix.lang.sqlpp.struct.SetOperationInput)3 VariableSubstitutionEnvironment (org.apache.asterix.lang.common.rewrites.VariableSubstitutionEnvironment)2 AbstractBinaryCorrelateClause (org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause)2 CaseExpression (org.apache.asterix.lang.sqlpp.expression.CaseExpression)2 Pair (org.apache.hyracks.algebricks.common.utils.Pair)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)1 LimitClause (org.apache.asterix.lang.common.clause.LimitClause)1