Java Code Examples for org.apache.accumulo.core.client.BatchScanner#setRanges()

The following examples show how to use org.apache.accumulo.core.client.BatchScanner#setRanges() . 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: ShardQueryLogic.java    From datawave with Apache License 2.0 6 votes vote down vote up
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 2
Source File: KeyValueIndex.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: AccumuloFeatureStore.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: AccumuloFeatureStore.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@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 5
Source File: AccumuloFeatureStore.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@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 6
Source File: AccumuloCounterSource.java    From datawave with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: ContentQueryTable.java    From datawave with Apache License 2.0 6 votes vote down vote up
@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 8
Source File: AccumuloChangelogStore.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
/**
 * 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 9
Source File: IndexStatsClient.java    From datawave with Apache License 2.0 6 votes vote down vote up
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 10
Source File: AccumuloEntityStore.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
@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 11
Source File: IndexStatsQueryLogic.java    From datawave with Apache License 2.0 5 votes vote down vote up
public List<FieldStat> getStat(Set<String> fields, Set<String> dataTypes, SortedSet<String> dates) throws IOException {
    // To allow "fields" to be empty and configure the scanners the same,
    // I have to have to references to the Scanner implementation because
    // ScannerBase does not implement Iterable<Entry<Key, Value>>
    final ScannerBase scanner;
    final Iterable<Entry<Key,Value>> dataSource;
    try {
        Set<Authorizations> auths = Collections.singleton(con.securityOperations().getUserAuthorizations(con.whoami()));
        if (fields.isEmpty()) {
            Scanner simpleScanner = ScannerHelper.createScanner(con, table, auths);
            dataSource = simpleScanner;
            scanner = simpleScanner;
        } else {
            BatchScanner bScanner = ScannerHelper.createBatchScanner(con, table, auths, fields.size());
            bScanner.setRanges(buildRanges(fields));
            scanner = bScanner;
            dataSource = bScanner;
        }
    } catch (Exception e) {
        log.error(e);
        throw new IOException(e);
    }
    
    configureScanIterators(scanner, dataTypes, dates);
    
    List<FieldStat> results = scanResults(dataSource);
    
    if (scanner instanceof BatchScanner) {
        scanner.close();
    }
    
    return results;
}
 
Example 12
Source File: BaseTableCache.java    From datawave with Apache License 2.0 5 votes vote down vote up
public void setupScanner(BatchScanner scanner) {
    scanner.setRanges(Lists.newArrayList(new Range()));
    Map<String,String> options = new HashMap<>();
    options.put(RegExFilter.COLF_REGEX, "^f$");
    options.put("negate", "true");
    IteratorSetting settings = new IteratorSetting(100, "skipFColumn", RegExFilter.class, options);
    scanner.addScanIterator(settings);
}
 
Example 13
Source File: BaseTableWrapper.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
protected BatchScanner getBatchScanner() {
  try {
    BatchScanner scanner = globals.getConfig().getConnector().createBatchScanner(tableName,
        globals.getConfig().getAuthorizations(), globals.getConfig().getQueryThreads());
    scanner.setRanges(Collections.singletonList(new Range()));
    return scanner;
  } catch (Exception e) {
    throw new AccumuloGraphException(e);
  }
}
 
Example 14
Source File: AccumuloOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public CloseableIterator<GeoWaveRow> getDataIndexResults(
    final byte[][] rows,
    final short adapterId,
    final String... additionalAuthorizations) {
  if ((rows == null) || (rows.length == 0)) {
    return new CloseableIterator.Empty<>();
  }
  final byte[] family = StringUtils.stringToBinary(ByteArrayUtils.shortToString(adapterId));

  // to have backwards compatibility before 1.8.0 we can assume BaseScanner is autocloseable
  final BatchScanner batchScanner;
  try {
    batchScanner =
        createBatchScanner(DataIndexUtils.DATA_ID_INDEX.getName(), additionalAuthorizations);
    batchScanner.setRanges(
        Arrays.stream(rows).map(r -> Range.exact(new Text(r))).collect(Collectors.toList()));
    batchScanner.fetchColumnFamily(new Text(family));
    final Map<ByteArray, byte[]> results = new HashMap<>();
    batchScanner.iterator().forEachRemaining(
        entry -> results.put(
            new ByteArray(entry.getKey().getRow().getBytes()),
            entry.getValue().get()));
    return new CloseableIteratorWrapper(new Closeable() {
      @Override
      public void close() throws IOException {
        batchScanner.close();
      }
    },
        Arrays.stream(rows).filter(r -> results.containsKey(new ByteArray(r))).map(
            r -> DataIndexUtils.deserializeDataIndexRow(
                r,
                adapterId,
                results.get(new ByteArray(r)),
                false)).iterator());
  } catch (final TableNotFoundException e) {
    LOGGER.error("unable to find data index table", e);
  }
  return new CloseableIterator.Empty<>();
}
 
Example 15
Source File: AccumuloEntityStore.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
@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 16
Source File: EventInputFormat.java    From accumulo-recipes with Apache License 2.0 4 votes vote down vote up
/**
 * Sets up the job to stream all events between the given start and end times that match the given query.
 * The query is propagated down to the tablet servers through iterators so that data can be scanned
 * close to the disks. This method will allow a custom shard builder and type registry to be used.
 * @param job
 * @param start
 * @param end
 * @param query
 * @throws AccumuloSecurityException
 * @throws AccumuloException
 * @throws TableNotFoundException
 * @throws IOException
 */
public static void setQueryInfo(Job job, Date start, Date end, Set<String> types, Node query, EventShardBuilder shardBuilder, TypeRegistry<String> typeRegistry) throws AccumuloSecurityException, AccumuloException, TableNotFoundException, IOException {

  validateOptions(job);

  job.getConfiguration().set("typeRegistry", new String(toBase64(typeRegistry)));

    Instance instance = getInstance(job);
    Connector connector = instance.getConnector(getPrincipal(job), getAuthenticationToken(job));
    BatchScanner scanner = connector.createBatchScanner(DEFAULT_IDX_TABLE_NAME, getScanAuthorizations(job), 5);

    if(query == null) {


      Set<Range> typeIndexRanges = new HashSet<Range>();
      for(String type : types) {

          Key typeStartKey = new Key("t__" + type + NULL_BYTE + shardBuilder.buildShard(start.getTime(), 0));
          Key typeStopKey = new Key("t__" + type + NULL_BYTE + shardBuilder.buildShard(end.getTime(), shardBuilder.numPartitions()));
          typeIndexRanges.add(new Range(typeStartKey, typeStopKey));
      }
      scanner.setRanges(typeIndexRanges);

      Collection<Range> ranges = new LinkedList<Range>();
      for(Map.Entry<Key,Value> entry : scanner) {
          String[] parts = splitPreserveAllTokens(entry.getKey().getRow().toString(), NULL_BYTE);
          String[] typeParts = splitByWholeSeparatorPreserveAllTokens(parts[0], "__");
          ranges.add(prefix(parts[1], PREFIX_E + ONE_BYTE + typeParts[1] + ONE_BYTE));
      }
      scanner.close();

      job.getConfiguration().set(XFORM_KEY, CF_XFORM);

      setRanges(job, ranges);
      addIterator(job, new IteratorSetting(18, WholeColumnFamilyIterator.class));

    } else {

      GlobalIndexVisitor globalIndexVisitor = new EventGlobalIndexVisitor(start, end, types, scanner, shardBuilder);

      IteratorSetting timeSetting = new IteratorSetting(14, EventTimeLimitingFilter.class);
        EventTimeLimitingFilter.setCurrentTime(timeSetting, end.getTime());
        EventTimeLimitingFilter.setTTL(timeSetting, end.getTime() - start.getTime());
      addIterator(job, timeSetting);


      job.getConfiguration().set(XFORM_KEY, QUERY_XFORM);
      configureScanner(job, types, query, new EventQfdHelper.EventNodeToJexl(typeRegistry), globalIndexVisitor, typeRegistry,
          EventOptimizedQueryIterator.class);
    }

}
 
Example 17
Source File: EdgeQueryLogic.java    From datawave with Apache License 2.0 4 votes vote down vote up
@Override
public void setupQuery(GenericQueryConfiguration configuration) throws Exception {
    config = (EdgeQueryConfiguration) configuration;
    prefilterValues = null;
    EdgeQueryConfiguration.dateType dateFilterType = ((EdgeQueryConfiguration) configuration).getDateRangeType();
    
    log.debug("Performing edge table query: " + config.getQueryString());
    
    boolean includeStats = ((EdgeQueryConfiguration) configuration).includeStats();
    
    String queryString = config.getQueryString();
    String normalizedQuery = null;
    String statsNormalizedQuery = null;
    
    queryString = fixQueryString(queryString);
    QueryData qData = configureRanges(queryString);
    setRanges(qData.getRanges());
    
    VisitationContext context = null;
    try {
        context = normalizeJexlQuery(queryString, false);
        normalizedQuery = context.getNormalizedQuery().toString();
        statsNormalizedQuery = context.getNormalizedStatsQuery().toString();
        log.debug("Jexl after normalizing SOURCE and SINK: " + normalizedQuery);
    } catch (JexlException ex) {
        log.error("Error parsing user query.", ex);
    }
    
    if ((null == normalizedQuery || normalizedQuery.equals("")) && qData.getRanges().size() < 1) {
        throw new IllegalStateException("Query string is empty after initial processing, no ranges or filters can be generated to execute.");
    }
    
    addIterators(qData, getDateBasedIterators(config.getBeginDate(), config.getEndDate(), currentIteratorPriority, dateFilterSkipLimit, dateFilterType));
    
    if (!normalizedQuery.equals("")) {
        log.debug("Query being sent to the filter iterator: " + normalizedQuery);
        IteratorSetting edgeIteratorSetting = new IteratorSetting(currentIteratorPriority, EdgeFilterIterator.class.getSimpleName() + "_"
                        + currentIteratorPriority, EdgeFilterIterator.class);
        edgeIteratorSetting.addOption(EdgeFilterIterator.JEXL_OPTION, normalizedQuery);
        edgeIteratorSetting.addOption(EdgeFilterIterator.PROTOBUF_OPTION, "TRUE");
        
        if (!statsNormalizedQuery.equals("")) {
            edgeIteratorSetting.addOption(EdgeFilterIterator.JEXL_STATS_OPTION, statsNormalizedQuery);
        }
        if (prefilterValues != null) {
            String value = serializePrefilter();
            edgeIteratorSetting.addOption(EdgeFilterIterator.PREFILTER_WHITELIST, value);
        }
        
        if (includeStats) {
            edgeIteratorSetting.addOption(EdgeFilterIterator.INCLUDE_STATS_OPTION, "TRUE");
        } else {
            edgeIteratorSetting.addOption(EdgeFilterIterator.INCLUDE_STATS_OPTION, "FALSE");
        }
        
        addIterator(qData, edgeIteratorSetting);
    }
    
    log.debug("Configuring connection: tableName: " + config.getTableName() + ", auths: " + config.getAuthorizations());
    
    BatchScanner scanner = createBatchScanner(config);
    
    log.debug("Using the following ranges: " + qData.getRanges());
    
    if (context != null && context.isHasAllCompleteColumnFamilies()) {
        for (Text columnFamily : context.getColumnFamilies()) {
            scanner.fetchColumnFamily(columnFamily);
        }
        
    }
    
    scanner.setRanges(qData.getRanges());
    
    addCustomFilters(qData, currentIteratorPriority);
    
    for (IteratorSetting setting : qData.getSettings()) {
        scanner.addScanIterator(setting);
    }
    
    this.scanner = scanner;
    iterator = scanner.iterator();
}
 
Example 18
Source File: DateIndexHelper.java    From datawave with Apache License 2.0 4 votes vote down vote up
/**
 * Get the date type description which includes the fields and the mapped date range.
 * 
 * @param dateType
 * @param begin
 * @param end
 * @param datatypeFilter
 * @return the date type description
 * @throws TableNotFoundException
 */
@Cacheable(value = "getTypeDescription", key = "{#root.target.dateIndexTableName,#root.target.auths,#dateType,#begin,#end,#datatypeFilter}",
                cacheManager = "dateIndexHelperCacheManager")
public DateTypeDescription getTypeDescription(String dateType, Date begin, Date end, Set<String> datatypeFilter) throws TableNotFoundException {
    log.debug("cache fault for getTypeDescription(" + dateIndexTableName + ", " + auths + ", " + dateType + ", " + begin + ", " + end + ", "
                    + datatypeFilter + ")");
    if (log.isTraceEnabled()) {
        this.showMeDaCache("before getTypeDescription");
    }
    long startTime = System.currentTimeMillis();
    
    DateTypeDescription desc = new DateTypeDescription();
    
    BatchScanner bs = ScannerHelper.createBatchScanner(connector, dateIndexTableName, auths, numQueryThreads);
    try {
        
        // scan from begin to end
        bs.setRanges(Arrays.asList(new Range(DateIndexUtil.format(begin), DateIndexUtil.format(end) + '~')));
        
        // restrict to our date type
        bs.fetchColumnFamily(new Text(dateType));
        
        Iterator<Entry<Key,Value>> iterator = bs.iterator();
        
        while (iterator.hasNext()) {
            Entry<Key,Value> entry = iterator.next();
            Key k = entry.getKey();
            
            String[] parts = StringUtils.split(k.getColumnQualifier().toString(), '\0');
            if (datatypeFilter == null || datatypeFilter.isEmpty() || datatypeFilter.contains(parts[1])) {
                desc.fields.add(parts[2]);
                String date = parts[0];
                if (desc.dateRange[0] == null) {
                    desc.dateRange[0] = date;
                    desc.dateRange[1] = date;
                } else {
                    if (date.compareTo(desc.dateRange[0]) < 0) {
                        desc.dateRange[0] = date;
                    }
                    if (date.compareTo(desc.dateRange[1]) > 0) {
                        desc.dateRange[1] = date;
                    }
                }
            }
        }
    } finally {
        bs.close();
    }
    
    // if the dates are still empty, then default to the incoming dates
    if (desc.dateRange[0] == null) {
        desc.dateRange[0] = DateIndexUtil.format(begin);
        desc.dateRange[1] = DateIndexUtil.format(end);
    }
    
    if (log.isDebugEnabled()) {
        long endTime = System.currentTimeMillis();
        log.debug("getTypeDescription from table: " + dateIndexTableName + ", " + auths + ", " + dateType + ", " + begin + ", " + end + ", "
                        + datatypeFilter + " returned " + desc + " in " + (endTime - startTime) + "ms");
    }
    
    return desc;
}
 
Example 19
Source File: AccumuloEventStore.java    From accumulo-recipes with Apache License 2.0 4 votes vote down vote up
@Override
public CloseableIterable<Event> getAllByType(Date start, Date stop, Set<String> types, Set<String> selectFields, Auths auths) {
    checkNotNull(types);
    checkNotNull(auths);
    try {

        BatchScanner scanner = helper.buildShardScanner(auths.getAuths());

        BatchScanner typeShardScanner = helper.buildIndexScanner(auths.getAuths());

        Set<Range> typeIndexRanges = new HashSet<Range>();
        for(String type : types) {

            Key typeStartKey = new Key("t__" + type + NULL_BYTE + shardBuilder.buildShard(start.getTime(), 0));
            Key typeStopKey = new Key("t__" + type + NULL_BYTE + shardBuilder.buildShard(stop.getTime(), shardBuilder.numPartitions()));
            typeIndexRanges.add(new Range(typeStartKey, typeStopKey));
        }
        typeShardScanner.setRanges(typeIndexRanges);

        Collection<Range> ranges = new LinkedList<Range>();
        for(Entry<Key,Value> entry : typeShardScanner) {
            String[] parts = splitPreserveAllTokens(entry.getKey().getRow().toString(), NULL_BYTE);
            String[] typeParts = splitByWholeSeparatorPreserveAllTokens(parts[0], "__");
            ranges.add(prefix(parts[1], PREFIX_E + ONE_BYTE + typeParts[1] + ONE_BYTE));
        }

        scanner.setRanges(ranges);

        if (selectFields != null && selectFields.size() > 0) {
            IteratorSetting iteratorSetting = new IteratorSetting(16, SelectFieldsExtractor.class);
            SelectFieldsExtractor.setSelectFields(iteratorSetting, selectFields);
            scanner.addScanIterator(iteratorSetting);
        }

        IteratorSetting timeFilter = new IteratorSetting(12, EventTimeLimitingFilter.class);
        EventTimeLimitingFilter.setCurrentTime(timeFilter, stop.getTime());

        EventTimeLimitingFilter.setTTL(timeFilter, stop.getTime() - start.getTime());
        scanner.addScanIterator(timeFilter);

        IteratorSetting setting = new IteratorSetting(18, WholeColumnFamilyIterator.class);
        scanner.addScanIterator(setting);

        IteratorSetting expirationFilter = new IteratorSetting(13, "metaExpiration", MetadataExpirationFilter.class);
        scanner.addScanIterator(expirationFilter);

        return transform(closeableIterable(scanner), helper.buildWholeColFXform());
    } catch (RuntimeException re) {
        throw re;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}