Here are the examples of the java api class org.apache.accumulo.core.client.BatchScanner taken from open source projects.
1. AccumuloRetriever#getScanner()
Project: Gaffer
File: AccumuloRetriever.java
File: AccumuloRetriever.java
/** * Create a scanner to use used in your query. * <p> * * @param ranges the ranges to get the scanner for * @return A {@link org.apache.accumulo.core.client.BatchScanner} for the * table specified in the properties with the ranges provided. * @throws TableNotFoundException if an accumulo table could not be found * @throws StoreException if a connection to accumulo could not be created. */ protected BatchScanner getScanner(final Set<Range> ranges) throws TableNotFoundException, StoreException { final BatchScanner scanner = store.getConnection().createBatchScanner(store.getProperties().getTable(), authorisations, store.getProperties().getThreadsForBatchScanner()); if (iteratorSettings != null) { for (final IteratorSetting iteratorSetting : iteratorSettings) { if (iteratorSetting != null) { scanner.addScanIterator(iteratorSetting); } } } scanner.setRanges(Range.mergeOverlapping(ranges)); if (IncludeEdgeType.NONE != operation.getIncludeEdges()) { for (final String col : operation.getView().getEdgeGroups()) { scanner.fetchColumnFamily(new Text(col)); } } if (operation.isIncludeEntities()) { for (final String col : operation.getView().getEntityGroups()) { scanner.fetchColumnFamily(new Text(col)); } } return scanner; }
2. TableUtils#getStoreConstructorInfo()
Project: Gaffer
File: TableUtils.java
File: TableUtils.java
/** * Returns the map containing all the information needed to create a new * instance of the accumulo gaffer.accumulostore * <p> * * @param properties the accumulo properties * @return A MapWritable containing all the required information to * construct an accumulo gaffer.accumulostore instance * @throws StoreException if a table could not be found or other table issues */ public static MapWritable getStoreConstructorInfo(final AccumuloProperties properties) throws StoreException { final Connector connection = getConnector(properties.getInstanceName(), properties.getZookeepers(), properties.getUserName(), properties.getPassword()); BatchScanner scanner; try { scanner = connection.createBatchScanner(AccumuloStoreConstants.GAFFER_UTILS_TABLE, getCurrentAuthorizations(connection), properties.getThreadsForBatchScanner()); } catch (final TableNotFoundException e) { throw new StoreException(e.getMessage(), e); } scanner.setRanges(Collections.singleton(getTableSetupRange(properties.getTable()))); final Iterator<Entry<Key, Value>> iter = scanner.iterator(); if (iter.hasNext()) { return getSchemasFromValue(iter.next().getValue()); } else { return null; } }
3. ParallelSnapshotScanner#setupBatchScanner()
Project: incubator-fluo
File: ParallelSnapshotScanner.java
File: ParallelSnapshotScanner.java
private BatchScanner setupBatchScanner() { BatchScanner scanner; try { // TODO hardcoded number of threads! // one thread is probably good.. going for throughput scanner = env.getConnector().createBatchScanner(env.getTable(), env.getAuthorizations(), 1); } catch (TableNotFoundException e) { throw new RuntimeException(e); } scanner.clearColumns(); scanner.clearScanIterators(); if (rangesToScan.size() > 0) { scanner.setRanges(rangesToScan); SnapshotScanner.setupScanner(scanner, Collections.<Column>emptySet(), startTs); } else if (rows != null) { List<Range> ranges = new ArrayList<>(rows.size()); for (Bytes row : rows) { ranges.add(Range.exact(ByteUtil.toText(row))); } scanner.setRanges(ranges); SnapshotScanner.setupScanner(scanner, columns, startTs); } else { return null; } return scanner; }
4. EntityLocalityGroupSetter#getPredicates()
Project: incubator-rya
File: EntityLocalityGroupSetter.java
File: EntityLocalityGroupSetter.java
private Iterator<String> getPredicates() { String auths = conf.get(ConfigUtils.CLOUDBASE_AUTHS); BatchScanner bs = null; try { bs = conn.createBatchScanner(tablePrefix + "prospects", new Authorizations(auths), 10); } catch (TableNotFoundException e) { e.printStackTrace(); } bs.setRanges(Collections.singleton(Range.prefix(new Text("predicate" + "")))); final Iterator<Entry<Key, Value>> iter = bs.iterator(); return new Iterator<String>() { private String next = null; private boolean hasNextCalled = false; private boolean isEmpty = false; @Override public boolean hasNext() { if (!hasNextCalled && !isEmpty) { while (iter.hasNext()) { Entry<Key, Value> temp = iter.next(); String row = temp.getKey().getRow().toString(); String[] rowArray = row.split(""); next = rowArray[1]; hasNextCalled = true; return true; } isEmpty = true; return false; } else if (isEmpty) { return false; } else { return true; } } @Override public String next() { if (hasNextCalled) { hasNextCalled = false; return next; } else if (isEmpty) { throw new NoSuchElementException(); } else { if (this.hasNext()) { hasNextCalled = false; return next; } else { throw new NoSuchElementException(); } } } @Override public void remove() { throw new UnsupportedOperationException("Cannot delete from iterator!"); } }; }
5. AbstractAccumuloPersistence#getScanner()
Project: geowave
File: AbstractAccumuloPersistence.java
File: AbstractAccumuloPersistence.java
protected BatchScanner getScanner(final ByteArrayId primaryId, final ByteArrayId secondaryId, final String... authorizations) throws TableNotFoundException { final BatchScanner scanner = accumuloOperations.createBatchScanner(getAccumuloTablename(), authorizations); final IteratorSetting[] settings = getScanSettings(); if ((settings != null) && (settings.length > 0)) { for (final IteratorSetting setting : settings) { scanner.addScanIterator(setting); } } final String columnFamily = getAccumuloColumnFamily(); final String columnQualifier = getAccumuloColumnQualifier(secondaryId); if (columnFamily != null) { if (columnQualifier != null) { scanner.fetchColumn(new Text(columnFamily), new Text(columnQualifier)); } else { scanner.fetchColumnFamily(new Text(columnFamily)); } } final Collection<Range> ranges = new ArrayList<Range>(); if (primaryId != null) { ranges.add(new Range(new Text(primaryId.getBytes()))); } else { ranges.add(new Range()); } scanner.setRanges(ranges); return scanner; }
6. ParallelSnapshotScanner#scan()
Project: incubator-fluo
File: ParallelSnapshotScanner.java
File: ParallelSnapshotScanner.java
private void scan(Map<Bytes, Map<Column, Bytes>> ret, List<Entry<Key, Value>> locks) { BatchScanner bs = setupBatchScanner(); try { for (Entry<Key, Value> entry : bs) { Bytes row = ByteUtil.toBytes(entry.getKey().getRowData()); Bytes cf = ByteUtil.toBytes(entry.getKey().getColumnFamilyData()); Bytes cq = ByteUtil.toBytes(entry.getKey().getColumnQualifierData()); Column col = new Column(cf, cq, ByteUtil.toBytes(entry.getKey().getColumnVisibilityData())); long colType = entry.getKey().getTimestamp() & ColumnConstants.PREFIX_MASK; if (colType == ColumnConstants.LOCK_PREFIX) { locks.add(entry); } else if (colType == ColumnConstants.DATA_PREFIX) { Map<Column, Bytes> cols = ret.get(row); if (cols == null) { cols = new HashMap<>(); ret.put(row, cols); } cols.put(col, Bytes.of(entry.getValue().get())); } else { throw new IllegalArgumentException("Unexpected column type " + colType); } } } finally { bs.close(); } }