List of usage examples for org.apache.commons.lang3.mutable Mutable getValue
T getValue();
From source file:edu.uci.ics.asterix.optimizer.rules.InlineUnnestFunctionRule.java
private ILogicalExpression findUsedVarOrigin(LogicalVariable usedVar, AbstractLogicalOperator parentOp, AbstractLogicalOperator currentOp) throws AlgebricksException { ILogicalExpression ret = null;/*from ww w .j a v a 2 s. com*/ if (currentOp.getOperatorTag() == LogicalOperatorTag.ASSIGN) { List<LogicalVariable> producedVars = new ArrayList<LogicalVariable>(); VariableUtilities.getProducedVariables(currentOp, producedVars); if (producedVars.contains(usedVar)) { AssignOperator assignOp = (AssignOperator) currentOp; int index = assignOp.getVariables().indexOf(usedVar); ILogicalExpression returnedExpr = assignOp.getExpressions().get(index).getValue(); if (returnedExpr.getExpressionTag() == LogicalExpressionTag.FUNCTION_CALL) { AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) returnedExpr; if (AsterixBuiltinFunctions.isBuiltinUnnestingFunction(funcExpr.getFunctionIdentifier())) { // we only inline for unnest functions removeUnecessaryAssign(parentOp, currentOp, assignOp, index); ret = returnedExpr; } } else if (returnedExpr.getExpressionTag() == LogicalExpressionTag.VARIABLE) { //recusively inline VariableReferenceExpression varExpr = (VariableReferenceExpression) returnedExpr; LogicalVariable var = varExpr.getVariableReference(); ILogicalExpression finalExpr = findUsedVarOrigin(var, currentOp, (AbstractLogicalOperator) currentOp.getInputs().get(0).getValue()); if (finalExpr != null) { removeUnecessaryAssign(parentOp, currentOp, assignOp, index); ret = finalExpr; } } } } else { for (Mutable<ILogicalOperator> child : currentOp.getInputs()) { ILogicalExpression expr = findUsedVarOrigin(usedVar, currentOp, (AbstractLogicalOperator) child.getValue()); if (expr != null) { ret = expr; } } } return ret; }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.RemoveUnusedAssignAndAggregateRule.java
private void collectUnusedAssignedVars(AbstractLogicalOperator op, Set<LogicalVariable> toRemove, boolean first, IOptimizationContext context) throws AlgebricksException { if (!first) { context.addToDontApplySet(this, op); }//from w w w. j a va2 s . c o m for (Mutable<ILogicalOperator> c : op.getInputs()) { collectUnusedAssignedVars((AbstractLogicalOperator) c.getValue(), toRemove, false, context); } if (op.hasNestedPlans()) { AbstractOperatorWithNestedPlans opWithNested = (AbstractOperatorWithNestedPlans) op; for (ILogicalPlan plan : opWithNested.getNestedPlans()) { for (Mutable<ILogicalOperator> r : plan.getRoots()) { collectUnusedAssignedVars((AbstractLogicalOperator) r.getValue(), toRemove, false, context); } } } boolean removeUsedVars = true; switch (op.getOperatorTag()) { case ASSIGN: { AssignOperator assign = (AssignOperator) op; toRemove.addAll(assign.getVariables()); break; } case AGGREGATE: { AggregateOperator agg = (AggregateOperator) op; toRemove.addAll(agg.getVariables()); break; } case UNNEST: { UnnestOperator uOp = (UnnestOperator) op; LogicalVariable pVar = uOp.getPositionalVariable(); if (pVar != null) { toRemove.add(pVar); } break; } case UNIONALL: { UnionAllOperator unionOp = (UnionAllOperator) op; for (Triple<LogicalVariable, LogicalVariable, LogicalVariable> varMapping : unionOp .getVariableMappings()) { toRemove.add(varMapping.third); } removeUsedVars = false; break; } } if (removeUsedVars) { List<LogicalVariable> used = new LinkedList<LogicalVariable>(); VariableUtilities.getUsedVariables(op, used); toRemove.removeAll(used); } }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.RemoveUnusedAssignAndAggregateRule.java
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { if (context.checkIfInDontApplySet(this, opRef.getValue())) { return false; }//from w ww. j a v a 2 s. c o m Set<LogicalVariable> toRemove = new HashSet<LogicalVariable>(); collectUnusedAssignedVars((AbstractLogicalOperator) opRef.getValue(), toRemove, true, context); boolean smthToRemove = !toRemove.isEmpty(); if (smthToRemove) { removeUnusedAssigns(opRef, toRemove, context); } return !toRemove.isEmpty(); }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushProjectDownRule.java
@Override public boolean rewritePre(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.PROJECT) { return false; }/*from w w w .ja v a 2s. co m*/ ProjectOperator pi = (ProjectOperator) op; Mutable<ILogicalOperator> opRef2 = pi.getInputs().get(0); HashSet<LogicalVariable> toPush = new HashSet<LogicalVariable>(); toPush.addAll(pi.getVariables()); Pair<Boolean, Boolean> p = pushThroughOp(toPush, opRef2, op, context); boolean smthWasPushed = p.first; if (p.second) { // the original projection is redundant opRef.setValue(op.getInputs().get(0).getValue()); smthWasPushed = true; } return smthWasPushed; }
From source file:edu.uci.ics.asterix.optimizer.rules.PushAggFuncIntoStandaloneAggregateRule.java
/** * Does the actual push of aggregates for qualified joins. * /*from ww w. java2s . c o m*/ * @param join * @param assignOp * that contains aggregate function calls. * @param context * @throws AlgebricksException */ private void pushAggregateFunctionThroughJoin(AbstractBinaryJoinOperator join, AssignOperator assignOp, IOptimizationContext context) throws AlgebricksException { for (Mutable<ILogicalOperator> branchRef : join.getInputs()) { AbstractLogicalOperator branch = (AbstractLogicalOperator) branchRef.getValue(); if (branch.getOperatorTag() == LogicalOperatorTag.AGGREGATE) { AggregateOperator aggOp = (AggregateOperator) branch; pushAggregateFunction(aggOp, assignOp, context); } else if (branch.getOperatorTag() == LogicalOperatorTag.INNERJOIN || branch.getOperatorTag() == LogicalOperatorTag.LEFTOUTERJOIN) { AbstractBinaryJoinOperator childJoin = (AbstractBinaryJoinOperator) branch; pushAggregateFunctionThroughJoin(childJoin, assignOp, context); } } }
From source file:com.norconex.collector.http.crawler.BasicFeaturesTest.java
@Test public void testKeepDownload() throws IOException { HttpCollector collector = newHttpCollector1Crawler("/test/a$dir/blah?case=keepDownloads"); HttpCrawler crawler = (HttpCrawler) collector.getCrawlers()[0]; crawler.getCrawlerConfig().setMaxDepth(0); crawler.getCrawlerConfig().setKeepDownloads(true); // String url = crawler.getCrawlerConfig().getStartURLs()[0]; collector.start(false);//from w w w. j av a 2 s . c o m File downloadDir = new File(crawler.getCrawlerConfig().getWorkDir(), "downloads"); final Mutable<File> downloadedFile = new MutableObject<>(); FileUtil.visitAllFiles(downloadDir, new IFileVisitor() { @Override public void visit(File file) { if (downloadedFile.getValue() != null) { return; } if (file.toString().contains("downloads")) { downloadedFile.setValue(file); } } }); String content = FileUtils.readFileToString(downloadedFile.getValue()); Assert.assertTrue("Invalid or missing download file.", content .contains("<b>This</b> file <i>must</i> be saved as is, " + "with this <span>formatting</span>")); }
From source file:edu.uci.ics.asterix.optimizer.rules.ConstantFoldingRule.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { ILogicalOperator op = opRef.getValue(); if (context.checkIfInDontApplySet(this, op)) { return false; }//from ww w. ja v a 2 s.c om return op.acceptExpressionTransform(cfv); }
From source file:edu.uci.ics.hyracks.algebricks.rewriter.rules.PushFunctionsBelowJoin.java
@Override public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context) throws AlgebricksException { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.ASSIGN) { return false; }/*ww w . j av a2s. c o m*/ AssignOperator assignOp = (AssignOperator) op; // Find a join operator below this assign. Mutable<ILogicalOperator> joinOpRef = findJoinOp(assignOp.getInputs().get(0)); if (joinOpRef == null) { return false; } AbstractBinaryJoinOperator joinOp = (AbstractBinaryJoinOperator) joinOpRef.getValue(); // Check if the assign uses a function that we wish to push below the join if possible. funcExprs.clear(); gatherFunctionCalls(assignOp, funcExprs); if (funcExprs.isEmpty()) { return false; } // Try to push the functions down the input branches of the join. boolean modified = false; if (pushDownFunctions(joinOp, 0, funcExprs, context)) { modified = true; } if (pushDownFunctions(joinOp, 1, funcExprs, context)) { modified = true; } if (modified) { context.computeAndSetTypeEnvironmentForOperator(joinOp); } return modified; }
From source file:edu.uci.ics.asterix.optimizer.rules.RemoveUnusedOneToOneEquiJoinRule.java
private void gatherProducingDataScans(Mutable<ILogicalOperator> opRef, List<LogicalVariable> joinUsedVars, List<DataSourceScanOperator> dataScans) { AbstractLogicalOperator op = (AbstractLogicalOperator) opRef.getValue(); if (op.getOperatorTag() != LogicalOperatorTag.DATASOURCESCAN) { for (Mutable<ILogicalOperator> inputOp : op.getInputs()) { gatherProducingDataScans(inputOp, joinUsedVars, dataScans); }// w ww.ja va 2s .c om return; } DataSourceScanOperator dataScan = (DataSourceScanOperator) op; fillPKVars(dataScan, pkVars); // Check if join uses all PK vars. if (joinUsedVars.containsAll(pkVars)) { dataScans.add(dataScan); } }
From source file:edu.uci.ics.hyracks.algebricks.core.algebra.expressions.AbstractFunctionCallExpression.java
@Override public void getUsedVariables(Collection<LogicalVariable> vars) { for (Mutable<ILogicalExpression> arg : arguments) { arg.getValue().getUsedVariables(vars); }//from w w w . j a v a 2s . c om }