@Test public void testRange() { populateTestEntities(10); final AbstractRefinableView<TestEntity> range = new DaoView<TestEntity>(ds, TestEntity.class) .fromAfter(NAMES[0], "1").to(NAMES[0], "9") .fromAfter(NAMES[1], "1").to(NAMES[1], "9"); Assert.assertTrue(range.includes(newTestEntity("5", "5"))); Assert.assertTrue(range.includes(newTestEntity("5", "55"))); Assert.assertTrue(range.includes(newTestEntity("9", "89"))); Assert.assertTrue(range.includes(newTestEntity("9", "9"))); Assert.assertFalse(range.includes(newTestEntity("1", "1"))); Assert.assertFalse(range.includes(newTestEntity("1", "0"))); Assert.assertFalse(range.includes(newTestEntity("1", "10"))); Assert.assertFalse(range.includes(newTestEntity("9", "99"))); DatasetReader<TestEntity> reader = range.newReader(); int cnt = 2; try { for (TestEntity entity : reader) { Assert.assertEquals(Integer.toString(cnt), entity.getPart1()); Assert.assertEquals(Integer.toString(cnt), entity.getPart2()); cnt++; } } finally { reader.close(); } Assert.assertEquals(10, cnt); }
@Override public DatasetReader<E> newReader() { final DatasetReader<E> wrappedReader = newEntityScanner(); final Iterator<E> filteredIterator = constraints.filter( wrappedReader.iterator(), getAccessor()); AbstractDatasetReader<E> reader = new AbstractDatasetReader<E>() { @Override public void initialize() { if (wrappedReader instanceof InitializeAccessor) { ((InitializeAccessor) wrappedReader).initialize(); } } @Override public boolean hasNext() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.hasNext(); } @Override public E next() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.next(); } @Override public void remove() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); filteredIterator.remove(); } @Override public void close() { wrappedReader.close(); } @Override public boolean isOpen() { return wrappedReader.isOpen(); } @Override public Iterator<E> iterator() { return filteredIterator; } }; reader.initialize(); return reader; }
DaoView extends AbstractRefinableView<E> implements InputFormatAccessor<E> { @Override public DatasetReader<E> newReader() { final DatasetReader<E> wrappedReader = newEntityScanner(); final Iterator<E> filteredIterator = constraints.filter( wrappedReader.iterator(), getAccessor()); AbstractDatasetReader<E> reader = new AbstractDatasetReader<E>() { @Override public void initialize() { if (wrappedReader instanceof InitializeAccessor) { ((InitializeAccessor) wrappedReader).initialize(); } } @Override public boolean hasNext() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.hasNext(); } @Override public E next() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.next(); } @Override public void remove() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); filteredIterator.remove(); } @Override public void close() { wrappedReader.close(); } @Override public boolean isOpen() { return wrappedReader.isOpen(); } @Override public Iterator<E> iterator() { return filteredIterator; } }; reader.initialize(); return reader; } }
DaoView extends AbstractRefinableView<E> implements InputFormatAccessor<E> { @Override public DatasetReader<E> newReader() { final DatasetReader<E> wrappedReader = newEntityScanner(); final Iterator<E> filteredIterator = constraints.filter( wrappedReader.iterator(), getAccessor()); AbstractDatasetReader<E> reader = new AbstractDatasetReader<E>() { @Override public void initialize() { if (wrappedReader instanceof InitializeAccessor) { ((InitializeAccessor) wrappedReader).initialize(); } } @Override public boolean hasNext() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.hasNext(); } @Override public E next() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.next(); } @Override public void remove() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); filteredIterator.remove(); } @Override public void close() { wrappedReader.close(); } @Override public boolean isOpen() { return wrappedReader.isOpen(); } @Override public Iterator<E> iterator() { return filteredIterator; } }; reader.initialize(); return reader; } DaoView(DaoDataset<E> dataset, Class<E> type); private  DaoView(DaoView<E> view, Constraints constraints); private  DaoView(DaoView<?> view, Schema schema, Class<E> type); }
DaoView extends AbstractRefinableView<E> implements InputFormatAccessor<E> { @Override public DatasetReader<E> newReader() { final DatasetReader<E> wrappedReader = newEntityScanner(); final Iterator<E> filteredIterator = constraints.filter( wrappedReader.iterator(), getAccessor()); AbstractDatasetReader<E> reader = new AbstractDatasetReader<E>() { @Override public void initialize() { if (wrappedReader instanceof InitializeAccessor) { ((InitializeAccessor) wrappedReader).initialize(); } } @Override public boolean hasNext() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.hasNext(); } @Override public E next() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.next(); } @Override public void remove() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); filteredIterator.remove(); } @Override public void close() { wrappedReader.close(); } @Override public boolean isOpen() { return wrappedReader.isOpen(); } @Override public Iterator<E> iterator() { return filteredIterator; } }; reader.initialize(); return reader; } DaoView(DaoDataset<E> dataset, Class<E> type); private  DaoView(DaoView<E> view, Constraints constraints); private  DaoView(DaoView<?> view, Schema schema, Class<E> type); @Override DatasetReader<E> newReader(); @Override DatasetWriter<E> newWriter(); @Override InputFormat<E, Void> getInputFormat(Configuration conf); }
DaoView extends AbstractRefinableView<E> implements InputFormatAccessor<E> { @Override public DatasetReader<E> newReader() { final DatasetReader<E> wrappedReader = newEntityScanner(); final Iterator<E> filteredIterator = constraints.filter( wrappedReader.iterator(), getAccessor()); AbstractDatasetReader<E> reader = new AbstractDatasetReader<E>() { @Override public void initialize() { if (wrappedReader instanceof InitializeAccessor) { ((InitializeAccessor) wrappedReader).initialize(); } } @Override public boolean hasNext() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.hasNext(); } @Override public E next() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); return filteredIterator.next(); } @Override public void remove() { Preconditions.checkState(isOpen(), "Attempt to read from a scanner that is not open"); filteredIterator.remove(); } @Override public void close() { wrappedReader.close(); } @Override public boolean isOpen() { return wrappedReader.isOpen(); } @Override public Iterator<E> iterator() { return filteredIterator; } }; reader.initialize(); return reader; } DaoView(DaoDataset<E> dataset, Class<E> type); private  DaoView(DaoView<E> view, Constraints constraints); private  DaoView(DaoView<?> view, Schema schema, Class<E> type); @Override DatasetReader<E> newReader(); @Override DatasetWriter<E> newWriter(); @Override InputFormat<E, Void> getInputFormat(Configuration conf);  }