public static List<VariableExpr> getBindingVariables(FromTerm fromTerm) { List<VariableExpr> bindingVars = new ArrayList<>(); if (fromTerm == null) { return bindingVars; } bindingVars.add(fromTerm.getLeftVariable()); if (fromTerm.hasPositionalVariable()) { bindingVars.add(fromTerm.getPositionalVariable()); } for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) { bindingVars.add(correlateClause.getRightVariable()); if (correlateClause.hasPositionalVariable()) { bindingVars.add(correlateClause.getPositionalVariable()); } } return bindingVars; }
@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; }
@Override public Void visit(FromTerm fromTerm, Integer step) throws CompilationException { fromTerm.getLeftExpression().accept(this, step + 2); out.print(" as "); fromTerm.getLeftVariable().accept(this, step + 2); if (fromTerm.hasPositionalVariable()) { out.print(" at "); fromTerm.getPositionalVariable().accept(this, step + 2); } if (fromTerm.hasCorrelateClauses()) { for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) { correlateClause.accept(this, step); } } return null; }
private void getFromBindings(FromClause fromClause, List<FieldBinding> outFieldBindings, Set<String> outFieldNames) throws CompilationException { for (FromTerm fromTerm : fromClause.getFromTerms()) { outFieldBindings.add(getFieldBinding(fromTerm.getLeftVariable(), outFieldNames)); if (fromTerm.hasPositionalVariable()) { outFieldBindings.add(getFieldBinding(fromTerm.getPositionalVariable(), outFieldNames)); } if (!fromTerm.hasCorrelateClauses()) { continue; } for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) { outFieldBindings.add(getFieldBinding(correlateClause.getRightVariable(), outFieldNames)); if (correlateClause.hasPositionalVariable()) { outFieldBindings.add(getFieldBinding(correlateClause.getPositionalVariable(), outFieldNames)); } } } }
@Override public Void visit(FromTerm fromTerm, Integer step) throws CompilationException { fromTerm.getLeftExpression().accept(this, step); out.print(skip(step) + "AS "); fromTerm.getLeftVariable().accept(this, 0); if (fromTerm.hasPositionalVariable()) { out.println(" AT "); fromTerm.getPositionalVariable().accept(this, 0); } if (fromTerm.hasCorrelateClauses()) { for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) { correlateClause.accept(this, step); } } return null; }
@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)); } FromTerm copy = new FromTerm(fromExpr, fromVar, positionVar, correlateClauses); copy.setSourceLocation(fromTerm.getSourceLocation()); return copy; }
@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()
@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(), leftVar.getSourceLocation()); // Registers the positional variable if (fromTerm.hasPositionalVariable()) { VariableExpr posVar = fromTerm.getPositionalVariable(); addNewVarSymbolToScope(scopeChecker.getCurrentScope(), posVar.getVar(), posVar.getSourceLocation()); } // Visits join/unnest/nest clauses. for (AbstractBinaryCorrelateClause correlateClause : fromTerm.getCorrelateClauses()) { correlateClause.accept(this, fromTerm); } return null; }
throws CompilationException { SourceLocation sourceLoc = fromTerm.getSourceLocation(); LogicalVariable fromVar = context.newVarFromExpression(fromTerm.getLeftVariable()); Expression fromExpr = fromTerm.getLeftExpression(); Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(fromExpr, tupSource);