mirror of https://github.com/apache/cassandra
make ColumnGroupReader implement Iterator<IColumn>
patch by jbellis; reviewed by gdusbabek for CASSANDRA-1338 git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@981541 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8aa58cb65d
commit
ea06b0fe23
|
|
@ -41,13 +41,13 @@ import org.apache.cassandra.utils.FBUtilities;
|
||||||
/**
|
/**
|
||||||
* A Column Iterator over SSTable
|
* A Column Iterator over SSTable
|
||||||
*/
|
*/
|
||||||
class SSTableSliceIterator extends AbstractIterator<IColumn> implements IColumnIterator
|
class SSTableSliceIterator implements IColumnIterator
|
||||||
{
|
{
|
||||||
private final boolean reversed;
|
private final boolean reversed;
|
||||||
private final byte[] startColumn;
|
private final byte[] startColumn;
|
||||||
private final byte[] finishColumn;
|
private final byte[] finishColumn;
|
||||||
private final AbstractType comparator;
|
private final AbstractType comparator;
|
||||||
private ColumnGroupReader reader;
|
private IColumnIterator reader;
|
||||||
private boolean closeFileWhenDone = false;
|
private boolean closeFileWhenDone = false;
|
||||||
private DecoratedKey decoratedKey;
|
private DecoratedKey decoratedKey;
|
||||||
|
|
||||||
|
|
@ -105,42 +105,24 @@ class SSTableSliceIterator extends AbstractIterator<IColumn> implements IColumnI
|
||||||
return decoratedKey;
|
return decoratedKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isColumnNeeded(IColumn column)
|
public ColumnFamily getColumnFamily() throws IOException
|
||||||
{
|
{
|
||||||
if (startColumn.length == 0 && finishColumn.length == 0)
|
return reader == null ? null : reader.getColumnFamily();
|
||||||
return true;
|
|
||||||
else if (startColumn.length == 0 && !reversed)
|
|
||||||
return comparator.compare(column.name(), finishColumn) <= 0;
|
|
||||||
else if (startColumn.length == 0 && reversed)
|
|
||||||
return comparator.compare(column.name(), finishColumn) >= 0;
|
|
||||||
else if (finishColumn.length == 0 && !reversed)
|
|
||||||
return comparator.compare(column.name(), startColumn) >= 0;
|
|
||||||
else if (finishColumn.length == 0 && reversed)
|
|
||||||
return comparator.compare(column.name(), startColumn) <= 0;
|
|
||||||
else if (!reversed)
|
|
||||||
return comparator.compare(column.name(), startColumn) >= 0 && comparator.compare(column.name(), finishColumn) <= 0;
|
|
||||||
else // if reversed
|
|
||||||
return comparator.compare(column.name(), startColumn) <= 0 && comparator.compare(column.name(), finishColumn) >= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnFamily getColumnFamily()
|
public boolean hasNext()
|
||||||
{
|
{
|
||||||
return reader == null ? null : reader.getEmptyColumnFamily();
|
return reader.hasNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IColumn computeNext()
|
public IColumn next()
|
||||||
{
|
{
|
||||||
if (reader == null)
|
return reader.next();
|
||||||
return endOfData();
|
}
|
||||||
|
|
||||||
while (true)
|
public void remove()
|
||||||
{
|
{
|
||||||
IColumn column = reader.pollColumn();
|
throw new UnsupportedOperationException();
|
||||||
if (column == null)
|
|
||||||
return endOfData();
|
|
||||||
if (isColumnNeeded(column))
|
|
||||||
return column;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
|
|
@ -154,7 +136,7 @@ class SSTableSliceIterator extends AbstractIterator<IColumn> implements IColumnI
|
||||||
* blocks before/after it for each next call. This function assumes that
|
* blocks before/after it for each next call. This function assumes that
|
||||||
* the CF is sorted by name and exploits the name index.
|
* the CF is sorted by name and exploits the name index.
|
||||||
*/
|
*/
|
||||||
class ColumnGroupReader
|
class ColumnGroupReader extends AbstractIterator<IColumn> implements IColumnIterator
|
||||||
{
|
{
|
||||||
private final ColumnFamily emptyColumnFamily;
|
private final ColumnFamily emptyColumnFamily;
|
||||||
|
|
||||||
|
|
@ -186,27 +168,51 @@ class SSTableSliceIterator extends AbstractIterator<IColumn> implements IColumnI
|
||||||
curRangeIndex--;
|
curRangeIndex--;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnFamily getEmptyColumnFamily()
|
public ColumnFamily getColumnFamily()
|
||||||
{
|
{
|
||||||
return emptyColumnFamily;
|
return emptyColumnFamily;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IColumn pollColumn()
|
public DecoratedKey getKey()
|
||||||
{
|
{
|
||||||
IColumn column = blockColumns.poll();
|
throw new UnsupportedOperationException();
|
||||||
if (column == null)
|
}
|
||||||
|
|
||||||
|
private boolean isColumnNeeded(IColumn column)
|
||||||
|
{
|
||||||
|
if (startColumn.length == 0 && finishColumn.length == 0)
|
||||||
|
return true;
|
||||||
|
else if (startColumn.length == 0 && !reversed)
|
||||||
|
return comparator.compare(column.name(), finishColumn) <= 0;
|
||||||
|
else if (startColumn.length == 0 && reversed)
|
||||||
|
return comparator.compare(column.name(), finishColumn) >= 0;
|
||||||
|
else if (finishColumn.length == 0 && !reversed)
|
||||||
|
return comparator.compare(column.name(), startColumn) >= 0;
|
||||||
|
else if (finishColumn.length == 0 && reversed)
|
||||||
|
return comparator.compare(column.name(), startColumn) <= 0;
|
||||||
|
else if (!reversed)
|
||||||
|
return comparator.compare(column.name(), startColumn) >= 0 && comparator.compare(column.name(), finishColumn) <= 0;
|
||||||
|
else // if reversed
|
||||||
|
return comparator.compare(column.name(), startColumn) <= 0 && comparator.compare(column.name(), finishColumn) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IColumn computeNext()
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
{
|
{
|
||||||
|
IColumn column = blockColumns.poll();
|
||||||
|
if (column != null && isColumnNeeded(column))
|
||||||
|
return column;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (getNextBlock())
|
if (column == null && !getNextBlock())
|
||||||
column = blockColumns.poll();
|
return endOfData();
|
||||||
}
|
}
|
||||||
catch (IOException e)
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return column;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getNextBlock() throws IOException
|
public boolean getNextBlock() throws IOException
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue