org.apache.accumulo.core.client.BatchScanner Java Examples
The following examples show how to use
org.apache.accumulo.core.client.BatchScanner.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Query.java From accumulo-examples with Apache License 2.0 | 6 votes |
public static void main(String[] args) throws Exception { QueryOpts opts = new QueryOpts(); opts.parseArgs(Query.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build(); BatchScanner bs = client.createBatchScanner(opts.tableName, Authorizations.EMPTY, 10)) { if (opts.useSample) { SamplerConfiguration samplerConfig = client.tableOperations() .getSamplerConfiguration(opts.tableName); CutoffIntersectingIterator.validateSamplerConfig( client.tableOperations().getSamplerConfiguration(opts.tableName)); bs.setSamplerConfiguration(samplerConfig); } for (String entry : query(bs, opts.terms, opts.sampleCutoff)) { System.out.println(" " + entry); } } }
Example #2
Source File: DiscoveryLogic.java From datawave with Apache License 2.0 | 6 votes |
/** * Takes in a batch scanner and returns an iterator over the DiscoveredThing objects contained in the value. * * @param scanner * @return */ public static Iterator<DiscoveredThing> transformScanner(final BatchScanner scanner) { return concat(transform(scanner.iterator(), new Function<Entry<Key,Value>,Iterator<DiscoveredThing>>() { DataInputBuffer in = new DataInputBuffer(); @Override public Iterator<DiscoveredThing> apply(Entry<Key,Value> from) { Value value = from.getValue(); in.reset(value.get(), value.getSize()); ArrayWritable aw = new ArrayWritable(DiscoveredThing.class); try { aw.readFields(in); } catch (IOException e) { log.error(e); return null; } ArrayList<DiscoveredThing> thangs = Lists.newArrayListWithCapacity(aw.get().length); for (Writable w : aw.get()) { thangs.add((DiscoveredThing) w); } return thangs.iterator(); } })); }
Example #3
Source File: IndexStatsClient.java From datawave with Apache License 2.0 | 6 votes |
public Map<String,Double> getStat(Set<String> fields, Set<String> dataTypes, SortedSet<String> dates) throws IOException { final ScannerBase scanner; try { Authorizations auths = con.securityOperations().getUserAuthorizations(con.whoami()); if (fields.isEmpty()) { scanner = con.createScanner(table, auths); } else { BatchScanner bScanner = con.createBatchScanner(table, auths, fields.size()); bScanner.setRanges(buildRanges(fields)); scanner = bScanner; } } catch (Exception e) { log.error(e); throw new IOException(e); } configureScanIterators(scanner, dataTypes, dates); Map<String,Double> results = scanResults(scanner); if (scanner instanceof BatchScanner) { scanner.close(); } return results; }
Example #4
Source File: AccumuloFeatureStore.java From accumulo-recipes with Apache License 2.0 | 6 votes |
@Override public Iterable<String> types(String group, String prefix, Auths auths) { checkNotNull(group); checkNotNull(prefix); checkNotNull(auths); try { BatchScanner scanner = connector.createBatchScanner(tableName + INDEX_SUFFIX, auths.getAuths(), config.getMaxQueryThreads()); scanner.setRanges(singleton(Range.prefix(group + NULL_BYTE + prefix))); IteratorSetting setting = new IteratorSetting(25, TypeIndexIterator.class); scanner.addScanIterator(setting); return transform(wrap(scanner), typeIndexTransform); } catch (TableNotFoundException e) { throw new RuntimeException(e); } }
Example #5
Source File: EntityInputFormat.java From accumulo-recipes with Apache License 2.0 | 6 votes |
public static void setQueryInfo(Job job, Set<String> entityTypes, Node query, EntityShardBuilder shardBuilder, TypeRegistry<String> typeRegistry) throws AccumuloSecurityException, AccumuloException, TableNotFoundException, IOException { validateOptions(job); checkNotNull(shardBuilder); checkNotNull(query); checkNotNull(entityTypes); checkNotNull(typeRegistry); Instance instance = getInstance(job); Connector connector = instance.getConnector(getPrincipal(job), getAuthenticationToken(job)); BatchScanner scanner = connector.createBatchScanner(DEFAULT_IDX_TABLE_NAME, getScanAuthorizations(job), 5); GlobalIndexVisitor globalIndexVisitor = new EntityGlobalIndexVisitor(scanner, shardBuilder, entityTypes); configureScanner(job, entityTypes, query, new NodeToJexl(typeRegistry), globalIndexVisitor, typeRegistry, OptimizedQueryIterator.class); job.getConfiguration().setBoolean(QUERY, true); job.getConfiguration().set(TYPE_REGISTRY, new String(toBase64(typeRegistry))); }
Example #6
Source File: AccumuloChangelogStore.java From accumulo-recipes with Apache License 2.0 | 6 votes |
/** * Gets the actual change objects that live inside of the specified buckets * * @param buckets dates representing time increments (i.e. 15 minutes) * @return */ @Override public CloseableIterable<Event> getChanges(Iterable<Date> buckets, Auths auths) { checkNotNull(buckets); checkNotNull(auths); try { final BatchScanner scanner = connector.createBatchScanner(tableName, auths.getAuths(), config.getMaxQueryThreads()); List<Range> ranges = new ArrayList<Range>(); for (Date date : buckets) { Range range = new Range(String.format("%d", truncatedReverseTimestamp(date.getTime(), bucketSize))); ranges.add(range); } scanner.setRanges(ranges); return transform(closeableIterable(scanner), entityTransform); } catch (TableNotFoundException e) { throw new RuntimeException(e); } }
Example #7
Source File: AccumuloFeatureStore.java From accumulo-recipes with Apache License 2.0 | 6 votes |
@Override public Iterable<String> names(String group, String type, String prefix, Auths auths) { checkNotNull(group); checkNotNull(type); checkNotNull(prefix); checkNotNull(auths); try { BatchScanner scanner = connector.createBatchScanner(tableName + INDEX_SUFFIX, auths.getAuths(), config.getMaxQueryThreads()); scanner.setRanges(singleton(Range.prefix(group + NULL_BYTE + type + NULL_BYTE + prefix))); IteratorSetting setting = new IteratorSetting(25, FirstEntryInRowIterator.class); scanner.addScanIterator(setting); return transform(wrap(scanner), groupTypeNameIndexTransform); } catch (TableNotFoundException e) { throw new RuntimeException(e); } }
Example #8
Source File: AccumuloFeatureStore.java From accumulo-recipes with Apache License 2.0 | 6 votes |
@Override public Iterable<String> groups(String prefix, Auths auths) { checkNotNull(prefix); checkNotNull(auths); try { BatchScanner scanner = connector.createBatchScanner(tableName + INDEX_SUFFIX, auths.getAuths(), config.getMaxQueryThreads()); scanner.setRanges(singleton(Range.prefix(prefix))); IteratorSetting setting = new IteratorSetting(25, GroupIndexIterator.class); scanner.addScanIterator(setting); return transform(wrap(scanner), groupIndexTransform); } catch (TableNotFoundException e) { throw new RuntimeException(e); } }
Example #9
Source File: AccumuloFeatureStore.java From accumulo-recipes with Apache License 2.0 | 6 votes |
protected ScannerBase metricScanner(AccumuloFeatureConfig xform, Date start, Date end, String group, Iterable<String> types, String name, TimeUnit timeUnit, Auths auths) { checkNotNull(xform); try { group = defaultString(group); timeUnit = (timeUnit == null ? TimeUnit.MINUTES : timeUnit); BatchScanner scanner = connector.createBatchScanner(tableName + REVERSE_SUFFIX, auths.getAuths(), config.getMaxQueryThreads()); Collection<Range> typeRanges = new ArrayList(); for (String type : types) typeRanges.add(buildRange(type, start, end, timeUnit)); scanner.setRanges(typeRanges); scanner.fetchColumn(new Text(combine(timeUnit.toString(), xform.featureName())), new Text(combine(group, name))); return scanner; } catch (TableNotFoundException e) { throw new RuntimeException(e); } }
Example #10
Source File: KeyValueIndex.java From accumulo-recipes with Apache License 2.0 | 6 votes |
/** * Returns all the unique event types in the event store. * @param auths * @return */ public CloseableIterable<String> getTypes(String prefix, Auths auths) { checkNotNull(auths); try { BatchScanner scanner = connector.createBatchScanner(indexTable, auths.getAuths(), config.getMaxQueryThreads()); IteratorSetting setting = new IteratorSetting(15, GlobalIndexTypesIterator.class); scanner.addScanIterator(setting); scanner.setRanges(singletonList(new Range(INDEX_T + INDEX_SEP + prefix, INDEX_T + INDEX_SEP + prefix + "\uffff"))); return transform(closeableIterable(scanner), new Function<Map.Entry<Key, Value>, String>() { @Override public String apply(Map.Entry<Key, Value> keyValueEntry) { String[] parts = splitByWholeSeparatorPreserveAllTokens(keyValueEntry.getKey().getRow().toString(), INDEX_SEP); return splitPreserveAllTokens(parts[1], NULL_BYTE)[0]; } }); } catch (Exception e) { throw new RuntimeException(e); } }
Example #11
Source File: Scanners.java From accumulo-recipes with Apache License 2.0 | 6 votes |
/** * Converts a {@link ScannerBase} into a {@link CloseableIterable} */ public static CloseableIterable<Entry<Key, Value>> closeableIterable(final ScannerBase scanner) { checkNotNull(scanner); return new FluentCloseableIterable<Entry<Key, Value>>() { @Override protected void doClose() throws IOException { if (scanner instanceof BatchScanner) ((BatchScanner) scanner).close(); } @Override protected Iterator<Entry<Key, Value>> retrieveIterator() { return scanner.iterator(); } }; }
Example #12
Source File: ContentQueryTable.java From datawave with Apache License 2.0 | 6 votes |
@Override public void setupQuery(GenericQueryConfiguration genericConfig) throws Exception { if (!genericConfig.getClass().getName().equals(ContentQueryConfiguration.class.getName())) { throw new QueryException("Did not receive a ContentQueryConfiguration instance!!"); } final ContentQueryConfiguration config = (ContentQueryConfiguration) genericConfig; try { final BatchScanner scanner = this.scannerFactory .newScanner(config.getTableName(), config.getAuthorizations(), this.queryThreads, config.getQuery()); scanner.setRanges(config.getRanges()); if (null != this.viewName) { final IteratorSetting cfg = new IteratorSetting(50, RegExFilter.class); cfg.addOption(RegExFilter.COLQ_REGEX, this.viewName); scanner.addScanIterator(cfg); } this.iterator = scanner.iterator(); this.scanner = scanner; } catch (TableNotFoundException e) { throw new RuntimeException("Table not found: " + this.getTableName(), e); } }
Example #13
Source File: ShardQueryLogic.java From datawave with Apache License 2.0 | 6 votes |
public static BatchScanner createBatchScanner(ShardQueryConfiguration config, ScannerFactory scannerFactory, QueryData qd) throws TableNotFoundException { final BatchScanner bs = scannerFactory.newScanner(config.getShardTableName(), config.getAuthorizations(), config.getNumQueryThreads(), config.getQuery()); if (log.isTraceEnabled()) { log.trace("Running with " + config.getAuthorizations() + " and " + config.getNumQueryThreads() + " threads: " + qd); } bs.setRanges(qd.getRanges()); for (IteratorSetting cfg : qd.getSettings()) { bs.addScanIterator(cfg); } return bs; }
Example #14
Source File: PCJKeyToJoinBindingSetIterator.java From rya with Apache License 2.0 | 6 votes |
public PCJKeyToJoinBindingSetIterator(BatchScanner scanner, Map<String, String> pcjVarMap, Map<String, Value> constantConstraints, int maxPrefixLen) { Preconditions.checkNotNull(scanner); Preconditions.checkArgument(pcjVarMap.size() > 0, "Variable map must contain at least one variable!"); Preconditions.checkNotNull(constantConstraints, "Constant constraints cannot be null."); Preconditions.checkArgument(maxPrefixLen > 0, "Max prefix length must be greater than 0."); Preconditions .checkArgument(maxPrefixLen <= pcjVarMap.size(), "Max prefix length must be less than total number of binding names."); this.scanner = scanner; this.pcjVarMap = HashBiMap.create(pcjVarMap).inverse(); this.constantConstraints = constantConstraints; this.maxPrefixLen = maxPrefixLen; this.iterator = scanner.iterator(); }
Example #15
Source File: AccumuloCounterSource.java From datawave with Apache License 2.0 | 6 votes |
@Override public boolean hasNext() { if (null == iterator) { try { BatchScanner scanner = connector.createBatchScanner(queryTable, connector.securityOperations().getUserAuthorizations(username), 100); scanner.setRanges(ranges); for (String cf : cfs) { scanner.fetchColumnFamily(new Text(cf)); } iterator = scanner.iterator(); } catch (TableNotFoundException | AccumuloException | AccumuloSecurityException e) { throw new RuntimeException(e); } } nextIterator(); return null != topKey; }
Example #16
Source File: AccumuloCacheStore.java From datawave with Apache License 2.0 | 6 votes |
@Override public int size() { try (BatchScanner batchScanner = connector.createBatchScanner(tableName, authorizations, 5)) { batchScanner.setRanges(Collections.singleton(new Range())); try { int rows = 0; for (Iterator<Map.Entry<Key,Value>> it = batchScanner.iterator(); it.hasNext(); it.next()) { rows++; } return rows; } finally { batchScanner.close(); } } catch (TableNotFoundException e) { throw new PersistenceException("Unable to calculate size of Accumulo cache table " + tableName, e); } }
Example #17
Source File: ColumnCardinalityCache.java From presto with Apache License 2.0 | 6 votes |
/** * Loads the cardinality for the given Range. Uses a BatchScanner and sums the cardinality for all values that encapsulate the Range. * * @param key Range to get the cardinality for * @return The cardinality of the column, which would be zero if the value does not exist */ @Override public Long load(CacheKey key) throws Exception { LOG.debug("Loading a non-exact range from Accumulo: %s", key); // Get metrics table name and the column family for the scanner String metricsTable = getMetricsTableName(key.getSchema(), key.getTable()); Text columnFamily = new Text(getIndexColumnFamily(key.getFamily().getBytes(UTF_8), key.getQualifier().getBytes(UTF_8)).array()); // Create scanner for querying the range BatchScanner scanner = connector.createBatchScanner(metricsTable, key.auths, 10); scanner.setRanges(connector.tableOperations().splitRangeByTablets(metricsTable, key.range, Integer.MAX_VALUE)); scanner.fetchColumn(columnFamily, CARDINALITY_CQ_AS_TEXT); try { return stream(scanner) .map(Entry::getValue) .map(Value::toString) .mapToLong(Long::parseLong) .sum(); } finally { scanner.close(); } }
Example #18
Source File: ParallelSnapshotScanner.java From fluo with Apache License 2.0 | 5 votes |
private BatchScanner setupBatchScanner() { BatchScanner scanner; try { // TODO hardcoded number of threads! // one thread is probably good.. going for throughput scanner = env.getAccumuloClient().createBatchScanner(env.getTable(), env.getAuthorizations(), 1); } catch (TableNotFoundException e) { throw new RuntimeException(e); } scanner.clearColumns(); scanner.clearScanIterators(); if (!rangesToScan.isEmpty()) { scanner.setRanges(rangesToScan); SnapshotScanner.setupScanner(scanner, Collections.<Column>emptySet(), startTs, true); } 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, true); } else { return null; } return scanner; }
Example #19
Source File: LockResolver.java From fluo with Apache License 2.0 | 5 votes |
static List<Entry<Key, Value>> getOpenReadLocks(Environment env, Map<Bytes, Set<Column>> rowColsToCheck) throws Exception { List<Range> ranges = new ArrayList<>(); for (Entry<Bytes, Set<Column>> e1 : rowColsToCheck.entrySet()) { for (Column col : e1.getValue()) { Key start = SpanUtil.toKey(new RowColumn(e1.getKey(), col)); Key end = new Key(start); end.setTimestamp(ColumnType.LOCK.first()); ranges.add(new Range(start, true, end, false)); } } try (BatchScanner bscanner = env.getAccumuloClient().createBatchScanner(env.getTable(), env.getAuthorizations(), 1)) { bscanner.setRanges(ranges); IteratorSetting iterCfg = new IteratorSetting(10, OpenReadLockIterator.class); bscanner.addScanIterator(iterCfg); List<Entry<Key, Value>> ret = new ArrayList<>(); for (Entry<Key, Value> entry : bscanner) { if (ColumnType.from(entry.getKey()) == ColumnType.RLOCK) { ret.add(entry); } } return ret; } }
Example #20
Source File: ParallelSnapshotScanner.java From fluo with Apache License 2.0 | 5 votes |
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 = rowConverter.apply(entry.getKey().getRowData()); Column col = columnConverter.apply(entry.getKey()); ColumnType colType = ColumnType.from(entry.getKey()); switch (colType) { case LOCK: locks.add(entry); writeLocksSeen.accept(entry); break; case DATA: ret.computeIfAbsent(row, k -> new HashMap<>()).put(col, Bytes.of(entry.getValue().get())); break; case RLOCK: readLocksSeen.computeIfAbsent(row, k -> new HashSet<>()).add(col); break; default: throw new IllegalArgumentException("Unexpected column type " + colType); } } } finally { bs.close(); } }
Example #21
Source File: KeyValueIndex.java From accumulo-recipes with Apache License 2.0 | 5 votes |
/** * Returns all the unique keys for the given event type for the given prefix. Unique key is defined as a unique key + data type alias * @param connector * @param indexTable * @param prefix * @param type * @param maxQueryThreads * @param auths * @return */ public static CloseableIterable<Pair<String,String>> uniqueKeys(Connector connector, String indexTable, String prefix, String type, int maxQueryThreads, Auths auths) { checkNotNull(prefix); checkNotNull(auths); try { BatchScanner scanner = connector.createBatchScanner(indexTable, auths.getAuths(), maxQueryThreads); IteratorSetting setting = new IteratorSetting(15, GlobalIndexUniqueKeyValueIterator.class); scanner.addScanIterator(setting); scanner.setRanges(singletonList( new Range(INDEX_K + INDEX_SEP + type + INDEX_SEP + prefix + Constants.NULL_BYTE, INDEX_K + INDEX_SEP + type + INDEX_SEP + prefix + END_BYTE)) ); return transform(closeableIterable(scanner), new Function<Map.Entry<Key, Value>, Pair<String, String>>() { @Override public Pair<String, String> apply(Map.Entry<Key, Value> keyValueEntry) { AttributeIndexKey key = new AttributeIndexKey(keyValueEntry.getKey()); return new Pair(key.getKey(), key.getAlias()); } }); } catch (Exception e) { throw new RuntimeException(e); } }
Example #22
Source File: AccumuloTemporalIndexer.java From rya with Apache License 2.0 | 5 votes |
public ScannerBase doQuery(final TemporalInstant queryInstant, final StatementConstraints constraints) throws QueryEvaluationException { // key is contraintPrefix + time, or just time. // Any constraints handled here, if the constraints are empty, the // thisKeyParts.contraintPrefix will be null. final List<KeyParts> keyParts = KeyParts.keyPartsForQuery(queryInstant, constraints); ScannerBase scanner = null; if (keyParts.size() > 1) { scanner = getBatchScanner(); } else { scanner = getScanner(); } final Collection<Range> ranges = new HashSet<Range>(); KeyParts lastKeyParts = null; Range range = null; for (final KeyParts thisKeyParts : keyParts) { range = getRange(thisKeyParts); ranges.add(range); lastKeyParts = thisKeyParts; } if (lastKeyParts == null || scanner == null) { throw new NullPointerException("lastkeyParts or scanner is null, impossible! keyParts.size()= " + keyParts.size() + " scanner= " + scanner); } //System.out.println("Scanning columns, cf:" + lastKeyParts.cf + "CQ:" + lastKeyParts.cq); scanner.fetchColumn(new Text(lastKeyParts.cf), new Text(lastKeyParts.cq)); if (scanner instanceof BatchScanner) { ((BatchScanner) scanner).setRanges(ranges); } else if (range != null) { ((Scanner) scanner).setRange(range); } return scanner; }
Example #23
Source File: ConfigUtils.java From rya with Apache License 2.0 | 5 votes |
public static BatchScanner createBatchScanner(final String tablename, final Configuration conf) throws AccumuloException, AccumuloSecurityException, TableNotFoundException { final Connector connector = ConfigUtils.getConnector(conf); final Authorizations auths = ConfigUtils.getAuthorizations(conf); Integer numThreads = null; if (conf instanceof RdfCloudTripleStoreConfiguration) { numThreads = ((RdfCloudTripleStoreConfiguration) conf).getNumThreads(); } else { numThreads = conf.getInt(RdfCloudTripleStoreConfiguration.CONF_NUM_THREADS, 2); } return connector.createBatchScanner(tablename, auths, numThreads); }
Example #24
Source File: AccumuloEntityStore.java From accumulo-recipes with Apache License 2.0 | 5 votes |
@Override public CloseableIterable<Entity> get(Collection<EntityIdentifier> typesAndIds, Set<String> selectFields, Auths auths) { checkNotNull(typesAndIds); checkNotNull(auths); try { BatchScanner scanner = helper.buildShardScanner(auths.getAuths()); Collection<Range> ranges = new LinkedList<Range>(); for (EntityIdentifier curIndex : typesAndIds) { String shardId = shardBuilder.buildShard(curIndex.getType(), curIndex.getId()); ranges.add(exact(shardId, PREFIX_E + ONE_BYTE + curIndex.getType() + ONE_BYTE + curIndex.getId())); } scanner.setRanges(ranges); if (selectFields != null && selectFields.size() > 0) { IteratorSetting iteratorSetting = new IteratorSetting(16, SelectFieldsExtractor.class); SelectFieldsExtractor.setSelectFields(iteratorSetting, selectFields); scanner.addScanIterator(iteratorSetting); } IteratorSetting expirationFilter = new IteratorSetting(7, "metaExpiration", MetadataExpirationFilter.class); scanner.addScanIterator(expirationFilter); IteratorSetting setting = new IteratorSetting(18, WholeColumnFamilyIterator.class); scanner.addScanIterator(setting); return transform(closeableIterable(scanner), helper.buildWholeColFXform()); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new RuntimeException(e); } }
Example #25
Source File: AccumuloEntityStore.java From accumulo-recipes with Apache License 2.0 | 5 votes |
@Override public CloseableIterable<Entity> getAllByType(Set<String> types, Set<String> selectFields, Auths auths) { checkNotNull(types); checkNotNull(auths); try { BatchScanner scanner = helper.buildShardScanner(auths.getAuths()); Collection<Range> ranges = new LinkedList<Range>(); for (String type : types) { Set<Text> shards = shardBuilder.buildShardsForTypes(singleton(type)); for (Text shard : shards) ranges.add(prefix(shard.toString(), PREFIX_E + ONE_BYTE + type)); } scanner.setRanges(ranges); if (selectFields != null && selectFields.size() > 0) { IteratorSetting iteratorSetting = new IteratorSetting(16, SelectFieldsExtractor.class); SelectFieldsExtractor.setSelectFields(iteratorSetting, selectFields); scanner.addScanIterator(iteratorSetting); } IteratorSetting expirationFilter = new IteratorSetting(7, "metaExpiration", MetadataExpirationFilter.class); scanner.addScanIterator(expirationFilter); IteratorSetting setting = new IteratorSetting(18, WholeColumnFamilyIterator.class); scanner.addScanIterator(setting); return transform(closeableIterable(scanner), helper.buildWholeColFXform()); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new RuntimeException(e); } }
Example #26
Source File: AccumuloGraphLogger.java From vertexium with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public void logStartIterator(String table, ScannerBase scanner) { if (!queryLogger.isTraceEnabled()) { return; } SortedSet<Column> fetchedColumns = null; if (scanner instanceof ScannerOptions) { fetchedColumns = ((ScannerOptions) scanner).getFetchedColumns(); } if (scanner instanceof BatchScanner) { try { Field rangesField = scanner.getClass().getDeclaredField("ranges"); rangesField.setAccessible(true); ArrayList<Range> ranges = (ArrayList<Range>) rangesField.get(scanner); if (ranges.size() == 0) { logStartIterator(table, (Range) null, fetchedColumns); } else if (ranges.size() == 1) { logStartIterator(table, ranges.iterator().next(), fetchedColumns); } else { logStartIterator(table, ranges, fetchedColumns); } } catch (Exception e) { queryLogger.trace("Could not get ranges from BatchScanner", e); } } else if (scanner instanceof Scanner) { Range range = ((Scanner) scanner).getRange(); logStartIterator(table, range, fetchedColumns); } else { queryLogger.trace("begin accumulo iterator: %s", scanner.getClass().getName()); } }
Example #27
Source File: EventGlobalIndexVisitor.java From accumulo-recipes with Apache License 2.0 | 5 votes |
public EventGlobalIndexVisitor(Date start, Date end, Set<String> types, BatchScanner indexScanner, EventShardBuilder shardBuilder) { this.start = start; this.end = end; this.indexScanner = indexScanner; this.shardBuilder = shardBuilder; this.types = types; }
Example #28
Source File: AccumuloEventStore.java From accumulo-recipes with Apache License 2.0 | 5 votes |
/** * This method will batch get a bunch of events by uuid (and optionally timestamp). If another store is used to * index into events in this store in a specially designed way (i.e. getting the last-n events, etc...) then * the most optimal way to store the index would be the UUID and the timestamp. However, if all that is known * about an event is the uuid, this method will do the extra fetch of the timestamp from the index table. */ @Override public CloseableIterable<Event> get(Collection<EventIdentifier> uuids, Set<String> selectFields, Auths auths) { checkNotNull(uuids); checkNotNull(auths); try { BatchScanner eventScanner = helper.buildShardScanner(auths.getAuths()); Collection<Range> eventRanges = new LinkedList<Range>(); for (EventIdentifier curIndex : uuids) { String shardId = shardBuilder.buildShard(EventBuilder.create(curIndex.getType(), curIndex.getId(), curIndex.getTimestamp()).build()); eventRanges.add(prefix(shardId, PREFIX_E + ONE_BYTE + curIndex.getType() + ONE_BYTE + curIndex.getId())); } eventScanner.setRanges(eventRanges); if (selectFields != null && selectFields.size() > 0) { IteratorSetting iteratorSetting = new IteratorSetting(25, SelectFieldsExtractor.class); SelectFieldsExtractor.setSelectFields(iteratorSetting, selectFields); eventScanner.addScanIterator(iteratorSetting); } IteratorSetting expirationFilter = new IteratorSetting(23, "metaExpiration", MetadataExpirationFilter.class); eventScanner.addScanIterator(expirationFilter); IteratorSetting setting = new IteratorSetting(26, WholeColumnFamilyIterator.class); eventScanner.addScanIterator(setting); return transform(closeableIterable(eventScanner), helper.buildWholeColFXform()); } catch (RuntimeException re) { throw re; } catch (Exception e) { throw new RuntimeException(e); } }
Example #29
Source File: ContinuousQuery.java From accumulo-examples with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { Opts opts = new Opts(); opts.parseArgs(ContinuousQuery.class.getName(), args); try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build()) { ArrayList<Text[]> randTerms = findRandomTerms( client.createScanner(opts.doc2Term, Authorizations.EMPTY), opts.numTerms); Random rand = new Random(); try (BatchScanner bs = client.createBatchScanner(opts.tableName, Authorizations.EMPTY, 5)) { for (long i = 0; i < opts.iterations; i += 1) { Text[] columns = randTerms.get(rand.nextInt(randTerms.size())); bs.clearScanIterators(); bs.clearColumns(); IteratorSetting ii = new IteratorSetting(20, "ii", IntersectingIterator.class); IntersectingIterator.setColumnFamilies(ii, columns); bs.addScanIterator(ii); bs.setRanges(Collections.singleton(new Range())); long t1 = System.currentTimeMillis(); int count = Iterators.size(bs.iterator()); long t2 = System.currentTimeMillis(); System.out.printf(" %s %,d %6.3f%n", Arrays.asList(columns), count, (t2 - t1) / 1000.0); } } } }
Example #30
Source File: ExamplesIT.java From accumulo-examples with Apache License 2.0 | 5 votes |
@Test public void testShardedIndex() throws Exception { File src = new File(System.getProperty("user.dir") + "/src"); assumeTrue(src.exists()); String[] names = getUniqueNames(3); final String shard = names[0], index = names[1]; c.tableOperations().create(shard); c.tableOperations().create(index); bw = c.createBatchWriter(shard, bwc); Index.index(30, src, "\\W+", bw); bw.close(); BatchScanner bs = c.createBatchScanner(shard, Authorizations.EMPTY, 4); List<String> found = Query.query(bs, Arrays.asList("foo", "bar"), null); bs.close(); // should find ourselves boolean thisFile = false; for (String file : found) { if (file.endsWith("/ExamplesIT.java")) thisFile = true; } assertTrue(thisFile); String[] args = new String[] {"-c", getClientPropsFile(), "--shardTable", shard, "--doc2Term", index}; // create a reverse index goodExec(Reverse.class, args); args = new String[] {"-c", getClientPropsFile(), "--shardTable", shard, "--doc2Term", index, "--terms", "5", "--count", "1000"}; // run some queries goodExec(ContinuousQuery.class, args); }