use of org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause in project asterixdb by apache.
the class SqlppExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(FromTerm fromTerm, Mutable<ILogicalOperator> tupSource) throws CompilationException {
LogicalVariable fromVar = context.newVarFromExpression(fromTerm.getLeftVariable());
Expression fromExpr = fromTerm.getLeftExpression();
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(fromExpr, tupSource);
ILogicalOperator unnestOp;
if (fromTerm.hasPositionalVariable()) {
LogicalVariable pVar = context.newVarFromExpression(fromTerm.getPositionalVariable());
// We set the positional variable type as BIGINT type.
unnestOp = new UnnestOperator(fromVar, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)), pVar, BuiltinType.AINT64, new PositionWriter());
} else {
unnestOp = new UnnestOperator(fromVar, new MutableObject<ILogicalExpression>(makeUnnestExpression(eo.first)));
}
unnestOp.getInputs().add(eo.second);
// Processes joins, unnests, and nests.
Mutable<ILogicalOperator> topOpRef = new MutableObject<>(unnestOp);
if (fromTerm.hasCorrelateClauses()) {
for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
if (correlateClause.getClauseType() == ClauseType.UNNEST_CLAUSE) {
// Correlation is allowed.
topOpRef = new MutableObject<>(correlateClause.accept(this, topOpRef).first);
} else {
// Correlation is dis-allowed.
uncorrelatedLeftBranchStack.push(topOpRef);
topOpRef = new MutableObject<>(correlateClause.accept(this, tupSource).first);
}
}
}
return new Pair<>(topOpRef.getValue(), fromVar);
}
use of org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause in project asterixdb by apache.
the class SqlppCloneAndSubstituteVariablesVisitor method visit.
@Override
public Pair<ILangExpression, VariableSubstitutionEnvironment> visit(FromTerm fromTerm, VariableSubstitutionEnvironment env) throws CompilationException {
VariableExpr leftVar = fromTerm.getLeftVariable();
VariableExpr newLeftVar = generateNewVariable(context, leftVar);
VariableExpr newLeftPosVar = fromTerm.hasPositionalVariable() ? generateNewVariable(context, fromTerm.getPositionalVariable()) : null;
Expression newLeftExpr = (Expression) visitUnnesBindingExpression(fromTerm.getLeftExpression(), env).first;
List<AbstractBinaryCorrelateClause> newCorrelateClauses = new ArrayList<>();
VariableSubstitutionEnvironment currentEnv = new VariableSubstitutionEnvironment(env);
currentEnv.removeSubstitution(newLeftVar);
if (newLeftPosVar != null) {
currentEnv.removeSubstitution(newLeftPosVar);
}
for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
if (correlateClause.getClauseType() == ClauseType.UNNEST_CLAUSE) {
// The right-hand-side of unnest could be correlated with the left side,
// therefore we propagate the substitution environment of the left-side.
Pair<ILangExpression, VariableSubstitutionEnvironment> p = correlateClause.accept(this, currentEnv);
currentEnv = p.second;
newCorrelateClauses.add((AbstractBinaryCorrelateClause) p.first);
} else {
// The right-hand-side of join and nest could not be correlated with the left side,
// therefore we propagate the original substitution environment.
newCorrelateClauses.add((AbstractBinaryCorrelateClause) correlateClause.accept(this, env).first);
// Join binding variables should be removed for further traversal.
currentEnv.removeSubstitution(correlateClause.getRightVariable());
if (correlateClause.hasPositionalVariable()) {
currentEnv.removeSubstitution(correlateClause.getPositionalVariable());
}
}
}
return new Pair<>(new FromTerm(newLeftExpr, newLeftVar, newLeftPosVar, newCorrelateClauses), currentEnv);
}
use of org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause in project asterixdb by apache.
the class FreeVariableVisitor method visit.
@Override
public Void visit(FromTerm fromTerm, Collection<VariableExpr> freeVars) throws CompilationException {
// The encountered binding variables so far in the fromterm.
Collection<VariableExpr> bindingVariables = new HashSet<>();
// Visit the left expression of a from term.
fromTerm.getLeftExpression().accept(this, freeVars);
// Adds binding variables.
bindingVariables.add(fromTerm.getLeftVariable());
if (fromTerm.hasPositionalVariable()) {
bindingVariables.add(fromTerm.getPositionalVariable());
}
// Visits join/unnest/nest clauses.
for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
Collection<VariableExpr> correlateFreeVars = new HashSet<>();
correlateClause.accept(this, correlateFreeVars);
if (correlateClause.getClauseType() != ClauseType.JOIN_CLAUSE) {
// Correlation is allowed if the clause is not a join clause,
// therefore we remove left-side binding variables for these cases.
correlateFreeVars.removeAll(bindingVariables);
// Adds binding variables.
bindingVariables.add(correlateClause.getRightVariable());
if (correlateClause.hasPositionalVariable()) {
bindingVariables.add(correlateClause.getPositionalVariable());
}
}
freeVars.addAll(correlateFreeVars);
}
return null;
}
use of org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause in project asterixdb by apache.
the class AbstractSqlppExpressionScopingVisitor method visit.
@Override
public Expression visit(FromTerm fromTerm, ILangExpression arg) throws CompilationException {
scopeChecker.createNewScope();
// Visit the left expression of a from term.
fromTerm.setLeftExpression(visit(fromTerm.getLeftExpression(), fromTerm));
// Registers the data item variable.
VariableExpr leftVar = fromTerm.getLeftVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), leftVar.getVar());
// Registers the positional variable
if (fromTerm.hasPositionalVariable()) {
VariableExpr posVar = fromTerm.getPositionalVariable();
addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar());
}
// Visits join/unnest/nest clauses.
for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
correlateClause.accept(this, fromTerm);
}
return null;
}
use of org.apache.asterix.lang.sqlpp.clause.AbstractBinaryCorrelateClause in project asterixdb by apache.
the class SqlppInlineUdfsVisitor method visit.
@Override
public Boolean visit(FromTerm fromTerm, List<FunctionDecl> func) throws CompilationException {
boolean changed = false;
Pair<Boolean, Expression> p = inlineUdfsInExpr(fromTerm.getLeftExpression(), func);
fromTerm.setLeftExpression(p.second);
changed |= p.first;
for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) {
changed |= correlateClause.accept(this, func);
}
return changed;
}
Aggregations