Search in sources :

Example 1 with ScannerBase

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);
        }
    }
}
Also used : SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) ScannerBase(org.apache.accumulo.core.client.ScannerBase) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key)

Example 2 with ScannerBase

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);
}
Also used : ClientSideIteratorScanner(org.apache.accumulo.core.client.ClientSideIteratorScanner) Connector(org.apache.accumulo.core.client.Connector) OfflineScanner(org.apache.accumulo.core.client.impl.OfflineScanner) BatchScanner(org.apache.accumulo.core.client.BatchScanner) ClientSideIteratorScanner(org.apache.accumulo.core.client.ClientSideIteratorScanner) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) ScannerBase(org.apache.accumulo.core.client.ScannerBase) BatchScanner(org.apache.accumulo.core.client.BatchScanner) TreeMap(java.util.TreeMap) Range(org.apache.accumulo.core.data.Range) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) Mutation(org.apache.accumulo.core.data.Mutation) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 3 with ScannerBase

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);
    }
}
Also used : ScannerBase(org.apache.accumulo.core.client.ScannerBase) Value(org.apache.accumulo.core.data.Value) TreeMap(java.util.TreeMap) Key(org.apache.accumulo.core.data.Key)

Example 4 with ScannerBase

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();
        }
    }
}
Also used : ClientSideIteratorScanner(org.apache.accumulo.core.client.ClientSideIteratorScanner) Connector(org.apache.accumulo.core.client.Connector) OfflineScanner(org.apache.accumulo.core.client.impl.OfflineScanner) BatchScanner(org.apache.accumulo.core.client.BatchScanner) ClientSideIteratorScanner(org.apache.accumulo.core.client.ClientSideIteratorScanner) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Scanner(org.apache.accumulo.core.client.Scanner) ScannerBase(org.apache.accumulo.core.client.ScannerBase) ArrayList(java.util.ArrayList) BatchScanner(org.apache.accumulo.core.client.BatchScanner) TreeMap(java.util.TreeMap) Range(org.apache.accumulo.core.data.Range) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) NewTableConfiguration(org.apache.accumulo.core.client.admin.NewTableConfiguration) Value(org.apache.accumulo.core.data.Value) BatchWriterConfig(org.apache.accumulo.core.client.BatchWriterConfig) BatchWriter(org.apache.accumulo.core.client.BatchWriter) IsolatedScanner(org.apache.accumulo.core.client.IsolatedScanner) Key(org.apache.accumulo.core.data.Key) Test(org.junit.Test)

Example 5 with ScannerBase

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());
}
Also used : ScannerBase(org.apache.accumulo.core.client.ScannerBase) Text(org.apache.hadoop.io.Text) KeyParts(org.apache.rya.indexing.KeyParts) Range(org.apache.accumulo.core.data.Range) TemporalInterval(org.apache.rya.indexing.TemporalInterval)

Aggregations

ScannerBase (org.apache.accumulo.core.client.ScannerBase)12 Key (org.apache.accumulo.core.data.Key)8 Value (org.apache.accumulo.core.data.Value)8 Range (org.apache.accumulo.core.data.Range)7 Text (org.apache.hadoop.io.Text)4 KeyParts (org.apache.rya.indexing.KeyParts)4 IOException (java.io.IOException)3 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 BatchScanner (org.apache.accumulo.core.client.BatchScanner)3 IteratorSetting (org.apache.accumulo.core.client.IteratorSetting)3 Scanner (org.apache.accumulo.core.client.Scanner)3 Span (org.apache.accumulo.core.trace.Span)3 HashMap (java.util.HashMap)2 BatchWriter (org.apache.accumulo.core.client.BatchWriter)2 BatchWriterConfig (org.apache.accumulo.core.client.BatchWriterConfig)2 ClientSideIteratorScanner (org.apache.accumulo.core.client.ClientSideIteratorScanner)2 Connector (org.apache.accumulo.core.client.Connector)2 IsolatedScanner (org.apache.accumulo.core.client.IsolatedScanner)2 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)2