ResultFilter extends Constraint { @Override public SeekingCurrentIterator getResultIterator() { SeekingCurrentIterator results; if (this.subConstraint == null) { Get get = new Get(this.range); for (CColumn column : this.columns) get.addColumn(column.getColumnFamily(), column.getColumnQualifier()); results = table.get(get); } else results = this.subConstraint.getResultIterator(); if (this.columns == null || this.columns.length == 0) return results; return new FilteringIterator(this.columns, results); } ResultFilter();  ResultFilter(Constraint subConstraint, CRange range,
      CColumn... columns);  ResultFilter(TableAdapter primaryTable, CRange range,
      CColumn... columns);  ResultFilter(CRange range, Constraint subConstraint);  ResultFilter(TableAdapter primaryTable, CRange range);  ResultFilter(Constraint subConstraint, CColumn... columns);  ResultFilter(TableAdapter primaryTable, CColumn... columns);  ResultFilter(TableAdapter primaryTable); @Override boolean equals(Object compareto); @Override int hashCode(); @Override String toString(); @Override SeekingCurrentIterator getResultIterator(); @Override void readFields(DataInput in); @Override void write(DataOutput out);  }
@Test public void selectStar() throws Exception { TableAdapter table = new InMemoryTable(); List<CKeyValue> values = new ArrayList<CKeyValue>(); values.add(new CKeyValue(new byte[] { 1 })); values.add(new CKeyValue(new byte[] { 2 }, new byte[] { 3 }, new byte[] { 4 })); values.add(new CKeyValue(new byte[] { 3 }, new byte[] { 4 }, new byte[] { 5 }, 0, new byte[] { 6 })); table.put(new Put(values)); ResultFilter selectStar = new ResultFilter(table); Iterator<Result> results = selectStar.getResultIterator(); assertCount(results, 3); assertSeek(selectStar.getResultIterator(), new byte[] { 2 }, true, 1, new byte[0], new byte[] { 6 }); }
@Test public void selectRange() throws Exception { TableAdapter table = new InMemoryTable(); List<CKeyValue> values = new ArrayList<CKeyValue>(); values.add(new CKeyValue(new byte[] { 1 })); values.add(new CKeyValue(new byte[] { 2 }, new byte[] { 3 }, new byte[] { 4 })); values.add(new CKeyValue(new byte[] { 3 }, new byte[] { 4 }, new byte[] { 5 }, 0, new byte[] { 6 })); table.put(new Put(values)); ResultFilter range = new ResultFilter(table, new CRange(new byte[] { 1 }, new byte[] { 3 })); assertCount(range.getResultIterator(), 3); SeekingCurrentIterator iter = range.getResultIterator(); iter.seek(new byte[] { 2 }); int count = 0; assertArrayEquals(new byte[] { 2 }, iter.current().getRecordId()); while (iter.hasNext()) { iter.next(); count++; } assertEquals(1, count); range = new ResultFilter(table, new CRange(new byte[] { 2 })); assertCount(range.getResultIterator(), 1); }
@Test public void selectCF() throws Exception { TableAdapter table = new InMemoryTable(); List<CKeyValue> values = new ArrayList<CKeyValue>(); values.add(new CKeyValue(new byte[] { 1 })); values.add(new CKeyValue(new byte[] { 2 }, new byte[] { 3 }, new byte[] { 4 })); values.add(new CKeyValue(new byte[] { 3 }, new byte[] { 3 }, new byte[] { 5 }, 0, new byte[] { 6 })); table.put(new Put(values)); ResultFilter families = new ResultFilter(table, new CColumn( new byte[] { 3 })); assertCount(families.getResultIterator(), 2); assertSeek(families.getResultIterator(), new byte[] { 2 }, true, 1, new byte[0], new byte[] { 6 }); families = new ResultFilter(table, new CColumn(new byte[] { 2 })); assertSeek(families.getResultIterator(), new byte[] { 2 }, false, 0); }
@Test public void selectCQ() throws Exception { TableAdapter table = new InMemoryTable(); List<CKeyValue> values = new ArrayList<CKeyValue>(); values.add(new CKeyValue(new byte[] { 1 })); values.add(new CKeyValue(new byte[] { 2 }, new byte[] { 3 }, new byte[] { 4 })); values.add(new CKeyValue(new byte[] { 3 }, new byte[] { 4 }, new byte[] { 5 }, 0, new byte[] { 6 })); table.put(new Put(values)); ResultFilter families = new ResultFilter(table, new CColumn( new byte[] { 3 }, new byte[] { 4 })); assertCount(families.getResultIterator(), 1); families = new ResultFilter(table, new CColumn(new byte[] { 3 }, new byte[] { 5 })); assertCount(families.getResultIterator(), 0); }
@Test public void selectMultipleColumns() throws Exception { TableAdapter table = new InMemoryTable(); List<CKeyValue> values = new ArrayList<CKeyValue>(); values.add(new CKeyValue(new byte[] { 1 })); values.add(new CKeyValue(new byte[] { 2 }, new byte[] { 3 }, new byte[] { 4 })); values.add(new CKeyValue(new byte[] { 3 }, new byte[] { 4 }, new byte[] { 5 }, 0, new byte[] { 6 })); table.put(new Put(values)); ResultFilter columns = new ResultFilter(table, new CColumn(new byte[] { 3 }), new CColumn(new byte[] { 4 })); assertCount(columns.getResultIterator(), 2); columns = new ResultFilter(table, new CColumn(new byte[] { 3 })); assertCount(columns.getResultIterator(), 1); columns = new ResultFilter(table, new CColumn(new byte[] { 3 }, new byte[] { 4 })); assertCount(columns.getResultIterator(), 1); columns = new ResultFilter(table, new CColumn(new byte[] { 3 }, new byte[] { 5 })); assertCount(columns.getResultIterator(), 0); columns = new ResultFilter(table, new CColumn(new byte[] { 4 })); assertCount(columns.getResultIterator(), 1); }