From 93b325a37ea075844dedc7efff31746a6cc2c719 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 18 May 2009 01:24:31 +0000 Subject: [PATCH] git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3291 ae02f08e-27ec-0310-ae8c-8ba02fe2eafd --- devel/log.config | 2 + .../xerial/relation/query/StreamAmoebaJoin.java | 124 ++++++++++----------- 2 files changed, 62 insertions(+), 64 deletions(-) create mode 100644 devel/log.config diff --git a/devel/log.config b/devel/log.config new file mode 100644 index 0000000..991db31 --- /dev/null +++ b/devel/log.config @@ -0,0 +1,2 @@ +org.xerial.relation.query.StreamAmoebaJoin-lattice=trace +org.xerial.relation.query.StreamAmoebaJoinTest=off \ No newline at end of file diff --git a/src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java b/src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java index c9101c4..ffc3436 100644 --- a/src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java +++ b/src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java @@ -70,6 +70,7 @@ public class StreamAmoebaJoin implements TreeVisitor public static final String ALTERNATIVE_ATTRIBUTE_SYMBOL = "-"; private static Logger _logger = Logger.getLogger(StreamAmoebaJoin.class); + private static Logger _logger2 = Logger.getLogger(StreamAmoebaJoin.class, "lattice"); final QuerySet query; final RelationEventHandler handler; @@ -127,19 +128,6 @@ public class StreamAmoebaJoin implements TreeVisitor handler.newRelationFragment(schema, knownNode, newNode); - // boolean isChanged = container.push(knownNode); - // if (isChanged) - // { - // Set stackListToExecutePop = popListOfNodeID.get(knownNode.nodeID); - // if (stackListToExecutePop == null) - // { - // stackListToExecutePop = new HashSet(); - // popListOfNodeID.put(knownNode.nodeID, stackListToExecutePop); - // } - // stackListToExecutePop.add(container); - // } - // - // container.push(newNode); } } @@ -245,80 +233,88 @@ public class StreamAmoebaJoin implements TreeVisitor void forward(Node node) { + List actionList = getActionList(node); + assert actionList != null; + + for (Operation each : actionList) + { + each.execute(); + } + } + + private List getActionList(Node nextNode) + { LatticeNode prevState = latticeCursor.getNode(); - LatticeNode nextState = latticeCursor.next(node.nodeName); + LatticeNode nextState = latticeCursor.next(nextNode.nodeName); stateStack.addLast(nextState); + Edge currentEdge = new Edge(prevState.getID(), nextState.getID()); + List actionList = operationSetOnForward.get(currentEdge); + if (actionList != null) + return actionList; + int prevNodeID = prevState.getID(); int nextNodeID = nextState.getID(); - Edge currentEdge = new Edge(prevNodeID, nextNodeID); - List actionList = operationSetOnForward.get(currentEdge); - if (actionList == null) - { - // lazily prepare the action list - actionList = new ArrayList(); - operationSetOnForward.put(currentEdge, actionList); - List backActionList = new ArrayList(); - operationSetOnBack.put(new Edge(nextNodeID, prevNodeID), backActionList); + // lazily prepare the action list + actionList = new ArrayList(); + operationSetOnForward.put(currentEdge, actionList); + List backActionList = new ArrayList(); + operationSetOnBack.put(new Edge(nextNodeID, prevNodeID), backActionList); + + // search for the corresponding relations to newly found two node pair + String newlyFoundTag = nextNode.nodeName; - // search for the corresponding relations to newly found two node pair - String newlyFoundTag = node.nodeName; + if (_logger2.isTraceEnabled()) + _logger2.trace("crate actions for " + newlyFoundTag); - if (prevState != nextState) + if (prevState != nextState) + { + // (core node, attribute node) + for (Schema r : query.getTargetQuerySet()) { - // (core node, attribute node) - for (Schema r : query.getTargetQuerySet()) + if (r.getNodeIndex(newlyFoundTag) == null) + continue; + + for (String previouslyFoundNode : nextState) { - if (r.getNodeIndex(newlyFoundTag) == null) + TupleIndex pi = r.getNodeIndex(previouslyFoundNode); + if (pi == null) continue; - for (String previouslyFoundNode : nextState) - { - TupleIndex pi = r.getNodeIndex(previouslyFoundNode); - if (pi == null) - continue; - - if (previouslyFoundNode.equals(newlyFoundTag)) - continue; - - if (_logger.isTraceEnabled()) - _logger.trace(String.format("new pair: %s(%s), %s (in %s)", previouslyFoundNode, pi, - newlyFoundTag, r)); - actionList.add(new PushRelation(r, previouslyFoundNode, newlyFoundTag)); - backActionList.add(new PopRelation(r, newlyFoundTag)); - break; - } + if (previouslyFoundNode.equals(newlyFoundTag)) + continue; + if (_logger2.isTraceEnabled()) + _logger2.trace(String.format("new pair: %s(%s), %s (in %s)", previouslyFoundNode, pi, + newlyFoundTag, r)); + actionList.add(new PushRelation(r, previouslyFoundNode, newlyFoundTag)); + backActionList.add(new PopRelation(r, newlyFoundTag)); + break; } + } - else + } + else + { + // loop back e.g. A -> A + for (Schema r : query.getTargetQuerySet()) { - // loop back e.g. A -> A - for (Schema r : query.getTargetQuerySet()) + String selfLoopNode = r.selfLoopNode(); + if (selfLoopNode == null) + continue; + else { - String selfLoopNode = r.selfLoopNode(); - if (selfLoopNode == null) - continue; - else - { - actionList.add(new PushLoopedRelation(r, selfLoopNode)); - break; - } + actionList.add(new PushLoopedRelation(r, selfLoopNode)); + break; } } - - // TODO handling cross edge (adding ClearRelation operation) - } - assert actionList != null; + // TODO handling cross edge (adding ClearRelation operation) - for (Operation each : actionList) - { - each.execute(); - } + return actionList; } -- 2.11.0