From 75c85d1d01ef95369a5ea4fdadb2b94fd18e6323 Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 19 May 2009 01:09:39 +0000 Subject: [PATCH] git-svn-id: http://www.xerial.org/svn/project/XerialJ/trunk/xerial-core@3297 ae02f08e-27ec-0310-ae8c-8ba02fe2eafd --- src/main/java/org/xerial/relation/LNode.java | 10 ++-- src/main/java/org/xerial/relation/Node.java | 9 ++- .../xerial/relation/query/AmoebaJoinHandler.java | 4 +- .../relation/query/AmoebaJoinHandlerBase.java | 54 +++++++++++++++++ .../xerial/relation/query/StreamAmoebaJoin.java | 69 ++++++++++------------ 5 files changed, 96 insertions(+), 50 deletions(-) create mode 100644 src/main/java/org/xerial/relation/query/AmoebaJoinHandlerBase.java diff --git a/src/main/java/org/xerial/relation/LNode.java b/src/main/java/org/xerial/relation/LNode.java index b5857c8..12b389e 100644 --- a/src/main/java/org/xerial/relation/LNode.java +++ b/src/main/java/org/xerial/relation/LNode.java @@ -32,13 +32,13 @@ package org.xerial.relation; */ public class LNode extends NodeBase { - private final static int INVALID_ID = -1; + private final static long INVALID_ID = -1; private final static String NULL_TEXT = null; - public final int nodeID; + public final long nodeID; public final String nodeValue; - public LNode(int nodeID, String nodeValue) + public LNode(long nodeID, String nodeValue) { this.nodeID = nodeID; this.nodeValue = nodeValue; @@ -52,7 +52,7 @@ public class LNode extends NodeBase */ public static class NodeBuilder { - private int nodeID = INVALID_ID; + private long nodeID = INVALID_ID; private String nodeValue = NULL_TEXT; public NodeBuilder() @@ -64,7 +64,7 @@ public class LNode extends NodeBase this.nodeValue = node.nodeValue; } - public NodeBuilder nodeID(int nodeID) + public NodeBuilder nodeID(long nodeID) { this.nodeID = nodeID; return this; diff --git a/src/main/java/org/xerial/relation/Node.java b/src/main/java/org/xerial/relation/Node.java index 7e2641f..9022d89 100644 --- a/src/main/java/org/xerial/relation/Node.java +++ b/src/main/java/org/xerial/relation/Node.java @@ -24,7 +24,6 @@ //-------------------------------------- package org.xerial.relation; - /** * Node is an element ({@link Cell}) of a relation. * @@ -36,11 +35,11 @@ public class Node extends NodeBase public static final int INVALID_ID = -1; public static final String NULL_TEXT = null; - public final int nodeID; + public final long nodeID; public final String nodeName; public final String nodeValue; - private Node(String nodeName, int nodeID, String nodeValue) + private Node(String nodeName, long nodeID, String nodeValue) { this.nodeID = nodeID; this.nodeName = nodeName; @@ -55,7 +54,7 @@ public class Node extends NodeBase */ public static class NodeBuilder { - private int nodeID = INVALID_ID; + private long nodeID = INVALID_ID; private String nodeValue = NULL_TEXT; private final String nodeName; @@ -71,7 +70,7 @@ public class Node extends NodeBase this.nodeValue = node.nodeValue; } - public NodeBuilder nodeID(int nodeID) + public NodeBuilder nodeID(long nodeID) { this.nodeID = nodeID; return this; diff --git a/src/main/java/org/xerial/relation/query/AmoebaJoinHandler.java b/src/main/java/org/xerial/relation/query/AmoebaJoinHandler.java index da12d26..6268f8d 100644 --- a/src/main/java/org/xerial/relation/query/AmoebaJoinHandler.java +++ b/src/main/java/org/xerial/relation/query/AmoebaJoinHandler.java @@ -29,9 +29,9 @@ import org.xerial.relation.schema.Schema; public interface AmoebaJoinHandler { - public void newAmoeba(Schema schema, Node n1, Node n2); + public void newAmoeba(Schema schema, Node coreNode, Node attributeNode); public void leaveNode(Schema schema, Node node); - public void text(Schema schema, Node contextNode, String nodeName, String text); + public void text(Schema schema, Node coreNode, String nodeName, String text); } diff --git a/src/main/java/org/xerial/relation/query/AmoebaJoinHandlerBase.java b/src/main/java/org/xerial/relation/query/AmoebaJoinHandlerBase.java new file mode 100644 index 0000000..7f1caea --- /dev/null +++ b/src/main/java/org/xerial/relation/query/AmoebaJoinHandlerBase.java @@ -0,0 +1,54 @@ +/*-------------------------------------------------------------------------- + * Copyright 2009 Taro L. Saito + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + *--------------------------------------------------------------------------*/ +//-------------------------------------- +// XerialJ +// +// AmoebaJoinHandlerBase.java +// Since: 2009/05/18 19:15:42 +// +// $URL$ +// $Author$ +//-------------------------------------- +package org.xerial.relation.query; + +import org.xerial.relation.Node; +import org.xerial.relation.schema.Schema; + +/** + * An empty implementation of {@link AmoebaJoinHandler} + * + * @author leo + * + */ +public class AmoebaJoinHandlerBase implements AmoebaJoinHandler +{ + + public void leaveNode(Schema schema, Node node) + { + + } + + public void newAmoeba(Schema schema, Node coreNode, Node attributeNode) + { + + } + + public void text(Schema schema, Node coreNode, String nodeName, String text) + { + + } + +} diff --git a/src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java b/src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java index d932cd5..6828ed1 100644 --- a/src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java +++ b/src/main/java/org/xerial/relation/query/StreamAmoebaJoin.java @@ -77,7 +77,7 @@ public class StreamAmoebaJoin implements TreeVisitor final AmoebaJoinHandler handler; // for running amoeba join - int nodeCount = 0; + long nodeCount = 0; Lattice nodeNameLattice = new Lattice(); LatticeCursor latticeCursor; @@ -106,33 +106,23 @@ public class StreamAmoebaJoin implements TreeVisitor class SimpleTextOperation implements TextOperation { final Schema schema; - final String contextNodeName; + final String coreNodeName; public SimpleTextOperation(Schema schema, String contextNodeName) { this.schema = schema; - this.contextNodeName = contextNodeName; + this.coreNodeName = contextNodeName; } public SimpleTextOperation(PushRelation pr) { this.schema = pr.schema; - if (isCoreNodeIndex(schema.getNodeIndex(pr.previouslyFoundTag))) - { - this.contextNodeName = pr.previouslyFoundTag; - } - else if (isCoreNodeIndex(schema.getNodeIndex(pr.newlyFoundTag))) - { - this.contextNodeName = pr.newlyFoundTag; - } - else - throw new XerialError(XerialErrorCode.INVALID_STATE, "no core node in action: " + pr); - + this.coreNodeName = pr.coreNodeName; } public void execute(String nodeName, String textData) { - Deque nodeStack = getNodeStack(contextNodeName); + Deque nodeStack = getNodeStack(coreNodeName); Node contextNode = nodeStack.getLast(); handler.text(schema, contextNode, nodeName, textData); } @@ -158,6 +148,7 @@ public class StreamAmoebaJoin implements TreeVisitor if (coreNode_action.containsKey(contextNode)) { coreNode_action.get(contextNode).execute(nodeName, textData); + return; } } } @@ -178,32 +169,44 @@ public class StreamAmoebaJoin implements TreeVisitor class PushRelation implements Operation { final Schema schema; - final String previouslyFoundTag; - final String newlyFoundTag; + final String coreNodeName; + final String attributeNodeName; + final String newlyFoundNodeName; public PushRelation(Schema schema, String previouslyFoundTag, String newlyFoundTag) { this.schema = schema; - this.previouslyFoundTag = previouslyFoundTag; - this.newlyFoundTag = newlyFoundTag; + this.newlyFoundNodeName = newlyFoundTag; + + if (isCoreNodeIndex(schema.getNodeIndex(previouslyFoundTag))) + { + this.coreNodeName = previouslyFoundTag; + this.attributeNodeName = newlyFoundTag; + } + else if (isCoreNodeIndex(schema.getNodeIndex(newlyFoundTag))) + { + this.coreNodeName = newlyFoundTag; + this.attributeNodeName = previouslyFoundTag; + } + else + throw new XerialError(XerialErrorCode.INVALID_STATE, "no core node in " + schema); } public void execute() { - Node knownNode = getNodeStack(previouslyFoundTag).getLast(); - Node newNode = getNodeStack(newlyFoundTag).getLast(); + Node coreNode = getNodeStack(coreNodeName).getLast(); + Node attributeNode = getNodeStack(attributeNodeName).getLast(); if (_logger.isTraceEnabled()) - _logger.trace(String.format("push:(%s, %s)", knownNode, newNode)); - - handler.newAmoeba(schema, knownNode, newNode); + _logger.trace(String.format("push:(%s, %s)", coreNode, attributeNode)); + handler.newAmoeba(schema, coreNode, attributeNode); } @Override public String toString() { - return String.format("push: %s for (%s, %s)", schema, previouslyFoundTag, newlyFoundTag); + return String.format("push: %s for (%s, %s)", schema, coreNodeName, attributeNodeName); } } @@ -216,17 +219,7 @@ public class StreamAmoebaJoin implements TreeVisitor for (PushRelation each : candidates) { Schema s = each.schema; - - if (isCoreNodeIndex(s.getNodeIndex(each.previouslyFoundTag))) - { - coreNode_action.put(each.previouslyFoundTag, each); - } - else if (isCoreNodeIndex(s.getNodeIndex(each.newlyFoundTag))) - { - coreNode_action.put(each.newlyFoundTag, each); - } - else - throw new XerialError(XerialErrorCode.INVALID_STATE, "no core node is found"); + coreNode_action.put(each.coreNodeName, each); } } @@ -258,7 +251,7 @@ public class StreamAmoebaJoin implements TreeVisitor { Schema s = each.schema; - coreNode_action.put(each.previouslyFoundTag, new PopRelation(s, each.newlyFoundTag)); + coreNode_action.put(each.coreNodeName, new PopRelation(s, each.newlyFoundNodeName)); } } @@ -502,7 +495,7 @@ public class StreamAmoebaJoin implements TreeVisitor for (PushRelation each : foundAction) { actionList.add(each); - backActionList.add(new PopRelation(each.schema, each.newlyFoundTag)); + backActionList.add(new PopRelation(each.schema, each.newlyFoundNodeName)); } } -- 2.11.0