You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2011/12/03 16:06:23 UTC
svn commit: r1209929 [1/2] - in
/incubator/lcf/branches/CONNECTORS-286/warthog/src:
main/java/org/apache/warthog/interfaces/
main/java/org/apache/warthog/tablestore/ test/java/org/apache/warthog/tests/
Author: kwright
Date: Sat Dec 3 15:06:22 2011
New Revision: 1209929
URL: http://svn.apache.org/viewvc?rev=1209929&view=rev
Log:
Revamp the way aggregates are done
Added:
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/AggregateRelationship.java (with props)
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipAccessor.java (with props)
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipRelationship.java (with props)
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableValue.java (with props)
Removed:
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/QueryDescription.java
Modified:
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterAccessor.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterRelationship.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/IndexRelationship.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/JoinRelationship.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/SubqueryFilter.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessor.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessorBuilder.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHFilter.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHRelationship.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTable.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeColumnKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeEqualsKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeGreaterKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeLesserKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeParentKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexValue.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableColumnKey.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableStore.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/MultiThreadTest.java
incubator/lcf/branches/CONNECTORS-286/warthog/src/test/java/org/apache/warthog/tests/SanityTest.java
Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/AggregateRelationship.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/AggregateRelationship.java?rev=1209929&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/AggregateRelationship.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/AggregateRelationship.java Sat Dec 3 15:06:22 2011
@@ -0,0 +1,61 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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.
+*/
+
+package org.apache.warthog.interfaces;
+
+/** This relationship type applies column aggregation and row aggregation
+* capabilities.
+*/
+public class AggregateRelationship implements WHRelationship
+{
+ protected WHRelationship relationshipToAggregate;
+ protected WHColumnDescription[] returnColumns;
+ protected String[] groupByColumns;
+
+ /** Constructor */
+ public AggregateRelationship(WHRelationship relationshipToAggregate,
+ WHColumnDescription[] returnColumns,
+ String[] groupByColumns)
+ {
+ this.relationshipToAggregate = relationshipToAggregate;
+ this.returnColumns = returnColumns;
+ this.groupByColumns = groupByColumns;
+ }
+
+ /** Get the column names represented by the relationship. */
+ public String[] getColumnNames()
+ throws WHException
+ {
+ // MHL
+ return null;
+ }
+
+ /** Get the row accessor. This determines
+ * both the initial set of rows and the ordering. The results can be later filtered to
+ * yield the final output data.
+ */
+ public WHAccessor buildAccessor()
+ throws WHException
+ {
+ // MHL
+ return null;
+ //return new FilterAccessor(relationshipToFilter.buildAccessor(),this,filterer);
+ }
+
+}
Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/AggregateRelationship.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/AggregateRelationship.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterAccessor.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterAccessor.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterAccessor.java Sat Dec 3 15:06:22 2011
@@ -23,56 +23,59 @@ package org.apache.warthog.interfaces;
*/
public class FilterAccessor implements WHAccessor
{
- protected WHRelationship relationshipToFilter;
protected WHFilter filter;
protected WHAccessor baseAccessor;
- protected WHRowID nextRow = null;
+ protected WHRowID currentRowID;
- public FilterAccessor(WHAccessor baseAccessor, WHRelationship relationshipToFilter, WHFilter filter)
+ public FilterAccessor(WHAccessor baseAccessor, WHFilter filter)
throws WHException
{
this.baseAccessor = baseAccessor;
- this.relationshipToFilter = relationshipToFilter;
this.filter = filter;
+ goToNextLegalRow();
}
-
- /** Are there any more rows?
+
+ protected void goToNextLegalRow()
+ throws WHException
+ {
+ while (true)
+ {
+ currentRowID = baseAccessor.getCurrentRowID();
+ if (currentRowID == null)
+ break;
+ if (filter == null || filter.include(baseAccessor))
+ break;
+ baseAccessor.advance();
+ }
+ }
+
+ /** Advance to the next row.
*/
- public boolean hasNext()
+ public void advance()
throws WHException
{
- if (nextRow == null)
+ if (currentRowID != null)
{
- // Locate the next row, or bump into the end.
- nextRow = findNextRow();
- if (nextRow == null)
- return false;
+ baseAccessor.advance();
+ goToNextLegalRow();
}
- return true;
}
-
- /** Read the next matching relationship row ID,
+
+ /** Read the current relationship row ID, Null will be returned if we are
+ * at the end of the sequence.
*/
- public WHRowID getNext()
+ public WHRowID getCurrentRowID()
throws WHException
{
- if (nextRow == null)
- nextRow = findNextRow();
- WHRowID rval = nextRow;
- nextRow = null;
- return rval;
+ return currentRowID;
}
-
- /** Find the next (filtered) row */
- protected WHRowID findNextRow()
+
+ /** Get the data for the current row and specified column.
+ */
+ public WHValue getValue(String columnName)
throws WHException
{
- while (baseAccessor.hasNext())
- {
- WHRowID theRow = baseAccessor.getNext();
- if (filter == null || filter.include(relationshipToFilter,theRow))
- return theRow;
- }
- return null;
+ return baseAccessor.getValue(columnName);
}
+
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterRelationship.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterRelationship.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterRelationship.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/FilterRelationship.java Sat Dec 3 15:06:22 2011
@@ -39,13 +39,6 @@ public class FilterRelationship implemen
{
return relationshipToFilter.getColumnNames();
}
-
- /** Get the data for a given row and column. */
- public WHValue getValue(WHRowID rowID, String columnName)
- throws WHException
- {
- return relationshipToFilter.getValue(rowID,columnName);
- }
/** Get the row accessor. This determines
* both the initial set of rows and the ordering. The results can be later filtered to
@@ -54,7 +47,7 @@ public class FilterRelationship implemen
public WHAccessor buildAccessor()
throws WHException
{
- return new FilterAccessor(relationshipToFilter.buildAccessor(),this,filterer);
+ return new FilterAccessor(relationshipToFilter.buildAccessor(),filterer);
}
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/IndexRelationship.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/IndexRelationship.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/IndexRelationship.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/IndexRelationship.java Sat Dec 3 15:06:22 2011
@@ -20,32 +20,27 @@
package org.apache.warthog.interfaces;
/** The index relationship basically views another relationship (a table) through
-* an index with criteria.
+* an index with criteria and ordering.
*/
public class IndexRelationship implements WHRelationship
{
protected WHIndex index;
protected IndexCriteria[] criteria;
+ protected boolean[] orderReversed;
/** Constructor */
- public IndexRelationship(WHIndex index, IndexCriteria[] criteria)
+ public IndexRelationship(WHIndex index, IndexCriteria[] criteria, boolean[] orderReversed)
{
this.index = index;
this.criteria = criteria;
+ this.orderReversed = orderReversed;
}
/** Get the column names represented by the relationship. */
public String[] getColumnNames()
throws WHException
{
- return index.getRelationship().getColumnNames();
- }
-
- /** Get the data for a given row and column. */
- public WHValue getValue(WHRowID rowID, String columnName)
- throws WHException
- {
- return index.getRelationship().getValue(rowID,columnName);
+ return index.getColumnNames();
}
/** Get the row accessor. This determines
@@ -55,7 +50,7 @@ public class IndexRelationship implement
public WHAccessor buildAccessor()
throws WHException
{
- return index.buildAccessor(criteria);
+ return index.buildAccessor(criteria,orderReversed);
}
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/JoinRelationship.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/JoinRelationship.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/JoinRelationship.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/JoinRelationship.java Sat Dec 3 15:06:22 2011
@@ -35,14 +35,6 @@ public class JoinRelationship implements
return null;
}
- /** Get the data for a given row and column. */
- public WHValue getValue(WHRowID rowID, String columnName)
- throws WHException
- {
- // MHL
- return null;
- }
-
/** Get the row accessor. This determines
* both the initial set of rows and the ordering. The results can be later filtered to
* yield the final output data.
Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipAccessor.java?rev=1209929&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipAccessor.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipAccessor.java Sat Dec 3 15:06:22 2011
@@ -0,0 +1,96 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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.
+*/
+
+package org.apache.warthog.interfaces;
+
+/** Accessor class that returns only rows from a parent between a specific numeric range.
+*/
+public class RowSkipAccessor implements WHAccessor
+{
+ protected WHAccessor baseAccessor;
+ protected Long startRow;
+ protected Long endRow;
+ protected WHRowID currentRowID;
+ long rowNumber = 0L;
+
+ public RowSkipAccessor(WHAccessor baseAccessor, Long startRow, Long rowCount)
+ throws WHException
+ {
+ this.baseAccessor = baseAccessor;
+ this.startRow = startRow;
+ if (rowCount != null)
+ endRow = new Long(((startRow==null)?0L:startRow.longValue())+rowCount.longValue());
+ else
+ endRow = null;
+ goToNextLegalRow();
+ }
+
+ protected void goToNextLegalRow()
+ throws WHException
+ {
+ while (true)
+ {
+ currentRowID = baseAccessor.getCurrentRowID();
+ if (currentRowID == null)
+ return;
+ if (startRow != null && rowNumber < startRow.longValue())
+ {
+ rowNumber++;
+ baseAccessor.advance();
+ continue;
+ }
+ if (endRow != null && rowNumber >= endRow.longValue())
+ {
+ currentRowID = null;
+ return;
+ }
+ break;
+ }
+ }
+
+ /** Advance to the next row.
+ */
+ public void advance()
+ throws WHException
+ {
+ if (currentRowID != null)
+ {
+ baseAccessor.advance();
+ goToNextLegalRow();
+ }
+ }
+
+ /** Read the current relationship row ID, Null will be returned if we are
+ * at the end of the sequence.
+ */
+ public WHRowID getCurrentRowID()
+ throws WHException
+ {
+ return currentRowID;
+ }
+
+ /** Get the data for the current row and specified column.
+ */
+ public WHValue getValue(String columnName)
+ throws WHException
+ {
+ return baseAccessor.getValue(columnName);
+ }
+
+}
Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipAccessor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipAccessor.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipRelationship.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipRelationship.java?rev=1209929&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipRelationship.java (added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipRelationship.java Sat Dec 3 15:06:22 2011
@@ -0,0 +1,55 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You 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.
+*/
+
+package org.apache.warthog.interfaces;
+
+/** This relationship type applies row filtering on top of another relationship.
+*/
+public class RowSkipRelationship implements WHRelationship
+{
+ protected WHRelationship relationshipToFilter;
+ Long startRow;
+ Long rowCount;
+
+ /** Constructor */
+ public RowSkipRelationship(WHRelationship relationshipToFilter, Long startRow, Long rowCount)
+ {
+ this.relationshipToFilter = relationshipToFilter;
+ this.startRow = startRow;
+ this.rowCount = rowCount;
+ }
+
+ /** Get the column names represented by the relationship. */
+ public String[] getColumnNames()
+ throws WHException
+ {
+ return relationshipToFilter.getColumnNames();
+ }
+
+ /** Get the row accessor. This determines
+ * both the initial set of rows and the ordering. The results can be later filtered to
+ * yield the final output data.
+ */
+ public WHAccessor buildAccessor()
+ throws WHException
+ {
+ return new RowSkipAccessor(relationshipToFilter.buildAccessor(),startRow,rowCount);
+ }
+
+}
Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipRelationship.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/RowSkipRelationship.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/SubqueryFilter.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/SubqueryFilter.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/SubqueryFilter.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/SubqueryFilter.java Sat Dec 3 15:06:22 2011
@@ -42,11 +42,11 @@ public class SubqueryFilter implements W
/** Check if a row should be filtered or not.
*/
- public boolean include(WHRelationship relationship, WHRowID rowID)
+ public boolean include(WHAccessor accessor)
throws WHException
{
- WHAccessor accessor = builder.createAccessor(relationship,rowID);
- return accessor.hasNext() == isExists;
+ WHAccessor checker = builder.createAccessor(accessor);
+ return isExists ^ (checker.getCurrentRowID() == null);
}
}
\ No newline at end of file
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessor.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessor.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessor.java Sat Dec 3 15:06:22 2011
@@ -24,13 +24,21 @@ package org.apache.warthog.interfaces;
*/
public interface WHAccessor
{
- /** Are there any more rows?
+ /** Advance to the next row.
*/
- public boolean hasNext()
+ public void advance()
throws WHException;
- /** Read the next matching relationship row ID,
+ /** Read the current relationship row ID, Null will be returned if we are
+ * at the end of the sequence.
*/
- public WHRowID getNext()
+ public WHRowID getCurrentRowID()
throws WHException;
+
+ /** Get the data for the current row and specified column.
+ */
+ public WHValue getValue(String columnName)
+ throws WHException;
+
+
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessorBuilder.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessorBuilder.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessorBuilder.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHAccessorBuilder.java Sat Dec 3 15:06:22 2011
@@ -27,8 +27,7 @@ public interface WHAccessorBuilder
/** Construct an accessor based on the specified row of the specified
* relationship.
*/
- public WHAccessor createAccessor(WHRelationship relationship,
- WHRowID rowID)
+ public WHAccessor createAccessor(WHAccessor accessor)
throws WHException;
}
\ No newline at end of file
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHFilter.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHFilter.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHFilter.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHFilter.java Sat Dec 3 15:06:22 2011
@@ -25,7 +25,7 @@ public interface WHFilter
{
/** Check if a row should be filtered or not.
*/
- public boolean include(WHRelationship relationship, WHRowID rowID)
+ public boolean include(WHAccessor accessor)
throws WHException;
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHIndex.java Sat Dec 3 15:06:22 2011
@@ -24,16 +24,11 @@ package org.apache.warthog.interfaces;
*/
public interface WHIndex extends WHRelationship
{
- /** Get the relationship the index applies to.
+ /** Get the underlying relationship the index applies to.
*/
public WHRelationship getRelationship()
throws WHException;
- /** Get the columns that are indexed
- */
- public String[] getIndexColumns()
- throws WHException;
-
// Additional accessor support method.
//
// Index access supports any kind of matches which allow pruning of whole subtrees
@@ -43,9 +38,12 @@ public interface WHIndex extends WHRelat
/** Create an accessor based on this index which uses the provided criteria. The
* criteria must align with the index's columns. Null values are permitted where
- * no criteria are present.
+ * no criteria are present.
+ *@param criteria are the criteria that apply to each individual index column; null for no criteria at all.
+ *@param orderReversed is a boolean for each individual index column; true if the comparator order of that column
+ * should be reversed for the accessor. Null indicates no reversal for any column.
*/
- public WHAccessor buildAccessor(IndexCriteria[] criteria)
+ public WHAccessor buildAccessor(IndexCriteria[] criteria, boolean[] orderReversed)
throws WHException;
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHRelationship.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHRelationship.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHRelationship.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHRelationship.java Sat Dec 3 15:06:22 2011
@@ -29,10 +29,6 @@ public interface WHRelationship
public String[] getColumnNames()
throws WHException;
- /** Get the data for a given row and column. */
- public WHValue getValue(WHRowID rowID, String columnName)
- throws WHException;
-
/** Get the row accessor. This determines
* both the initial set of rows and the ordering. The results can be later filtered to
* yield the final output data.
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTable.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTable.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTable.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTable.java Sat Dec 3 15:06:22 2011
@@ -31,11 +31,11 @@ public interface WHTable extends WHRelat
/** Update row(s) */
public void updateRows(String[] columns, WHValue[] values,
- WHAccessor accessor, WHFilter filter)
+ WHAccessor accessor)
throws WHException;
/** Delete row(s) */
- public void deleteRows(WHAccessor accessor, WHFilter filter)
+ public void deleteRows(WHAccessor accessor)
throws WHException;
}
\ No newline at end of file
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/interfaces/WHTableStore.java Sat Dec 3 15:06:22 2011
@@ -62,8 +62,4 @@ public interface WHTableStore
public void dropIndex(String name)
throws WHException;
- /** Perform a query */
- public WHRelationship performQuery(QueryDescription specification)
- throws WHException;
-
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Index.java Sat Dec 3 15:06:22 2011
@@ -58,21 +58,21 @@ public class Index implements WHIndex
protected Table table;
protected LongValue indexID;
protected long indexIDValue;
- protected String[] columnNames;
+ protected long[] columnIDs;
protected WHComparator[] comparators;
protected boolean unique;
/** Constructor */
- public Index(TableStore ts, LongValue indexID, Table table, String[] columnNames, String[] comparatorClasses, boolean unique)
+ public Index(TableStore ts, LongValue indexID, Table table, long[] columnIDs, String[] comparatorClasses, boolean unique)
throws WHException
{
- if (columnNames.length != comparatorClasses.length)
+ if (columnIDs.length != comparatorClasses.length)
throw new WHException("Number of index column names must match number of comparator classes");
this.ts = ts;
this.table = table;
this.indexID = indexID;
this.indexIDValue = indexID.getValue();
- this.columnNames = columnNames;
+ this.columnIDs = columnIDs;
this.unique = unique;
this.comparators = new WHComparator[comparatorClasses.length];
try
@@ -104,44 +104,42 @@ public class Index implements WHIndex
return table.getColumnNames();
}
- /** Get the data for a given row and column. */
- public WHValue getValue(WHRowID rowID, String columnName)
- throws WHException
- {
- return table.getValue(rowID,columnName);
- }
-
- /** Get a default accessor with ordering but no filtering.
+ /** Get a default accessor with default ordering and no filtering.
*/
public WHAccessor buildAccessor()
throws WHException
{
// Use null criteria
- return buildAccessor(new IndexCriteria[columnNames.length]);
+ return buildAccessor(null,null);
}
- /** Get the columns that are indexed
- */
- public String[] getIndexColumns()
- throws WHException
- {
- return columnNames;
- }
/** Create an accessor based on this index which uses the provided criteria. The
* criteria must align with the index's columns. Null values are permitted where
- * no criteria are present.
+ * no criteria are present.
+ *@param criteria are the criteria that apply to each individual index column; null for no criteria at all.
+ *@param orderReversed is a boolean for each individual index column; true if the comparator order of that column
+ * should be reversed for the accessor. Null indicates no reversal for any column.
*/
- public WHAccessor buildAccessor(IndexCriteria[] criteria)
+ public WHAccessor buildAccessor(IndexCriteria[] criteria, boolean[] orderReversed)
throws WHException
{
- if (criteria.length != columnNames.length)
+ if (criteria != null && criteria.length != columnIDs.length)
throw new WHException("Criteria count must match index column count");
- return new IndexAccessor(this,criteria);
+ if (orderReversed != null && orderReversed.length != columnIDs.length)
+ throw new WHException("Order reversal count must match index column count");
+ return new IndexAccessor(this,criteria,orderReversed);
}
// Below this line are methods that are not meant to be used for general purposes,
+ /** Get the columns that are indexed
+ */
+ protected long[] getIndexColumnIDs()
+ {
+ return columnIDs;
+ }
+
/** Get the index id */
protected LongValue getID()
{
@@ -182,7 +180,7 @@ public class Index implements WHIndex
protected void addNodeInto(LongValue rowID, WHKey parentKey)
throws WHException
{
- for (int columnIndex = 0 ; columnIndex < columnNames.length ; columnIndex++ )
+ for (int columnIndex = 0 ; columnIndex < columnIDs.length ; columnIndex++ )
{
// Place a node into a specific tree as indicated by the column number.
// This will either wind up in an equals chain (in which case, a link to the column child will already exist),
@@ -198,10 +196,10 @@ public class Index implements WHIndex
throws WHException
{
// Get the current column
- String columnName = columnNames[columnIndex];
+ long columnID = columnIDs[columnIndex];
WHComparator comparator = comparators[columnIndex];
// Read the value we're going to be inserting
- WHValue insertValue = table.getValue(rowID,columnName);
+ WHValue insertValue = table.getTableColumnValue(rowID,columnID);
// Keep going until we've found the insertion point (or until it looks like we're looping,
// which means we've hit a concurrency problem)
//Set<LongValue> hitSoFar = new HashSet<LongValue>();
@@ -212,8 +210,8 @@ public class Index implements WHIndex
if (currentRowID == null)
{
// Set the node in place
- setIndexParentChild(parentKey,columnName,rowID);
- return new IndexNodeColumnKey(indexIDValue,rowID.getValue(),columnName);
+ setIndexParentChild(parentKey,columnID,rowID);
+ return new IndexNodeColumnKey(indexIDValue,rowID.getValue(),columnID);
}
//if (hitSoFar.contains(currentRowID))
@@ -221,7 +219,7 @@ public class Index implements WHIndex
//hitSoFar.add(currentRowID);
// Read the value at this node
- WHValue currentValue = table.getValue(currentRowID,columnName);
+ WHValue currentValue = table.getTableColumnValue(currentRowID,columnID);
// Perform the comparison
int comparatorResult = comparator.compare(currentValue,insertValue);
@@ -231,11 +229,11 @@ public class Index implements WHIndex
{
case WHComparator.RESULT_LESS:
// Descend the lesser tree for this column.
- parentKey = new IndexNodeLesserKey(indexIDValue,currentRowID.getValue(),columnName);
+ parentKey = new IndexNodeLesserKey(indexIDValue,currentRowID.getValue(),columnID);
continue;
case WHComparator.RESULT_GREATER:
// Descend the greater tree for this column.
- parentKey = new IndexNodeGreaterKey(indexIDValue,currentRowID.getValue(),columnName);
+ parentKey = new IndexNodeGreaterKey(indexIDValue,currentRowID.getValue(),columnID);
continue;
case WHComparator.RESULT_EQUALS:
// Insert here! into the chain if need be...
@@ -244,7 +242,7 @@ public class Index implements WHIndex
throw new WHException("Comparator returned illegal result");
}
- if (unique && columnIndex +1 == columnNames.length)
+ if (unique && columnIndex +1 == columnIDs.length)
{
// Unique constraint violation
throw new WHUniqueConstraintViolationException("Row "+new Long(rowID.getValue()).toString()+" violates uniqueness constraint on index "+new Long(indexIDValue).toString());
@@ -254,21 +252,21 @@ public class Index implements WHIndex
// We insert the new node at the beginning of the chain so we don't have to scan it, obviously...
// First, get the old ref, if there is one.
- LongValue currentEqualsRowID = readIndexNodeEqualsNode(currentRowID,columnName);
+ LongValue currentEqualsRowID = readIndexNodeEqualsNode(currentRowID,columnID);
// Move the old pointer to the new position
if (currentEqualsRowID != null)
{
// Delete the old one
- deleteIndexNodeEqualsNode(currentRowID,columnName);
+ deleteIndexNodeEqualsNode(currentRowID,columnID);
// Move the pointer to the child of the node we just created
- setIndexNodeEqualsNode(rowID,columnName,currentEqualsRowID);
+ setIndexNodeEqualsNode(rowID,columnID,currentEqualsRowID);
}
// Now, set the new ref.
- setIndexNodeEqualsNode(currentRowID,columnName,rowID);
+ setIndexNodeEqualsNode(currentRowID,columnID,rowID);
- return new IndexNodeColumnKey(indexIDValue,currentRowID.getValue(),columnName);
+ return new IndexNodeColumnKey(indexIDValue,currentRowID.getValue(),columnID);
}
}
@@ -288,7 +286,7 @@ public class Index implements WHIndex
// As part of promoting the lesser or greater child, the other child (if it exists) will be inserted
// into the btree and will be carried to the bottom and linked in.
- for (int i = columnNames.length ; i > 0 ; i--)
+ for (int i = columnIDs.length ; i > 0 ; i--)
{
removeFromBtree(rowID,i-1);
}
@@ -299,32 +297,32 @@ public class Index implements WHIndex
protected void removeFromBtree(LongValue rowID, int columnIndex)
throws WHException
{
- String columnName = columnNames[columnIndex];
+ long columnID = columnIDs[columnIndex];
// Build the index node's parent key
- WHKey parentKey = readIndexNodeParentKey(rowID,columnName);
+ WHKey parentKey = readIndexNodeParentKey(rowID,columnID);
// Look for an 'equals' child
- LongValue equalsChild = readIndexNodeEqualsNode(rowID,columnName);
+ LongValue equalsChild = readIndexNodeEqualsNode(rowID,columnID);
if (equalsChild != null)
{
// Case (1) (as described above). Promote the child. We know the child has
// no greater/lesser children.
- deleteIndexNodeEqualsNode(rowID,columnName);
- deleteIndexParentChild(parentKey,columnName);
- setIndexParentChild(parentKey,columnName,equalsChild);
+ deleteIndexNodeEqualsNode(rowID,columnID);
+ deleteIndexParentChild(parentKey,columnID);
+ setIndexParentChild(parentKey,columnID,equalsChild);
// Now, transfer the delete node's lesser/greater children to the equalsChild.
- LongValue lesserChild = readIndexNodeLesserNode(rowID,columnName);
+ LongValue lesserChild = readIndexNodeLesserNode(rowID,columnID);
if (lesserChild != null)
{
- deleteIndexNodeLesserNode(rowID,columnName);
- setIndexNodeLesserNode(equalsChild,columnName,lesserChild);
+ deleteIndexNodeLesserNode(rowID,columnID);
+ setIndexNodeLesserNode(equalsChild,columnID,lesserChild);
}
- LongValue greaterChild = readIndexNodeGreaterNode(rowID,columnName);
+ LongValue greaterChild = readIndexNodeGreaterNode(rowID,columnID);
if (greaterChild != null)
{
- deleteIndexNodeGreaterNode(rowID,columnName);
- setIndexNodeGreaterNode(equalsChild,columnName,greaterChild);
+ deleteIndexNodeGreaterNode(rowID,columnID);
+ setIndexNodeGreaterNode(equalsChild,columnID,greaterChild);
}
return;
}
@@ -335,43 +333,43 @@ public class Index implements WHIndex
// arbitrary. Someday we'll choose to promote the deeper side perhaps...
// First, unhook the whole tree from the parent.
- deleteIndexParentChild(parentKey,columnName);
+ deleteIndexParentChild(parentKey,columnID);
// Now look for a promotion candidate to hook in in its place.
LongValue promotionCandidate = null;
if (promotionCandidate == null)
{
- promotionCandidate = readIndexNodeLesserNode(rowID,columnName);
+ promotionCandidate = readIndexNodeLesserNode(rowID,columnID);
if (promotionCandidate != null)
// We found our promotion candidate!
- deleteIndexNodeLesserNode(rowID,columnName);
+ deleteIndexNodeLesserNode(rowID,columnID);
}
if (promotionCandidate == null)
{
- promotionCandidate = readIndexNodeGreaterNode(rowID,columnName);
+ promotionCandidate = readIndexNodeGreaterNode(rowID,columnID);
if (promotionCandidate != null)
// Candidate found
- deleteIndexNodeGreaterNode(rowID,columnName);
+ deleteIndexNodeGreaterNode(rowID,columnID);
}
if (promotionCandidate != null)
{
// Hook in the promotion candidate as child of the parent.
- setIndexParentChild(parentKey,columnName,promotionCandidate);
+ setIndexParentChild(parentKey,columnID,promotionCandidate);
// Transfer the remaining lesser/greater children into the promotionCandidate node
- LongValue lesserChild = readIndexNodeLesserNode(rowID,columnName);
+ LongValue lesserChild = readIndexNodeLesserNode(rowID,columnID);
if (lesserChild != null)
{
// Peel it away from the deleteNodeID
- deleteIndexNodeLesserNode(rowID,columnName);
+ deleteIndexNodeLesserNode(rowID,columnID);
// Now insert this node into promotionCandidate via parentKey
placeIntoBtree(lesserChild,parentKey,columnIndex);
}
- LongValue greaterChild = readIndexNodeGreaterNode(rowID,columnName);
+ LongValue greaterChild = readIndexNodeGreaterNode(rowID,columnID);
if (greaterChild != null)
{
// Delete the reference from the deletion node
- deleteIndexNodeGreaterNode(rowID,columnName);
+ deleteIndexNodeGreaterNode(rowID,columnID);
// Now insert this node into promotionCandidate via parentKey
placeIntoBtree(greaterChild,parentKey,columnIndex);
}
@@ -387,11 +385,14 @@ public class Index implements WHIndex
{
// Create an accessor for the table
WHAccessor tableAccessor = table.buildAccessor();
- while (tableAccessor.hasNext())
+ while (true)
{
- LongValue rowID = (LongValue)tableAccessor.getNext();
+ LongValue rowID = (LongValue)tableAccessor.getCurrentRowID();
+ if (rowID == null)
+ break;
// Add this row to the index.
addNewRow(rowID);
+ tableAccessor.advance();
}
}
@@ -410,7 +411,7 @@ public class Index implements WHIndex
protected void deleteBtree(WHKey key, int indexColumn)
throws WHException
{
- if (indexColumn == columnNames.length)
+ if (indexColumn == columnIDs.length)
return;
// For this btree, start with the root
@@ -420,15 +421,15 @@ public class Index implements WHIndex
return;
// Delete the child.
- String columnName = columnNames[indexColumn];
+ long columnID = columnIDs[indexColumn];
// First, unlink from the parent.
- deleteIndexParentChild(key,columnName);
+ deleteIndexParentChild(key,columnID);
// Recursively clean up all child links.
- deleteBtree(new IndexNodeEqualsKey(indexIDValue,child.getValue(),columnName),indexColumn);
- deleteBtree(new IndexNodeLesserKey(indexIDValue,child.getValue(),columnName),indexColumn);
- deleteBtree(new IndexNodeGreaterKey(indexIDValue,child.getValue(),columnName),indexColumn);
+ deleteBtree(new IndexNodeEqualsKey(indexIDValue,child.getValue(),columnID),indexColumn);
+ deleteBtree(new IndexNodeLesserKey(indexIDValue,child.getValue(),columnID),indexColumn);
+ deleteBtree(new IndexNodeGreaterKey(indexIDValue,child.getValue(),columnID),indexColumn);
// Move on to next column
- deleteBtree(new IndexNodeColumnKey(indexIDValue,child.getValue(),columnName),indexColumn+1);
+ deleteBtree(new IndexNodeColumnKey(indexIDValue,child.getValue(),columnID),indexColumn+1);
}
// Protected methods
@@ -436,142 +437,142 @@ public class Index implements WHIndex
/** Get next column's root node for an index node.
* This link is necessary in order to allow each tree to rebalance independently.
*/
- protected LongValue readIndexNodeColumnNode(LongValue rowID, String columnName)
+ protected LongValue readIndexNodeColumnNode(LongValue rowID, long columnID)
throws WHException
{
- return (LongValue)ts.get(new IndexNodeColumnKey(indexIDValue,rowID.getValue(),columnName));
+ return (LongValue)ts.get(new IndexNodeColumnKey(indexIDValue,rowID.getValue(),columnID));
}
/** Set next column's root node for an index node.
*/
- protected void setIndexNodeColumnNode(LongValue rowID, String columnName, LongValue refRowID)
+ protected void setIndexNodeColumnNode(LongValue rowID, long columnID, LongValue refRowID)
throws WHException
{
- IndexNodeColumnKey key = new IndexNodeColumnKey(indexIDValue,rowID.getValue(),columnName);
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,refRowID.getValue(),columnName);
+ IndexNodeColumnKey key = new IndexNodeColumnKey(indexIDValue,rowID.getValue(),columnID);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,refRowID.getValue(),columnID);
ts.put(key,refRowID);
ts.put(parentKey,key);
}
/** Delete the column root-node child reference for an index node. Presumes that the reference exists.
*/
- protected void deleteIndexNodeColumnNode(LongValue rowID, String columnName)
+ protected void deleteIndexNodeColumnNode(LongValue rowID, long columnID)
throws WHException
{
- IndexNodeColumnKey key = new IndexNodeColumnKey(indexIDValue,rowID.getValue(),columnName);
+ IndexNodeColumnKey key = new IndexNodeColumnKey(indexIDValue,rowID.getValue(),columnID);
LongValue childReference = (LongValue)ts.get(key);
if (childReference == null)
throw new WHConcurrencyException();
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnName);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnID);
ts.put(key,null);
ts.put(parentKey,null);
}
/** Get the lesser child reference for an index node.
*/
- protected LongValue readIndexNodeLesserNode(LongValue rowID, String columnName)
+ protected LongValue readIndexNodeLesserNode(LongValue rowID, long columnID)
throws WHException
{
- return (LongValue)ts.get(new IndexNodeLesserKey(indexIDValue,rowID.getValue(),columnName));
+ return (LongValue)ts.get(new IndexNodeLesserKey(indexIDValue,rowID.getValue(),columnID));
}
/** Set the lesser child reference for an index node. Presumes that no such reference already exists.
*/
- protected void setIndexNodeLesserNode(LongValue rowID, String columnName, LongValue refRowID)
+ protected void setIndexNodeLesserNode(LongValue rowID, long columnID, LongValue refRowID)
throws WHException
{
- IndexNodeLesserKey key = new IndexNodeLesserKey(indexIDValue,rowID.getValue(),columnName);
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,refRowID.getValue(),columnName);
+ IndexNodeLesserKey key = new IndexNodeLesserKey(indexIDValue,rowID.getValue(),columnID);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,refRowID.getValue(),columnID);
ts.put(key,refRowID);
ts.put(parentKey,key);
}
/** Delete the lesser child reference for an index node. Presumes that the reference exists.
*/
- protected void deleteIndexNodeLesserNode(LongValue rowID, String columnName)
+ protected void deleteIndexNodeLesserNode(LongValue rowID, long columnID)
throws WHException
{
- IndexNodeLesserKey key = new IndexNodeLesserKey(indexIDValue,rowID.getValue(),columnName);
+ IndexNodeLesserKey key = new IndexNodeLesserKey(indexIDValue,rowID.getValue(),columnID);
LongValue childReference = (LongValue)ts.get(key);
if (childReference == null)
throw new WHConcurrencyException();
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnName);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnID);
ts.put(key,null);
ts.put(parentKey,null);
}
/** Get the greater child reference for an index node.
*/
- protected LongValue readIndexNodeGreaterNode(LongValue rowID, String columnName)
+ protected LongValue readIndexNodeGreaterNode(LongValue rowID, long columnID)
throws WHException
{
- return (LongValue)ts.get(new IndexNodeGreaterKey(indexIDValue,rowID.getValue(),columnName));
+ return (LongValue)ts.get(new IndexNodeGreaterKey(indexIDValue,rowID.getValue(),columnID));
}
/** Set the greater child reference for an index node. Presumes that the reference is currently empty.
*/
- protected void setIndexNodeGreaterNode(LongValue rowID, String columnName, LongValue refRowID)
+ protected void setIndexNodeGreaterNode(LongValue rowID, long columnID, LongValue refRowID)
throws WHException
{
- IndexNodeGreaterKey key = new IndexNodeGreaterKey(indexIDValue,rowID.getValue(),columnName);
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,refRowID.getValue(),columnName);
+ IndexNodeGreaterKey key = new IndexNodeGreaterKey(indexIDValue,rowID.getValue(),columnID);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,refRowID.getValue(),columnID);
ts.put(key,refRowID);
ts.put(parentKey,key);
}
/** Delete the greater child reference for an index node. Presumes that the reference exists.
*/
- protected void deleteIndexNodeGreaterNode(LongValue rowID, String columnName)
+ protected void deleteIndexNodeGreaterNode(LongValue rowID, long columnID)
throws WHException
{
- IndexNodeGreaterKey key = new IndexNodeGreaterKey(indexIDValue,rowID.getValue(),columnName);
+ IndexNodeGreaterKey key = new IndexNodeGreaterKey(indexIDValue,rowID.getValue(),columnID);
LongValue childReference = (LongValue)ts.get(key);
if (childReference == null)
throw new WHConcurrencyException();
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnName);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnID);
ts.put(key,null);
ts.put(parentKey,null);
}
/** Get the equals child reference for an index node.
*/
- protected LongValue readIndexNodeEqualsNode(LongValue rowID, String columnName)
+ protected LongValue readIndexNodeEqualsNode(LongValue rowID, long columnID)
throws WHException
{
- return (LongValue)ts.get(new IndexNodeEqualsKey(indexIDValue,rowID.getValue(),columnName));
+ return (LongValue)ts.get(new IndexNodeEqualsKey(indexIDValue,rowID.getValue(),columnID));
}
/** Set the equals child reference for an index node. Presumes that a reference doesn't yet exist.
*/
- protected void setIndexNodeEqualsNode(LongValue rowID, String columnName, LongValue refRowID)
+ protected void setIndexNodeEqualsNode(LongValue rowID, long columnID, LongValue refRowID)
throws WHException
{
- IndexNodeEqualsKey key = new IndexNodeEqualsKey(indexIDValue,rowID.getValue(),columnName);
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,refRowID.getValue(),columnName);
+ IndexNodeEqualsKey key = new IndexNodeEqualsKey(indexIDValue,rowID.getValue(),columnID);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,refRowID.getValue(),columnID);
ts.put(key,refRowID);
ts.put(parentKey,key);
}
/** Delete the equals child reference for an index node. Presumes that the reference exists.
*/
- protected void deleteIndexNodeEqualsNode(LongValue rowID, String columnName)
+ protected void deleteIndexNodeEqualsNode(LongValue rowID, long columnID)
throws WHException
{
- IndexNodeEqualsKey key = new IndexNodeEqualsKey(indexIDValue,rowID.getValue(),columnName);
+ IndexNodeEqualsKey key = new IndexNodeEqualsKey(indexIDValue,rowID.getValue(),columnID);
LongValue childReference = (LongValue)ts.get(key);
if (childReference == null)
throw new WHConcurrencyException();
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnName);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnID);
ts.put(key,null);
ts.put(parentKey,null);
}
/** Get the parent reference for an index node.
*/
- protected WHKey readIndexNodeParentKey(LongValue rowID, String columnName)
+ protected WHKey readIndexNodeParentKey(LongValue rowID, long columnID)
throws WHException
{
- WHKey rval = (WHKey)ts.get(new IndexNodeParentKey(indexIDValue,rowID.getValue(),columnName));
+ WHKey rval = (WHKey)ts.get(new IndexNodeParentKey(indexIDValue,rowID.getValue(),columnID));
if (rval == null)
throw new WHConcurrencyException();
return rval;
@@ -587,16 +588,16 @@ public class Index implements WHIndex
/** Set an index parent's child node. Presumes this child is not set yet.
*/
- protected void setIndexParentChild(WHKey parentKey, String columnName, LongValue rowID)
+ protected void setIndexParentChild(WHKey parentKey, long columnID, LongValue rowID)
throws WHException
{
ts.put(parentKey,rowID);
- ts.put(new IndexNodeParentKey(indexIDValue,rowID.getValue(),columnName),parentKey);
+ ts.put(new IndexNodeParentKey(indexIDValue,rowID.getValue(),columnID),parentKey);
}
/** Remove an index parent's child node reference. Presumes that this child exists.
*/
- protected void deleteIndexParentChild(WHKey parentKey, String columnName)
+ protected void deleteIndexParentChild(WHKey parentKey, long columnID)
throws WHException
{
// Get the existing child
@@ -604,7 +605,7 @@ public class Index implements WHIndex
if (childNodeRef == null)
throw new WHConcurrencyException();
ts.put(parentKey,null);
- ts.put(new IndexNodeParentKey(indexIDValue,childNodeRef.getValue(),columnName),null);
+ ts.put(new IndexNodeParentKey(indexIDValue,childNodeRef.getValue(),columnID),null);
}
/** Get the root pointer for an index.
@@ -617,25 +618,25 @@ public class Index implements WHIndex
/** Set the root pointer for an index. Presumes the root pointer does not currently exist.
*/
- protected void setIndexRootNode(LongValue rootRowID, String columnName)
+ protected void setIndexRootNode(LongValue rootRowID, long columnID)
throws WHException
{
IndexRootKey key = new IndexRootKey(indexIDValue);
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,rootRowID.getValue(),columnName);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,rootRowID.getValue(),columnID);
ts.put(key,rootRowID);
ts.put(parentKey,key);
}
/** Delete the root node reference for an index. Presumes that the reference exists.
*/
- protected void deleteIndexRootNode(String columnName)
+ protected void deleteIndexRootNode(long columnID)
throws WHException
{
IndexRootKey key = new IndexRootKey(indexIDValue);
LongValue childReference = (LongValue)ts.get(key);
if (childReference == null)
throw new WHConcurrencyException();
- IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnName);
+ IndexNodeParentKey parentKey = new IndexNodeParentKey(indexIDValue,childReference.getValue(),columnID);
ts.put(key,null);
ts.put(parentKey,null);
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexAccessor.java Sat Dec 3 15:06:22 2011
@@ -39,65 +39,81 @@ import java.util.*;
public class IndexAccessor implements WHAccessor
{
protected Index index;
- protected String[] indexColumns;
+ protected Table table;
+ protected long[] indexColumnIDs;
protected WHComparator[] comparators;
protected IndexCriteria[] indexCriteria;
+ protected boolean[] orderReversed;
/** This is the current node queue. Nodes on the queue are unevaluated!! */
protected NodeQueue queue = new NodeQueue();
/** The current (matching) rowID, to be returned */
- protected WHRowID nextRowID = null;
+ protected LongValue currentRowID;
/** Constructor */
- public IndexAccessor(Index index, IndexCriteria[] indexCriteria)
+ public IndexAccessor(Index index, IndexCriteria[] indexCriteria, boolean[] orderReversed)
throws WHException
{
this.index = index;
- this.indexColumns = index.getIndexColumns();
+ this.table = index.getTable();
+ this.indexColumnIDs = index.getIndexColumnIDs();
this.comparators = index.getComparators();
this.indexCriteria = indexCriteria;
+ this.orderReversed = orderReversed;
LongValue rootRowID = index.readIndexRootNode();
if (rootRowID != null)
queue.pushNeedsAnalysis(rootRowID,0);
+ goToNextLegalRow();
}
-
- /** Are there any more rows?
+
+ /** Advance to the next row.
*/
- public boolean hasNext()
+ public void advance()
throws WHException
{
- return getNextRowID() != null;
+ if (currentRowID != null)
+ {
+ goToNextLegalRow();
+ }
}
-
- /** Read the next matching relationship row ID,
+
+ /** Read the current relationship row ID, Null will be returned if we are
+ * at the end of the sequence.
*/
- public WHRowID getNext()
+ public WHRowID getCurrentRowID()
throws WHException
{
- WHRowID rowID = getNextRowID();
- nextRowID = null;
- return rowID;
+ return currentRowID;
}
-
- /** Get the next row ID */
- protected WHRowID getNextRowID()
+
+ /** Get the data for the current row and specified column.
+ */
+ public WHValue getValue(String columnName)
+ throws WHException
+ {
+ if (currentRowID != null)
+ return table.getTableColumnValue(currentRowID,table.getColumnID(columnName));
+ throw new WHException("Can't read beyond end of accessor");
+ }
+
+ protected void goToNextLegalRow()
throws WHException
{
- if (nextRowID != null)
- return nextRowID;
-
while (true)
{
// Find the next node, using the queue
Node node = queue.pop();
if (node == null)
- return null;
+ {
+ currentRowID = null;
+ return;
+ }
if (node.getAction() == ACTION_DEREFERENCE)
{
- nextRowID = node.getRowID();
- return nextRowID;
+ currentRowID = node.getRowID();
+ return;
}
if (node.getAction() == ACTION_CHASE_EQUALS)
@@ -107,7 +123,7 @@ public class IndexAccessor implements WH
// Push the rowID, then chase the equals chain.
queue.pushNeedsDereference(chaseRowID);
// Now find the next node in the equals chain.
- LongValue nextEqualsNode = index.readIndexNodeEqualsNode(chaseRowID,indexColumns[indexColumns.length-1]);
+ LongValue nextEqualsNode = index.readIndexNodeEqualsNode(chaseRowID,indexColumnIDs[indexColumnIDs.length-1]);
if (nextEqualsNode != null)
{
// Because it's equals chain, we know that it is unnecessary to evaluate its fields, so note that when
@@ -129,9 +145,9 @@ public class IndexAccessor implements WH
// nodes in backwards order!!
// Evaluate this column
- String currentColumn = indexColumns[columnIndex];
+ long currentColumnID = indexColumnIDs[columnIndex];
// Get the column value
- WHValue columnValue = index.getTable().getValue(rowID,currentColumn);
+ WHValue columnValue = index.getTable().getTableColumnValue(rowID,currentColumnID);
// Do the assessment, if there are index criteria for this column
int criteria;
@@ -140,35 +156,70 @@ public class IndexAccessor implements WH
else
criteria = IndexCriteria.SIGNAL_LESSER | IndexCriteria.SIGNAL_GREATER | IndexCriteria.SIGNAL_EQUALS;
- // Remember, we want to push greater values first, then lesser.
- if ((criteria & IndexCriteria.SIGNAL_GREATER) != 0)
- {
- // Dereference the greater child for this column and push that node for analysis
- LongValue childRowID = index.readIndexNodeGreaterNode(rowID,indexColumns[columnIndex]);
- if (childRowID != null)
- queue.pushNeedsAnalysis(childRowID,columnIndex);
- }
- // Do the equals children next
- if ((criteria & IndexCriteria.SIGNAL_EQUALS) != 0)
+ // Remember, we want to push greater values first, then lesser. Order reversal will swap that around.
+ if (orderReversed == null || orderReversed[columnIndex] == false)
{
- // We want to continue on to the next column, or if we're at the end, we take the
- // row ID.
- if (columnIndex + 1 == indexColumns.length)
- queue.pushChaseEquals(rowID);
- else
- {
- LongValue childRowID = index.readIndexNodeColumnNode(rowID,indexColumns[columnIndex]);
- if (childRowID == null)
- throw new WHConcurrencyException();
- queue.pushNeedsAnalysis(childRowID,columnIndex+1);
+ if ((criteria & IndexCriteria.SIGNAL_GREATER) != 0)
+ {
+ // Dereference the greater child for this column and push that node for analysis
+ LongValue childRowID = index.readIndexNodeGreaterNode(rowID,indexColumnIDs[columnIndex]);
+ if (childRowID != null)
+ queue.pushNeedsAnalysis(childRowID,columnIndex);
+ }
+ // Do the equals children next
+ if ((criteria & IndexCriteria.SIGNAL_EQUALS) != 0)
+ {
+ // We want to continue on to the next column, or if we're at the end, we take the
+ // row ID.
+ if (columnIndex + 1 == indexColumnIDs.length)
+ queue.pushChaseEquals(rowID);
+ else
+ {
+ LongValue childRowID = index.readIndexNodeColumnNode(rowID,indexColumnIDs[columnIndex]);
+ if (childRowID == null)
+ throw new WHConcurrencyException();
+ queue.pushNeedsAnalysis(childRowID,columnIndex+1);
+ }
+ }
+ if ((criteria & IndexCriteria.SIGNAL_LESSER) != 0)
+ {
+ // Dereference the lesser child for this column and push that node for analysis
+ LongValue childRowID = index.readIndexNodeLesserNode(rowID,indexColumnIDs[columnIndex]);
+ if (childRowID != null)
+ queue.pushNeedsAnalysis(childRowID,columnIndex);
}
}
- if ((criteria & IndexCriteria.SIGNAL_LESSER) != 0)
+ else
{
- // Dereference the lesser child for this column and push that node for analysis
- LongValue childRowID = index.readIndexNodeLesserNode(rowID,indexColumns[columnIndex]);
- if (childRowID != null)
- queue.pushNeedsAnalysis(childRowID,columnIndex);
+ if ((criteria & IndexCriteria.SIGNAL_LESSER) != 0)
+ {
+ // Dereference the lesser child for this column and push that node for analysis
+ LongValue childRowID = index.readIndexNodeLesserNode(rowID,indexColumnIDs[columnIndex]);
+ if (childRowID != null)
+ queue.pushNeedsAnalysis(childRowID,columnIndex);
+ }
+ // Do the equals children next
+ if ((criteria & IndexCriteria.SIGNAL_EQUALS) != 0)
+ {
+ // We want to continue on to the next column, or if we're at the end, we take the
+ // row ID.
+ if (columnIndex + 1 == indexColumnIDs.length)
+ queue.pushChaseEquals(rowID);
+ else
+ {
+ LongValue childRowID = index.readIndexNodeColumnNode(rowID,indexColumnIDs[columnIndex]);
+ if (childRowID == null)
+ throw new WHConcurrencyException();
+ queue.pushNeedsAnalysis(childRowID,columnIndex+1);
+ }
+ }
+ if ((criteria & IndexCriteria.SIGNAL_GREATER) != 0)
+ {
+ // Dereference the greater child for this column and push that node for analysis
+ LongValue childRowID = index.readIndexNodeGreaterNode(rowID,indexColumnIDs[columnIndex]);
+ if (childRowID != null)
+ queue.pushNeedsAnalysis(childRowID,columnIndex);
+ }
}
}
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeColumnKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeColumnKey.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeColumnKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeColumnKey.java Sat Dec 3 15:06:22 2011
@@ -26,9 +26,9 @@ import org.apache.warthog.common.*;
public class IndexNodeColumnKey extends IndexNodeKey
{
/** Constructor */
- public IndexNodeColumnKey(long indexID, long rowID, String columnName)
+ public IndexNodeColumnKey(long indexID, long rowID, long columnID)
{
- super(indexID,rowID,columnName);
+ super(indexID,rowID,columnID);
}
public IndexNodeColumnKey(byte[] data)
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeEqualsKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeEqualsKey.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeEqualsKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeEqualsKey.java Sat Dec 3 15:06:22 2011
@@ -26,9 +26,9 @@ import org.apache.warthog.common.*;
public class IndexNodeEqualsKey extends IndexNodeKey
{
/** Constructor */
- public IndexNodeEqualsKey(long indexID, long rowID, String columnName)
+ public IndexNodeEqualsKey(long indexID, long rowID, long columnID)
{
- super(indexID,rowID,columnName);
+ super(indexID,rowID,columnID);
}
public IndexNodeEqualsKey(byte[] data)
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeGreaterKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeGreaterKey.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeGreaterKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeGreaterKey.java Sat Dec 3 15:06:22 2011
@@ -26,9 +26,9 @@ import org.apache.warthog.common.*;
public class IndexNodeGreaterKey extends IndexNodeKey
{
/** Constructor */
- public IndexNodeGreaterKey(long indexID, long rowID, String columnName)
+ public IndexNodeGreaterKey(long indexID, long rowID, long columnID)
{
- super(indexID,rowID,columnName);
+ super(indexID,rowID,columnID);
}
public IndexNodeGreaterKey(byte[] data)
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeKey.java Sat Dec 3 15:06:22 2011
@@ -27,17 +27,14 @@ public class IndexNodeKey implements WHK
{
protected long indexID;
protected long rowID;
- protected String columnName;
+ protected long columnID;
- protected long hashCodeValue;
-
/** Constructor */
- public IndexNodeKey(long indexID, long rowID, String columnName)
+ public IndexNodeKey(long indexID, long rowID, long columnID)
{
this.indexID = indexID;
this.rowID = rowID;
- this.columnName = columnName;
- //hashCodeValue = calculateHashCode(indexID,rowID,columnName);
+ this.columnID = columnID;
}
public IndexNodeKey(byte[] data)
@@ -45,30 +42,29 @@ public class IndexNodeKey implements WHK
BufferPointer bp = new BufferPointer(data);
this.indexID = LongKey.readObject(bp);
this.rowID = LongKey.readObject(bp);
- this.columnName = StringKey.readObject(bp);
- //hashCodeValue = calculateHashCode(indexID,rowID,columnName);
+ this.columnID = LongKey.readObject(bp);
}
public byte[] serializeObject()
{
byte[] rval = new byte[LongKey.sizeObject()+
- LongKey.sizeObject() + StringKey.sizeObject(columnName)];
+ LongKey.sizeObject() + LongKey.sizeObject()];
BufferPointer bp = new BufferPointer(rval);
LongKey.writeObject(bp,indexID);
LongKey.writeObject(bp,rowID);
- StringKey.writeObject(bp,columnName);
+ LongKey.writeObject(bp,columnID);
return rval;
}
public long getHashCode()
{
- return hashCodeValue;
+ return calculateHashCode(indexID,rowID,columnID);
}
- public static long calculateHashCode(long indexID, long rowID, String columnName)
+ public static long calculateHashCode(long indexID, long rowID, long columnID)
{
return LongKey.calculateHashCode(indexID) + LongKey.calculateHashCode(rowID) +
- StringKey.calculateHashCode(columnName);
+ LongKey.calculateHashCode(columnID);
}
public boolean isEquals(WHValue o)
@@ -76,14 +72,14 @@ public class IndexNodeKey implements WHK
IndexNodeKey key = (IndexNodeKey)o;
return key.indexID == indexID &&
key.rowID == rowID &&
- key.columnName.equals(columnName);
+ key.columnID == columnID;
}
public int hashCode()
{
return ((int)((indexID << 5) ^ (indexID >> 3))) +
((int)((rowID << 5) ^ (rowID >> 3))) +
- columnName.hashCode();
+ ((int)((columnID << 5) ^ (columnID >> 3)));
}
public boolean equals(Object o)
@@ -93,7 +89,7 @@ public class IndexNodeKey implements WHK
IndexNodeKey other = (IndexNodeKey)o;
return other.indexID == indexID &&
other.rowID == rowID &&
- other.columnName.equals(columnName);
+ other.columnID == columnID;
}
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeLesserKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeLesserKey.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeLesserKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeLesserKey.java Sat Dec 3 15:06:22 2011
@@ -26,9 +26,9 @@ import org.apache.warthog.common.*;
public class IndexNodeLesserKey extends IndexNodeKey
{
/** Constructor */
- public IndexNodeLesserKey(long indexID, long rowID, String columnName)
+ public IndexNodeLesserKey(long indexID, long rowID, long columnID)
{
- super(indexID,rowID,columnName);
+ super(indexID,rowID,columnID);
}
public IndexNodeLesserKey(byte[] data)
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeParentKey.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeParentKey.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeParentKey.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexNodeParentKey.java Sat Dec 3 15:06:22 2011
@@ -27,9 +27,9 @@ import org.apache.warthog.common.*;
public class IndexNodeParentKey extends IndexNodeKey
{
/** Constructor */
- public IndexNodeParentKey(long indexID, long rowID, String columnName)
+ public IndexNodeParentKey(long indexID, long rowID, long columnID)
{
- super(indexID,rowID,columnName);
+ super(indexID,rowID,columnID);
}
public IndexNodeParentKey(byte[] data)
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexValue.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexValue.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/IndexValue.java Sat Dec 3 15:06:22 2011
@@ -26,15 +26,15 @@ import org.apache.warthog.common.*;
public class IndexValue implements WHValue
{
protected long tableID;
- protected String[] columnNames;
+ protected long[] columnIDs;
protected String[] comparatorClassNames;
protected boolean unique;
/** Constructor */
- public IndexValue(long tableID, String[] columnNames, String[] comparatorClassNames, boolean unique)
+ public IndexValue(long tableID, long[] columnIDs, String[] comparatorClassNames, boolean unique)
{
this.tableID = tableID;
- this.columnNames = columnNames;
+ this.columnIDs = columnIDs;
this.comparatorClassNames = comparatorClassNames;
this.unique = unique;
}
@@ -43,7 +43,7 @@ public class IndexValue implements WHVal
{
BufferPointer bp = new BufferPointer(data);
tableID = LongValue.readObject(bp);
- columnNames = StringArray.readObject(bp);
+ columnIDs = LongArray.readObject(bp);
comparatorClassNames = StringArray.readObject(bp);
unique = BooleanValue.readObject(bp);
}
@@ -51,12 +51,12 @@ public class IndexValue implements WHVal
public byte[] serializeObject()
{
byte[] rval = new byte[LongValue.sizeObject() +
- StringArray.sizeObject(columnNames) +
+ LongArray.sizeObject(columnIDs.length) +
StringArray.sizeObject(comparatorClassNames) +
BooleanValue.sizeObject()];
BufferPointer bp = new BufferPointer(rval);
LongValue.writeObject(bp,tableID);
- StringArray.writeObject(bp,columnNames);
+ LongArray.writeObject(bp,columnIDs);
StringArray.writeObject(bp,comparatorClassNames);
BooleanValue.writeObject(bp,unique);
return rval;
@@ -67,7 +67,7 @@ public class IndexValue implements WHVal
{
IndexValue other = (IndexValue)value;
return other.tableID == this.tableID &&
- StringArray.compareObject(other.columnNames,this.columnNames) &&
+ LongArray.compareObject(other.columnIDs,this.columnIDs) &&
StringArray.compareObject(other.comparatorClassNames,this.comparatorClassNames) &&
other.unique == this.unique;
}
@@ -77,9 +77,9 @@ public class IndexValue implements WHVal
return tableID;
}
- public String[] getColumnNames()
+ public long[] getColumnIDs()
{
- return columnNames;
+ return columnIDs;
}
public String[] getComparatorClassNames()
@@ -94,10 +94,10 @@ public class IndexValue implements WHVal
public int hashCode()
{
- int rval = ((int)((tableID << 5) ^ (tableID >> 3)));
- for (int i = 0 ; i < columnNames.length ; i++)
+ int rval = (int)((tableID << 5) ^ (tableID >> 3));
+ for (int i = 0 ; i < columnIDs.length ; i++)
{
- rval += columnNames[i].hashCode();
+ rval += (int)((columnIDs[i] << 5) ^ (columnIDs[i] >> 3));
rval += comparatorClassNames[i].hashCode();
}
rval += (unique?87245:31);
@@ -110,7 +110,7 @@ public class IndexValue implements WHVal
return false;
IndexValue other = (IndexValue)o;
return other.tableID == tableID &&
- StringArray.compareObject(other.columnNames,this.columnNames) &&
+ LongArray.compareObject(other.columnIDs,this.columnIDs) &&
StringArray.compareObject(other.comparatorClassNames,this.comparatorClassNames) &&
other.unique == this.unique;
}
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/Table.java Sat Dec 3 15:06:22 2011
@@ -31,17 +31,29 @@ public class Table implements WHTable
protected LongValue tableID;
protected long tableIDValue;
protected String[] columns;
+ protected long[] columnIDs;
+ protected long nextColumnID;
+ protected Map<String,Integer> columnLookup = new HashMap<String,Integer>();
protected static final int maxInstanceCount = 128;
protected static final int maxInstanceMask = maxInstanceCount-1;
/** Constructor */
- public Table(TableStore ts, LongValue tableID, String[] columns)
+ public Table(TableStore ts, LongValue tableID, String[] columns, long[] columnIDs, long nextColumnID)
+ throws WHException
{
+ if (columnIDs.length != columns.length)
+ throw new WHException("Number of column names must match number of column IDs");
this.ts = ts;
this.tableID = tableID;
this.tableIDValue = tableID.getValue();
this.columns = columns;
+ this.columnIDs = columnIDs;
+ this.nextColumnID = nextColumnID;
+ for (int i = 0 ; i < columns.length ; i++)
+ {
+ columnLookup.put(columns[i],new Integer(i));
+ }
}
/** Get the column names.
@@ -63,7 +75,7 @@ public class Table implements WHTable
// Set the values
for (int i = 0 ; i < columns.length ; i++)
{
- setTableColumnValue(rowID,columns[i],values[i]);
+ setTableColumnValue(rowID,getColumnID(columns[i]),values[i]);
}
// Add to all indices
ts.addIndexRow(tableID,rowID,null);
@@ -73,22 +85,24 @@ public class Table implements WHTable
/** Update row(s) */
public void updateRows(String[] columns, WHValue[] values,
- WHAccessor accessor, WHFilter filter)
+ WHAccessor accessor)
throws WHException
{
if (columns.length != values.length)
throw new WHException("Column count must agree with value count");
// Convert the columns to a set, for convenience later
- Set<String> columnSet = new HashSet<String>();
+ Set<Long> columnSet = new HashSet<Long>();
for (int i = 0 ; i < columns.length ; i++)
{
- columnSet.add(columns[i]);
+ columnSet.add(new Long(columnIDs[i]));
}
- WHAccessor fa = new FilterAccessor(accessor,this,filter);
+
// Update the rows one at a time
- while (fa.hasNext())
+ while (true)
{
- LongValue rowID = (LongValue)fa.getNext();
+ LongValue rowID = (LongValue)accessor.getCurrentRowID();
+ if (rowID == null)
+ break;
// Note: The problem with this loop is that I cannot guarantee that the accessor will continue
// to work right after I delete and re-add the row to/from the indexes. If the accessor is an
@@ -101,41 +115,37 @@ public class Table implements WHTable
// Change the values as specified
for (int i = 0 ; i < columns.length ; i++)
{
- setTableColumnValue(rowID,columns[i],values[i]);
+ setTableColumnValue(rowID,getColumnID(columns[i]),values[i]);
}
// Add the row back to all indexes which can potentially intersect the changes
ts.addIndexRow(tableID,rowID,columnSet);
+ accessor.advance();
}
}
/** Delete row(s) */
- public void deleteRows(WHAccessor accessor, WHFilter filter)
+ public void deleteRows(WHAccessor accessor)
throws WHException
{
- WHAccessor fa = new FilterAccessor(accessor,this,filter);
// Read the rows one at a time
- while (fa.hasNext())
+ while (true)
{
- LongValue rowID = (LongValue)fa.getNext();
+ LongValue rowID = (LongValue)accessor.getCurrentRowID();
+ if (rowID == null)
+ break;
// Delete the row from all indexes
ts.deleteIndexRow(tableID,rowID,null);
// Delete all values
- for (int i = 0 ; i < columns.length ; i++)
+ for (int i = 0 ; i < columnIDs.length ; i++)
{
- setTableColumnValue(rowID,columns[i],null);
+ setTableColumnValue(rowID,columnIDs[i],null);
}
// Unlink the row in the linked list
removeTableRow(rowID);
+ accessor.advance();
}
}
- /** Get the data for a given row and column. */
- public WHValue getValue(WHRowID rowID, String columnName)
- throws WHException
- {
- return getTableColumnValue((LongValue)rowID,columnName);
- }
-
/** Build an accessor that simply scans all the rows in the table */
public WHAccessor buildAccessor()
throws WHException
@@ -156,6 +166,20 @@ public class Table implements WHTable
return tableIDValue;
}
+ protected long[] getColumnIDs()
+ {
+ return columnIDs;
+ }
+
+ protected long getColumnID(String columnName)
+ throws WHException
+ {
+ Integer i = columnLookup.get(columnName);
+ if (i == null)
+ throw new WHException("No such column: "+columnName);
+ return columnIDs[i.intValue()];
+ }
+
/** Remove all rows.
* WARNING: This effectively causes the entire table to have to fit into memory!
* It is better to delete rows piecemeal in separate transactions.
@@ -163,7 +187,7 @@ public class Table implements WHTable
protected void remove()
throws WHException
{
- deleteRows(buildAccessor(),null);
+ deleteRows(buildAccessor());
}
/** Add a table row to the linked list for that table.
@@ -242,18 +266,18 @@ public class Table implements WHTable
/** Set a table column value.
*/
- protected void setTableColumnValue(LongValue rowID, String columnName, WHValue value)
+ protected void setTableColumnValue(LongValue rowID, long columnID, WHValue value)
throws WHException
{
- ts.put(new TableColumnKey(tableIDValue,rowID.getValue(),columnName),value);
+ ts.put(new TableColumnKey(tableIDValue,rowID.getValue(),columnID),value);
}
/** Get a table column value.
*/
- protected WHValue getTableColumnValue(LongValue rowID, String columnName)
+ protected WHValue getTableColumnValue(LongValue rowID, long columnID)
throws WHException
{
- return ts.get(new TableColumnKey(tableIDValue,rowID.getValue(),columnName));
+ return ts.get(new TableColumnKey(tableIDValue,rowID.getValue(),columnID));
}
/** Get the max number of instances.
Modified: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java?rev=1209929&r1=1209928&r2=1209929&view=diff
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java (original)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/tablestore/TableAccessor.java Sat Dec 3 15:06:22 2011
@@ -27,7 +27,7 @@ import java.util.*;
public class TableAccessor implements WHAccessor
{
protected Table table;
- /** This is the next row to be returned. */
+ /** This is the current row to be returned. */
protected LongValue currentRowID;
/** This is the current instance number */
protected int currentInstanceNumber;
@@ -39,36 +39,12 @@ public class TableAccessor implements WH
this.table = table;
currentInstanceNumber = 0;
currentRowID = null;
- seekToNext();
+ goToNextLegalRow();
}
-
- /** Are there any more rows?
- */
- public boolean hasNext()
- throws WHException
- {
- return currentRowID != null;
- }
-
- /** Read the next matching relationship row ID,
- */
- public WHRowID getNext()
+ protected void goToNextLegalRow()
throws WHException
{
- WHRowID rval = currentRowID;
- seekToNext();
- return rval;
- }
-
- // Protected methods
-
- protected void seekToNext()
- throws WHException
- {
- if (currentInstanceNumber == table.getMaxInstanceNumber())
- return;
-
while (true)
{
if (currentRowID == null)
@@ -89,5 +65,35 @@ public class TableAccessor implements WH
return;
}
}
+
+ /** Advance to the next row.
+ */
+ public void advance()
+ throws WHException
+ {
+ if (currentRowID != null)
+ {
+ goToNextLegalRow();
+ }
+ }
+
+ /** Read the current relationship row ID, Null will be returned if we are
+ * at the end of the sequence.
+ */
+ public WHRowID getCurrentRowID()
+ throws WHException
+ {
+ return currentRowID;
+ }
+
+ /** Get the data for the current row and specified column.
+ */
+ public WHValue getValue(String columnName)
+ throws WHException
+ {
+ if (currentRowID != null)
+ return table.getTableColumnValue(currentRowID,table.getColumnID(columnName));
+ throw new WHException("Can't read beyond end of accessor");
+ }
}