public RuleResult exec( PlannerContext plannerContext, FlowElementGraph flowElementGraph ) { RuleResult ruleResult = new RuleResult( registry, flowElementGraph ); ProcessLogger logger = plannerContext.getLogger(); int size = flowElementGraph.vertexSet().size(); boolean logAsInfo = size >= ELEMENT_THRESHOLD; if( logAsInfo ) logger.logInfo( "elements in graph: {}, info logging threshold: {}, logging planner execution status", size, ELEMENT_THRESHOLD ); long beginExec = System.currentTimeMillis(); try { planPhases( plannerContext, logAsInfo, ruleResult ); } catch( Exception exception ) { ruleResult.setPlannerException( exception ); } finally { long endExec = System.currentTimeMillis(); ruleResult.setDuration( beginExec, endExec ); RuleResult.ResultStatus status = ruleResult.getResultStatus(); String duration = formatDurationFromMillis( endExec - beginExec ); logPhase( logger, logAsInfo, "rule registry completed: {}, with status: {}, and duration: {}", registry.getName(), status, duration ); } return ruleResult; }
@Test public void testRuleEngine() { RuleRegistry ruleRegistry = new RuleRegistry(); ruleRegistry.addElementFactory( NonTapFactory.TEMP_TAP, new NonTapFactory() ); PlannerContext plannerContext = new PlannerContext( ruleRegistry, null, null, null, true ); ruleRegistry.addRule( new RuleAssert( PlanPhase.PreResolveAssembly, new LoneGroupExpression(), "lone group assertion" ) ); ruleRegistry.addRule( new RuleInsertionTransformer( PlanPhase.PreResolveAssembly, new TestGroupGroupExpression(), IntermediateTapElementFactory.TEMP_TAP ) ); try { new RuleExec( new TraceWriter(), ruleRegistry ).executeRulePhase( PlanPhase.PreResolveAssembly, plannerContext, new RuleResult( new LoneGroupAssertionGraph() ) ); fail(); } catch( PlannerException exception ) { // do nothing } new RuleExec( new TraceWriter(), ruleRegistry ).executeRulePhase( PlanPhase.PreResolveAssembly, plannerContext, new RuleResult( new HashJoinSameSourceGraph() ) ); }
@Test public void testSubGraphIterator() { RuleRegistry ruleRegistry = new RuleRegistry(); ruleRegistry.addElementFactory( NonTapFactory.TEMP_TAP, new NonTapFactory() ); PlannerContext plannerContext = new PlannerContext( ruleRegistry, null, null, null, true ); ruleRegistry.addRule( new RuleInsertionTransformer( PlanPhase.PreResolveAssembly, new TestCheckpointExpression(), IntermediateTapElementFactory.TEMP_TAP ) ); // ruleRegistry.addRule( new RuleContractedTransform( PlanPhase.PreResolve, new NoOpPipeExpression() ) ); RuleResult ruleResult = new RuleExec( new TraceWriter(), ruleRegistry ).executeRulePhase( PlanPhase.PreResolveAssembly, plannerContext, new RuleResult( new StandardElementGraph() ) ); FlowElementGraph flowElementGraph = ruleResult.getAssemblyGraph(); SubGraphIterator iterator = new ExpressionSubGraphIterator( new PlannerContext(), new NoGroupTapExpressionGraph(), new TapGroupTapExpressionGraph(), flowElementGraph ); while( iterator.hasNext() ) assertNotNull( iterator.next() ); }
private void runSubGraphIteratorRotate( FlowElementGraph elementGraph, int numSubGraphs ) { RuleRegistry ruleRegistry = new RuleRegistry(); PlannerContext plannerContext = new PlannerContext( ruleRegistry ); ruleRegistry.addRule( new RemoveNoOpPipeTransformer() ); RuleResult ruleResult = new RuleExec( new TraceWriter(), ruleRegistry ).executeRulePhase( PlanPhase.PreResolveAssembly, plannerContext, new RuleResult( elementGraph ) ); FlowElementGraph flowElementGraph = ruleResult.getAssemblyGraph(); flowElementGraph.writeDOT( getPlanPath() + "/node.dot" ); ExpressionSubGraphIterator iterator = new ExpressionSubGraphIterator( new PlannerContext(), new TestNoGroupTapExpressionGraph(), new TestConsecutiveTapsExpressionGraph(), false, flowElementGraph ); iterator.getContractedGraph().writeDOT( getPlanPath() + "/node-contracted.dot" ); int count = 0; while( iterator.hasNext() && count < 10 ) { ElementGraph next = iterator.next(); assertNotNull( next ); next.writeDOT( getPlanPath() + "/pipeline/" + count + "-graph.dot" ); count++; } assertEquals( "wrong number of sub-graphs", numSubGraphs, count ); }
RuleResult ruleResult = new RuleExec( new TraceWriter(), ruleRegistry ).executeRulePhase( PlanPhase.PreResolveAssembly, plannerContext, new RuleResult( elementGraph ) ); FlowElementGraph flowElementGraph = ruleResult.getAssemblyGraph();