use of org.apache.accumulo.core.client.ScannerBase in project accumulo by apache.
the class SampleIT method assertSampleNotPresent.
private void assertSampleNotPresent(SamplerConfiguration sc, ScannerBase... scanners) {
for (ScannerBase scanner : scanners) {
SamplerConfiguration csc = scanner.getSamplerConfiguration();
scanner.setSamplerConfiguration(sc);
try {
for (Entry<Key, Value> entry : scanner) {
entry.getKey();
}
Assert.fail("Expected SampleNotPresentException, but it did not happen : " + scanner.getClass().getSimpleName());
} catch (SampleNotPresentException e) {
}
scanner.clearSamplerConfiguration();
for (Entry<Key, Value> entry : scanner) {
entry.getKey();
}
if (csc == null) {
scanner.clearSamplerConfiguration();
} else {
scanner.setSamplerConfiguration(csc);
}
}
}
use of org.apache.accumulo.core.client.ScannerBase in project accumulo by apache.
the class SampleIT method testBasic.
@Test
public void testBasic() throws Exception {
Connector conn = getConnector();
String tableName = getUniqueNames(1)[0];
String clone = tableName + "_clone";
conn.tableOperations().create(tableName, new NewTableConfiguration().enableSampling(SC1));
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
TreeMap<Key, Value> expected = new TreeMap<>();
String someRow = writeData(bw, SC1, expected);
Assert.assertEquals(20, expected.size());
Scanner scanner = conn.createScanner(tableName, Authorizations.EMPTY);
Scanner isoScanner = new IsolatedScanner(conn.createScanner(tableName, Authorizations.EMPTY));
Scanner csiScanner = new ClientSideIteratorScanner(conn.createScanner(tableName, Authorizations.EMPTY));
scanner.setSamplerConfiguration(SC1);
csiScanner.setSamplerConfiguration(SC1);
isoScanner.setSamplerConfiguration(SC1);
isoScanner.setBatchSize(10);
BatchScanner bScanner = conn.createBatchScanner(tableName, Authorizations.EMPTY, 2);
bScanner.setSamplerConfiguration(SC1);
bScanner.setRanges(Arrays.asList(new Range()));
check(expected, scanner, bScanner, isoScanner, csiScanner);
conn.tableOperations().flush(tableName, null, null, true);
Scanner oScanner = newOfflineScanner(conn, tableName, clone, SC1);
check(expected, scanner, bScanner, isoScanner, csiScanner, oScanner);
// ensure non sample data can be scanned after scanning sample data
for (ScannerBase sb : Arrays.asList(scanner, bScanner, isoScanner, csiScanner, oScanner)) {
sb.clearSamplerConfiguration();
Assert.assertEquals(20000, Iterables.size(sb));
sb.setSamplerConfiguration(SC1);
}
Iterator<Key> it = expected.keySet().iterator();
while (it.hasNext()) {
Key k = it.next();
if (k.getRow().toString().equals(someRow)) {
it.remove();
}
}
expected.put(new Key(someRow, "cf1", "cq1", 8), new Value("42".getBytes()));
expected.put(new Key(someRow, "cf1", "cq3", 8), new Value("suprise".getBytes()));
Mutation m = new Mutation(someRow);
m.put("cf1", "cq1", 8, "42");
m.putDelete("cf1", "cq2", 8);
m.put("cf1", "cq3", 8, "suprise");
bw.addMutation(m);
bw.close();
check(expected, scanner, bScanner, isoScanner, csiScanner);
conn.tableOperations().flush(tableName, null, null, true);
oScanner = newOfflineScanner(conn, tableName, clone, SC1);
check(expected, scanner, bScanner, isoScanner, csiScanner, oScanner);
scanner.setRange(new Range(someRow));
isoScanner.setRange(new Range(someRow));
csiScanner.setRange(new Range(someRow));
oScanner.setRange(new Range(someRow));
bScanner.setRanges(Arrays.asList(new Range(someRow)));
expected.clear();
expected.put(new Key(someRow, "cf1", "cq1", 8), new Value("42".getBytes()));
expected.put(new Key(someRow, "cf1", "cq3", 8), new Value("suprise".getBytes()));
check(expected, scanner, bScanner, isoScanner, csiScanner, oScanner);
}
use of org.apache.accumulo.core.client.ScannerBase in project accumulo by apache.
the class SampleIT method check.
private void check(TreeMap<Key, Value> expected, ScannerBase... scanners) {
TreeMap<Key, Value> actual = new TreeMap<>();
for (ScannerBase s : scanners) {
actual.clear();
for (Entry<Key, Value> entry : s) {
actual.put(entry.getKey(), entry.getValue());
}
Assert.assertEquals(String.format("Saw %d instead of %d entries using %s", actual.size(), expected.size(), s.getClass().getSimpleName()), expected, actual);
}
}
use of org.apache.accumulo.core.client.ScannerBase in project accumulo by apache.
the class SampleIT method testIterator.
@Test
public void testIterator() throws Exception {
Connector conn = getConnector();
String tableName = getUniqueNames(1)[0];
String clone = tableName + "_clone";
conn.tableOperations().create(tableName, new NewTableConfiguration().enableSampling(SC1));
BatchWriter bw = conn.createBatchWriter(tableName, new BatchWriterConfig());
TreeMap<Key, Value> expected = new TreeMap<>();
writeData(bw, SC1, expected);
ArrayList<Key> keys = new ArrayList<>(expected.keySet());
Range range1 = new Range(keys.get(6), true, keys.get(11), true);
Scanner scanner = null;
Scanner isoScanner = null;
ClientSideIteratorScanner csiScanner = null;
BatchScanner bScanner = null;
Scanner oScanner = null;
try {
scanner = conn.createScanner(tableName, Authorizations.EMPTY);
isoScanner = new IsolatedScanner(conn.createScanner(tableName, Authorizations.EMPTY));
csiScanner = new ClientSideIteratorScanner(conn.createScanner(tableName, Authorizations.EMPTY));
bScanner = conn.createBatchScanner(tableName, Authorizations.EMPTY, 2);
csiScanner.setIteratorSamplerConfiguration(SC1);
List<? extends ScannerBase> scanners = Arrays.asList(scanner, isoScanner, bScanner, csiScanner);
for (ScannerBase s : scanners) {
s.addScanIterator(new IteratorSetting(100, IteratorThatUsesSample.class));
}
// the iterator should see less than 10 entries in sample data, and return data
setRange(range1, scanners);
for (ScannerBase s : scanners) {
Assert.assertEquals(2954, countEntries(s));
}
Range range2 = new Range(keys.get(5), true, keys.get(18), true);
setRange(range2, scanners);
// the iterator should see more than 10 entries in sample data, and return no data
for (ScannerBase s : scanners) {
Assert.assertEquals(0, countEntries(s));
}
// flush an rerun same test against files
conn.tableOperations().flush(tableName, null, null, true);
oScanner = newOfflineScanner(conn, tableName, clone, null);
oScanner.addScanIterator(new IteratorSetting(100, IteratorThatUsesSample.class));
scanners = Arrays.asList(scanner, isoScanner, bScanner, csiScanner, oScanner);
setRange(range1, scanners);
for (ScannerBase s : scanners) {
Assert.assertEquals(2954, countEntries(s));
}
setRange(range2, scanners);
for (ScannerBase s : scanners) {
Assert.assertEquals(0, countEntries(s));
}
updateSamplingConfig(conn, tableName, SC2);
csiScanner.setIteratorSamplerConfiguration(SC2);
oScanner = newOfflineScanner(conn, tableName, clone, null);
oScanner.addScanIterator(new IteratorSetting(100, IteratorThatUsesSample.class));
scanners = Arrays.asList(scanner, isoScanner, bScanner, csiScanner, oScanner);
for (ScannerBase s : scanners) {
try {
countEntries(s);
Assert.fail("Expected SampleNotPresentException, but it did not happen : " + s.getClass().getSimpleName());
} catch (SampleNotPresentException e) {
}
}
} finally {
if (scanner != null) {
scanner.close();
}
if (bScanner != null) {
bScanner.close();
}
if (isoScanner != null) {
isoScanner.close();
}
if (csiScanner != null) {
csiScanner.close();
}
if (oScanner != null) {
oScanner.close();
}
}
}
use of org.apache.accumulo.core.client.ScannerBase in project incubator-rya by apache.
the class AccumuloTemporalIndexer method queryInstantInsideInterval.
/**
* Get instances inside a given interval.
* Returns after interval's beginning time, and before ending time,
* exclusive (don't match the beginning and ending).
*/
@Override
public CloseableIteration<Statement, QueryEvaluationException> queryInstantInsideInterval(final TemporalInterval queryInterval, final StatementConstraints constraints) throws QueryEvaluationException {
// get rows where the time is after the given interval's beginning time and before the ending time.
final TemporalInterval theQueryInterval = queryInterval;
final Query query = new Query() {
private final TemporalInterval queryInterval = theQueryInterval;
@Override
public Range getRange(final KeyParts keyParts) {
final Text start = Range.followingPrefix(new Text(keyParts.getQueryKey(queryInterval.getHasBeginning())));
// <-- end specific logic
final Text endAt = new Text(keyParts.getQueryKey(queryInterval.getHasEnd()));
// System.out.println("Scanning queryInstantInsideInterval: from excluding:" + KeyParts.toHumanString(start) + " up to:" + KeyParts.toHumanString(endAt));
return new Range(start, false, endAt, false);
}
};
final ScannerBase scanner = query.doQuery(queryInterval.getHasBeginning(), constraints);
return getContextIteratorWrapper(scanner, constraints.getContext());
}
Aggregations