public ElementSubGraph getMatched() { return match.getMatchedGraph(); }
@Override public String toString() { final StringBuilder sb = new StringBuilder( "Match{" ); // sb.append( "matcherGraph=" ).append( matcherGraph ); // sb.append( ", mapping=" ).append( mapping ); sb.append( getMatchedGraph() ); sb.append( '}' ); return sb.toString(); } }
public EnumMultiMap<FlowElement> getCaptureMap() { if( captureMap != null ) return captureMap; captureMap = new EnumMultiMap<>(); Map<FlowElement, ElementExpression> reversed = new LinkedHashMap<>(); if( Util.reverseMap( vertexMapping, reversed ) ) throw new IllegalStateException( "duplicates found in mapping" ); // returns a Set ordered topologically by the matched graph. retains this first, this second ordering for simple cases Iterator<FlowElement> iterator = ElementGraphs.getTopologicalIterator( getMatchedGraph() ); while( iterator.hasNext() ) { FlowElement next = iterator.next(); ElementExpression elementExpression = reversed.get( next ); // matchedGraph may be a super-set of what's in the mapping, so elementExpression may be null if( elementExpression == null ) continue; captureMap.addAll( elementExpression.getCapture(), next ); } return captureMap; }
@Override public ElementGraph next() { try { if( !hasNext() ) throw new NoSuchElementException(); ElementGraph contractedMatchedGraph = match.getMatchedGraph(); Set<FlowElement> excludes = getContractedGraph().vertexSetCopy(); excludes.removeAll( contractedMatchedGraph.vertexSet() ); return asSubGraph( elementGraph, contractedMatchedGraph, excludes ); } finally { match = null; } }
@Override public void writeDOTs( String path ) { int count = 0; beginGraph.writeDOT( new File( path, makeFileName( count++, "element-graph" ) ).toString() ); if( graphPartitioner instanceof ExpressionGraphPartitioner ) { ExpressionGraphPartitioner expressionGraphPartitioner = (ExpressionGraphPartitioner) graphPartitioner; ExpressionGraph contractionGraph = expressionGraphPartitioner.getContractionGraph(); if( contractionGraph != null ) contractionGraph.writeDOT( new File( path, makeFileName( count++, "contraction-graph", contractionGraph ) ).toString() ); ExpressionGraph expressionGraph = expressionGraphPartitioner.getExpressionGraph(); if( expressionGraph != null ) expressionGraph.writeDOT( new File( path, makeFileName( count++, "expression-graph", expressionGraph ) ).toString() ); } if( contractedGraph != null ) contractedGraph.writeDOT( new File( path, makeFileName( count++, "contracted-graph" ) ).toString() ); List<ElementGraph> subGraphs = getSubGraphs(); for( int i = 0; i < subGraphs.size(); i++ ) { ElementGraph subGraph = subGraphs.get( i ); // want to write annotations with elements new ElementMultiGraph( subGraph, annotatedSubGraphs.get( subGraph ) ).writeDOT( new File( path, makeFileName( count, i, "partition-result-sub-graph" ) ).toString() ); if( i < contractedMatches.size() ) contractedMatches.get( i ).getMatchedGraph().writeDOT( new File( path, makeFileName( count, i, "partition-contracted-graph" ) ).toString() ); } }
public Transformed<ElementSubGraph> transform( PlannerContext plannerContext, ElementGraph rootGraph ) { Transformed<ElementSubGraph> transformed = new Transformed<>( plannerContext, this, subGraphMatcher, rootGraph ); try { Transformed contractedTransformed = graphTransformer.transform( plannerContext, rootGraph ); // contracted graph transform transformed.addChildTransform( contractedTransformed ); // apply contracted sub-graph matcher to get the bounded sub-graph of the original graph ElementGraph contractedGraph = contractedTransformed.getEndGraph(); Match match = findAllPrimaries ? subGraphFinder.findAllMatches( plannerContext, contractedGraph ) : subGraphFinder.findFirstMatch( plannerContext, contractedGraph ); if( !match.foundMatch() ) return transformed; ElementGraph contractedSubGraph = match.getMatchedGraph(); ElementSubGraph resultSubGraph = asSubGraphOf( rootGraph, contractedSubGraph ); // the bounded sub-graph of the rootGraph transformed.setEndGraph( resultSubGraph ); return transformed; } catch( Throwable throwable ) { throw new TransformException( throwable, transformed ); } }
@Test public void testFind2() { ElementGraph graph = new HashJoinSameSourceGraph(); graph = new ContractedTransformer( new SyncPipeExpressionGraph() ).transform( graph ).getEndGraph(); FlowElementExpression sharedTap = new FlowElementExpression( Tap.class, TypeExpression.Topo.SplitOnly ); FlowElementExpression sharedHashJoin = new FlowElementExpression( HashJoin.class ); ExpressionGraph expressionGraph = new ExpressionGraph() .arc( sharedTap, ScopeExpression.ALL, sharedHashJoin ); GraphFinder graphFinder = new GraphFinder( expressionGraph ); Match match = graphFinder.findFirstMatch( graph ); match.getMatchedGraph().writeDOT( getPlanPath() + "/match.dot" ); }
@Test public void testFind() { ElementGraph graph = new HashJoinSameSourceGraph(); graph = new ContractedTransformer( new SyncPipeExpressionGraph() ).transform( graph ).getEndGraph(); FlowElementExpression SHARED_TAP = new FlowElementExpression( Tap.class, TypeExpression.Topo.SplitOnly ); FlowElementExpression SHARED_HASHJOIN = new FlowElementExpression( HashJoin.class ); ExpressionGraph expressionGraph = new ExpressionGraph() .arcs( SHARED_TAP, SHARED_HASHJOIN ) .arcs( SHARED_TAP, SHARED_HASHJOIN ); GraphFinder graphFinder = new GraphFinder( expressionGraph ); Match match = graphFinder.findFirstMatch( graph ); match.getMatchedGraph().writeDOT( getPlanPath() + "/match.dot" ); }
@Test public void testFindAllMatched() { // ElementGraph graph = new HashJoinSameSourceGraph(); ElementGraph graph = new JoinAroundJoinRightMostGraph(); graph.writeDOT( getPlanPath() + "/full.dot" ); // graph = new ContractedTransform( new SyncPipeExpressionGraph() ).transform( graph ).getEndGraph(); graph = new ContractedTransformer( new NoGroupTapExpressionGraph() ).transform( graph ).getEndGraph(); graph.writeDOT( getPlanPath() + "/contracted.dot" ); ExpressionGraph expressionGraph = new ExpressionGraph( new FlowElementExpression( ElementCapture.Primary, Tap.class ) ); GraphFinder graphFinder = new GraphFinder( expressionGraph ); Match match = graphFinder.findAllMatches( graph ); match.getMatchedGraph().writeDOT( getPlanPath() + "/match.dot" ); } }
@Test public void testFindAllOnPrimary() { // ElementGraph graph = new HashJoinSameSourceGraph(); ElementGraph graph = new JoinAroundJoinRightMostGraph(); graph.writeDOT( getPlanPath() + "/full.dot" ); // graph = new ContractedTransform( new SyncPipeExpressionGraph() ).transform( graph ).getEndGraph(); graph = new ContractedTransformer( new NoGroupTapExpressionGraph() ).transform( graph ).getEndGraph(); graph.writeDOT( getPlanPath() + "/contracted.dot" ); ExpressionGraph expressionGraph = new ExpressionGraph() .arc( new FlowElementExpression( Tap.class ), ScopeExpression.ALL, new FlowElementExpression( ElementCapture.Primary, HashJoin.class ) ); GraphFinder graphFinder = new GraphFinder( expressionGraph ); Match match = graphFinder.findAllMatchesOnPrimary( graph ); match.getMatchedGraph().writeDOT( getPlanPath() + "/match.dot" ); }