private FileSystemPartitionIterator partitionIterator() { DatasetDescriptor descriptor = dataset.getDescriptor(); try { return new FileSystemPartitionIterator( fs, root, descriptor.getPartitionStrategy(), descriptor.getSchema(), getKeyPredicate()); } catch (IOException ex) { throw new DatasetException("Cannot list partitions in view:" + this, ex); } }
@Test public void testWith() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.with("timestamp", oct_24_2013).toKeyPredicate()); assertIterableEquals(keys.subList(16, 17), partitions); }
@Test public void testLongConstraint() throws IOException { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.with("day", 22L).toKeyPredicate()); List<StorageKey> expected = Lists.newArrayList( keys.get(0), keys.get(3), keys.get(6), keys.get(9), keys.get(12), keys.get(15), keys.get(18), keys.get(21)); assertIterableEquals(expected, partitions); TestHelpers.assertThrows("Should reject constraint with string type", IllegalArgumentException.class, new Runnable() { @Override public void run() { emptyConstraints.with("day", "24"); } }); TestHelpers.assertThrows("Should reject constraint with long type", IllegalArgumentException.class, new Runnable() { @Override public void run() { emptyConstraints.with("day", 25); } }); }
@Test public void testFrom() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.from("timestamp", oct_24_2013).toKeyPredicate()); assertIterableEquals(keys.subList(16, 24), partitions); }
@Test public void testWith() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.with("timestamp", oct_24_2013).toKeyPredicate()); assertIterableEquals(keys.subList(16, 17), partitions); }
@Test public void testUnbounded() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.toKeyPredicate()); assertIterableEquals(keys, partitions); }
@Test public void testAfter() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.fromAfter("timestamp", oct_24_2013_end).toKeyPredicate()); assertIterableEquals(keys.subList(17, 24), partitions); }
@Test public void testTo() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.to("timestamp", oct_25_2012).toKeyPredicate()); assertIterableEquals(keys.subList(0, 6), partitions); }
@Test public void testBefore() throws Exception { Iterable <StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.toBefore("timestamp", oct_25_2012).toKeyPredicate()); assertIterableEquals(keys.subList(0, 5), partitions); }
@Test public void testUnbounded() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.toKeyPredicate()); assertIterableEquals(keys, partitions); }
@Test public void testBefore() throws Exception { Iterable <StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.toBefore("timestamp", oct_25_2012).toKeyPredicate()); assertIterableEquals(keys.subList(0, 5), partitions); }
@Test public void testAfter() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.fromAfter("timestamp", oct_24_2013_end).toKeyPredicate()); assertIterableEquals(keys.subList(17, 24), partitions); }
@Test public void testTo() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.to("timestamp", oct_25_2012).toKeyPredicate()); assertIterableEquals(keys.subList(0, 6), partitions); }
@Test public void testUnbounded() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.toKeyPredicate()); assertIterableEquals(keys, partitions); }
@Test public void testFrom() throws Exception { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.from("timestamp", oct_24_2013).toKeyPredicate()); assertIterableEquals(keys.subList(16, 24), partitions); }
@Test public void testDayRange() throws Exception { Predicate<StorageKey> predicate = emptyConstraints .from("timestamp", oct_24_2013) .to("timestamp", oct_24_2013_end) .toKeyPredicate(); Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, predicate); assertIterableEquals(keys.subList(16, 17), partitions); }
@Test public void testLargerRange() throws Exception { Predicate<StorageKey> predicate = emptyConstraints .from("timestamp", oct_25_2012) .to("timestamp", oct_24_2013) .toKeyPredicate(); Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, predicate); assertIterableEquals(keys.subList(5, 17), partitions); }
@Test public void testIntConstraint() throws IOException { Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, emptyConstraints.with("month", 9).toKeyPredicate()); List<StorageKey> expected = Lists.newArrayList(); expected.addAll(keys.subList(0, 3)); expected.addAll(keys.subList(12, 15)); assertIterableEquals(expected, partitions); TestHelpers.assertThrows("Should reject constraint with string type", IllegalArgumentException.class, new Runnable() { @Override public void run() { emptyConstraints.with("month", "10"); } }); TestHelpers.assertThrows("Should reject constraint with long type", IllegalArgumentException.class, new Runnable() { @Override public void run() { emptyConstraints.with("month", 11L); } }); }
@Test public void testDayRange() throws Exception { Predicate<StorageKey> predicate = emptyConstraints .from("timestamp", oct_24_2013) .to("timestamp", oct_24_2013_end) .toKeyPredicate(); Iterable<StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, predicate); assertIterableEquals(keys.subList(16, 17), partitions); }
@Test public void testLargerRange() throws Exception { Predicate<StorageKey> predicate = emptyConstraints .from("timestamp", oct_25_2012) .to("timestamp", oct_24_2013) .toKeyPredicate(); Iterable <StorageKey> partitions = new FileSystemPartitionIterator( fileSystem, testDirectory, strategy, schema, predicate); assertIterableEquals(keys.subList(5, 17), partitions); }