Java Code Examples for org.apache.accumulo.core.client.Scanner#setRange()

The following examples show how to use org.apache.accumulo.core.client.Scanner#setRange() . 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: AccumuloRyaDAO.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
public String getNamespace(final String pfx) throws RyaDAOException {
    try {
        final Scanner scanner = connector.createScanner(tableLayoutStrategy.getNs(),
                ALL_AUTHORIZATIONS);
        scanner.fetchColumn(INFO_NAMESPACE_TXT, EMPTY_TEXT);
        scanner.setRange(new Range(new Text(pfx)));
        final Iterator<Map.Entry<Key, Value>> iterator = scanner
                .iterator();

        if (iterator.hasNext()) {
            return new String(iterator.next().getValue().get(), StandardCharsets.UTF_8);
        }
    } catch (final Exception e) {
        throw new RyaDAOException(e);
    }
    return null;
}
 
Example 2
Source File: FirstNEntriesInRowIteratorIT.java    From accumulo-recipes with Apache License 2.0 6 votes vote down vote up
@Test
public void testFirstNEntriesReturned_multipleRowsLotsOfKeys_FetchRowColumn() throws AccumuloSecurityException, AccumuloException, TableExistsException, TableNotFoundException, IOException {

    persistTestMutations(50, 500);

    Scanner scanner = buildScanner(10);
    scanner.setRange(new Range("1"));
    scanner.fetchColumnFamily(new Text("1"));

    assertEquals(1, Iterables.size(scanner));


    for (Map.Entry<Key, Value> entry : scanner) {
        Iterable<Map.Entry<Key, Value>> items = decodeRow(entry.getKey(), entry.getValue());
        assertEquals(1, Iterables.size(items));
    }
}
 
Example 3
Source File: TermFrequencyQueryTable.java    From datawave with Apache License 2.0 6 votes vote down vote up
@Override
public void setupQuery(GenericQueryConfiguration configuration) throws Exception {
    if (!configuration.getClass().getName().equals(TermFrequencyQueryConfiguration.class.getName())) {
        throw new QueryException("Did not receive a TermFrequencyQueryConfiguration instance");
    }
    
    TermFrequencyQueryConfiguration tfConfig = (TermFrequencyQueryConfiguration) configuration;
    
    try {
        Scanner scanner = QueryScannerHelper.createScanner(tfConfig.getConnector(), tfConfig.getTableName(), tfConfig.getAuthorizations(),
                        tfConfig.getQuery());
        scanner.setRange(tfConfig.getRange());
        
        this.iterator = scanner.iterator();
        this.scanner = scanner;
    } catch (TableNotFoundException e) {
        throw new RuntimeException("Table not found: " + this.getTableName(), e);
    }
}
 
Example 4
Source File: ElementTableWrapper.java    From AccumuloGraph with Apache License 2.0 6 votes vote down vote up
/**
 * Read the given properties for the given element.
 * If propertyKeys is null, read all properties.
 * If the element has no properties, return an empty Map.
 * If the element does not exist, return null.
 * @param id
 * @param propertyKeys
 * @return
 */
public Map<String, Object> readProperties(Element element, String[] propertyKeys) {
  Scanner s = getScanner();
  s.setRange(Range.exact((String) element.getId()));

  // If propertyKeys is null, we read everything.
  // Otherwise, limit to the given attributes.
  if (propertyKeys != null) {
    s.fetchColumnFamily(new Text(Constants.LABEL));

    for (String key : propertyKeys) {
      s.fetchColumnFamily(new Text(key));
    }
  }

  Map<String, Object> props = new PropertyParser().parse(s);
  s.close();

  return props;
}
 
Example 5
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * find intervals stored in the repository before the given Interval. Find interval endings that are
 * before the given beginning.
 * Indexing Intervals  will probably change or be removed.
 * Currently predicate and subject constraints are filtered on the client.
 */
@Override
public CloseableIteration<Statement, QueryEvaluationException> queryIntervalBefore(
        final TemporalInterval queryInterval, final StatementConstraints constraints) throws QueryEvaluationException
{
    final Scanner scanner = getScanner();
    if (scanner != null) {
        // get rows where the end date is less than the queryInterval.getBefore()
        final Range range = new Range(null, false, new Key(new Text(queryInterval.getHasBeginning().getAsKeyBytes())), false);
        scanner.setRange(range);
         if (constraints.hasContext()) {
            scanner.fetchColumn(new Text(constraints.getContext().toString()), new Text(KeyParts.CQ_END));
        } else {
            scanner.fetchColumn(new Text(""), new Text(KeyParts.CQ_END));
        }
    }
    return getIteratorWrapper(scanner);
}
 
Example 6
Source File: AccumuloClient.java    From presto with Apache License 2.0 5 votes vote down vote up
private Optional<String> getDefaultTabletLocation(String fulltable)
{
    try {
        String tableId = connector.tableOperations().tableIdMap().get(fulltable);

        // Create a scanner over the metadata table, fetching the 'loc' column of the default tablet row
        Scanner scan = connector.createScanner("accumulo.metadata", connector.securityOperations().getUserAuthorizations(username));
        scan.fetchColumnFamily(new Text("loc"));
        scan.setRange(new Range(tableId + '<'));

        // scan the entry
        Optional<String> location = Optional.empty();
        for (Entry<Key, Value> entry : scan) {
            if (location.isPresent()) {
                throw new PrestoException(FUNCTION_IMPLEMENTATION_ERROR, "Scan for default tablet returned more than one entry");
            }

            location = Optional.of(entry.getValue().toString());
        }

        scan.close();
        return location;
    }
    catch (Exception e) {
        // Swallow this exception so the query does not fail due to being unable to locate the tablet server for the default tablet.
        // This is purely an optimization, but we will want to log the error.
        LOG.error("Failed to get tablet location, returning dummy location", e);
        return Optional.empty();
    }
}
 
Example 7
Source File: AccumuloGeoTableTest.java    From mrgeo with Apache License 2.0 5 votes vote down vote up
@Test
@Category(UnitTest.class)
public void testGetTile() throws Exception
{

  ZooKeeperInstance zkinst = new ZooKeeperInstance(inst, zoo);
  PasswordToken pwTok = new PasswordToken(pw.getBytes());
  Connector conn = zkinst.getConnector(u, pwTok);
  Assert.assertNotNull(conn);

  PasswordToken token = new PasswordToken(pw.getBytes());

  Authorizations auths = new Authorizations(authsStr.split(","));
  long start = 0;
  long end = Long.MAX_VALUE;
  Key sKey = AccumuloUtils.toKey(start);
  Key eKey = AccumuloUtils.toKey(end);
  Range r = new Range(sKey, eKey);
  Scanner s = conn.createScanner("paris4", auths);
  s.fetchColumnFamily(new Text(Integer.toString(10)));
  s.setRange(r);

  Iterator<Entry<Key, Value>> it = s.iterator();
  while (it.hasNext())
  {
    Entry<Key, Value> ent = it.next();
    if (ent == null)
    {
      return;
    }
    System.out.println("current key   = " + AccumuloUtils.toLong(ent.getKey().getRow()));
    System.out.println("current value = " + ent.getValue().getSize());
  }

}
 
Example 8
Source File: AccumuloRdfCountToolTest.java    From rya with Apache License 2.0 5 votes vote down vote up
@Test
public void testTTL() throws Exception {
    RyaIRI test1 = RdfToRyaConversions.convertIRI(VF.createIRI(litdupsNS, "test1"));
    RyaIRI pred1 = RdfToRyaConversions.convertIRI(VF.createIRI(litdupsNS, "pred1"));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(0))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(1))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(2))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(3))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(4))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(5))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(6))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(7))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(8))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(9))));
    dao.add(new RyaStatement(test1, pred1, RdfToRyaConversions.convertLiteral(VF.createLiteral(10))));

    AccumuloRdfCountTool.main(new String[]{
            "-Dac.mock=true",
            "-Dac.instance=" + instance,
            "-Dac.username=" + user,
            "-Dac.pwd=" + pwd,
            "-Dac.ttl=0",
            "-Drdf.tablePrefix=" + tablePrefix,
    });

    Scanner scanner = connector.createScanner(tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX, auths);
    scanner.setRange(new Range());
    int count = 0;
    for (Map.Entry<Key, Value> entry : scanner) {
        count++;
    }
    assertEquals(0, count);
}
 
Example 9
Source File: AccumuloPeriodicQueryResultStorage.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
public CloseableIterator<BindingSet> listResults(final String queryId, final Optional<Long> binId)
        throws PeriodicQueryStorageException {
    requireNonNull(queryId);

    final String tableName = tableNameFactory.makeTableName(ryaInstance, queryId);
    // Fetch the Variable Orders for the binding sets and choose one of
    // them. It
    // doesn't matter which one we choose because they all result in the
    // same output.
    final PeriodicQueryStorageMetadata metadata = getPeriodicQueryMetadata(queryId);
    final VariableOrder varOrder = metadata.getVariableOrder();

    try {
        // Fetch only the Binding Sets whose Variable Order matches the
        // selected one.
        final Scanner scanner = accumuloConn.createScanner(tableName, auths);
        scanner.fetchColumnFamily(new Text(varOrder.toString()));
        if (binId.isPresent()) {
            scanner.setRange(Range.prefix(getRowPrefix(binId.get())));
        }
        return new AccumuloValueBindingSetIterator(scanner);

    } catch (final Exception e) {
        throw new PeriodicQueryStorageException(String.format("PCJ Table does not exist for name '%s'.", tableName), e);
    }
}
 
Example 10
Source File: QueryUtil.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Scans over the index table for files or directories with a given name that can contain a single
 * wildcard '*' anywhere in the term.
 *
 * @param exp
 *          the name a file or directory to search for with one optional wildcard '*'
 */
public Iterable<Entry<Key,Value>> singleWildCardSearch(String exp) throws Exception {
  int starIndex = exp.indexOf("*");
  if (exp.indexOf("*", starIndex + 1) >= 0)
    throw new Exception("only one wild card for search");

  if (starIndex < 0) {
    return exactTermSearch(exp);
  } else if (starIndex == 0 || starIndex == exp.length() - 1) {
    return singleRestrictedWildCardSearch(exp);
  }

  String firstPart = exp.substring(0, starIndex);
  String lastPart = exp.substring(starIndex + 1);
  String regexString = ".*/" + exp.replace("*", "[^/]*");

  Scanner scanner = client.createScanner(tableName, auths);
  if (firstPart.length() >= lastPart.length()) {
    System.out.println("executing middle wildcard search for " + regexString
        + " from entries starting with " + firstPart);
    scanner.setRange(Range.prefix(getForwardIndex(firstPart)));
  } else {
    System.out.println("executing middle wildcard search for " + regexString
        + " from entries ending with " + lastPart);
    scanner.setRange(Range.prefix(getReverseIndex(lastPart)));
  }
  IteratorSetting regex = new IteratorSetting(50, "regex", RegExFilter.class);
  RegExFilter.setRegexs(regex, null, null, regexString, null, false);
  scanner.addScanIterator(regex);
  return scanner;
}
 
Example 11
Source File: Upgrade322ToolTest.java    From rya with Apache License 2.0 5 votes vote down vote up
public void printTableData(String tableName)
  throws TableNotFoundException{
    Scanner scanner = connector.createScanner(tableName, auths);
    scanner.setRange(new Range());
    for(Map.Entry<Key, Value> entry : scanner) {
        final Key key = entry.getKey();
        final Value value = entry.getValue();
        System.out.println(key.getRow() + " " + key.getColumnFamily() + " " + key.getColumnQualifier() + " " + key.getTimestamp() + " " + value.toString());
    }
}
 
Example 12
Source File: AccumuloFeatureStore.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
protected ScannerBase metricScanner(AccumuloFeatureConfig xform, Date start, Date end, String group, String type, String name, TimeUnit timeUnit, Auths auths) {
    checkNotNull(xform);

    try {

        group = defaultString(group);
        timeUnit = (timeUnit == null ? TimeUnit.MINUTES : timeUnit);

        Scanner scanner = connector.createScanner(tableName + REVERSE_SUFFIX, auths.getAuths());
        scanner.setRange(buildRange(type, start, end, timeUnit));

        if (group != null && name != null) {
            scanner.fetchColumn(new Text(combine(timeUnit.toString(), xform.featureName())), new Text(combine(group, name)));
        } else {
            scanner.fetchColumnFamily(new Text(combine(timeUnit.toString(), xform.featureName())));

            String cqRegex = null;
            if (group != null) {
                cqRegex = combine(group, "(.*)");
            } else if (name != null)
                cqRegex = combine("(.*)", name);
            if (cqRegex != null) {
                IteratorSetting regexIterator = new IteratorSetting(Constants.DEFAULT_ITERATOR_PRIORITY - 1, "regex", RegExFilter.class);
                scanner.addScanIterator(regexIterator);
            }
        }

        return scanner;
    } catch (TableNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
Example 13
Source File: AccumuloOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public CloseableIterator<GeoWaveRow> getDataIndexResults(
    final short adapterId,
    final String... additionalAuthorizations) {
  final byte[] family = StringUtils.stringToBinary(ByteArrayUtils.shortToString(adapterId));

  // to have backwards compatibility before 1.8.0 we can assume BaseScanner is autocloseable
  final Scanner scanner;
  try {
    scanner = createScanner(DataIndexUtils.DATA_ID_INDEX.getName(), additionalAuthorizations);
    scanner.setRange(new Range());
    scanner.fetchColumnFamily(new Text(family));
    return new CloseableIteratorWrapper(new Closeable() {
      @Override
      public void close() throws IOException {
        scanner.close();
      }
    },
        Streams.stream(scanner).map(
            entry -> DataIndexUtils.deserializeDataIndexRow(
                entry.getKey().getRow().getBytes(),
                adapterId,
                entry.getValue().get(),
                false)).iterator());
  } catch (final TableNotFoundException e) {
    LOGGER.error("unable to find data index table", e);
  }
  return new CloseableIterator.Empty<>();
}
 
Example 14
Source File: MergeToolMapper.java    From rya with Apache License 2.0 5 votes vote down vote up
private static Scanner setupScanner(final Context context, final String tableName, final Configuration config) throws IOException {
    final RangeInputSplit split = (RangeInputSplit) context.getInputSplit();
    final Range splitRange = split.getRange();
    final Scanner scanner = AccumuloRyaUtils.getScanner(tableName, config);
    scanner.setRange(splitRange);

    return scanner;
}
 
Example 15
Source File: EdgeTableWrapper.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
public void loadEndpointsAndLabel(AccumuloEdge edge) {
  Scanner s = getScanner();

  try {
    s.setRange(new Range(edge.getId().toString()));
    s.fetchColumnFamily(new Text(Constants.LABEL));
    Iterator<Entry<Key,Value>> iter = s.iterator();
    if (!iter.hasNext()) {
      dump();
      throw new AccumuloGraphException("Unable to find edge row: "+edge);
    }

    Entry<Key, Value> entry = iter.next();

    String cq = entry.getKey().getColumnQualifier().toString();
    String[] ids = cq.split(Constants.ID_DELIM);

    String label = AccumuloByteSerializer.deserialize(entry.getValue().get());

    edge.setVertices(new AccumuloVertex(globals, ids[0]),
        new AccumuloVertex(globals, ids[1]));
    edge.setLabel(label);

  } finally {
    s.close();
  }
}
 
Example 16
Source File: AccumuloIndexAgeDisplay.java    From datawave with Apache License 2.0 4 votes vote down vote up
/**
 * Pull data from accumulo, create a collection of delete cmds for th accumulo script for {@code indexes > 1 day}
 */
public void extractDataFromAccumulo() {
    dataBuckets = new ArrayList[buckets.length];
    for (int ii = 0; ii < dataBuckets.length; ii++) {
        dataBuckets[ii] = new ArrayList<>();
    }
    
    Scanner scanner = null;
    
    try {
        Authorizations userAuthorizations = conn.securityOperations().getUserAuthorizations(userName);
        scanner = conn.createScanner(tableName, userAuthorizations);
        scanner = addColumnsToScanner(scanner);
        Range range = new Range();
        scanner.setRange(range);
        
        long currentTime = System.currentTimeMillis();
        long mostRecent = currentTime - (MILLIS_IN_DAY * buckets[buckets.length - 1]);
        for (Map.Entry<Key,Value> entry : scanner) {
            long rowAge = entry.getKey().getTimestamp();
            if (rowAge < mostRecent) { // ** ignore data less than the newest bucket
                Text deleteCommand = createDeleteCmd(entry);
                int bucketIndex = 0;
                // separate the data according to the bucket they will be dropped into
                for (int age : buckets) {
                    if (rowAge <= (currentTime - (age * MILLIS_IN_DAY))) { // don't delete indexes < 1 day old
                        dataBuckets[bucketIndex].add((deleteCommand.toString()).replace("\0", "\\x00"));
                        break;
                    }
                    bucketIndex++;
                }
            }
        }
        
    } catch (AccumuloException ae) {
        log.error("Authorization error.");
    } catch (AccumuloSecurityException ase) {
        log.error("Accumulo security error.");
    } catch (TableNotFoundException tnfe) {
        log.error("Unable to find " + tableName + " in our accumulo instance.");
    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
}
 
Example 17
Source File: AccumuloClient.java    From presto with Apache License 2.0 4 votes vote down vote up
/**
 * Gets the TabletServer hostname for where the given key is located in the given table
 *
 * @param table Fully-qualified table name
 * @param key Key to locate
 * @return The tablet location, or DUMMY_LOCATION if an error occurs
 */
private Optional<String> getTabletLocation(String table, Key key)
{
    try {
        // Get the Accumulo table ID so we can scan some fun stuff
        String tableId = connector.tableOperations().tableIdMap().get(table);

        // Create our scanner against the metadata table, fetching 'loc' family
        Scanner scanner = connector.createScanner("accumulo.metadata", auths);
        scanner.fetchColumnFamily(new Text("loc"));

        // Set the scan range to just this table, from the table ID to the default tablet
        // row, which is the last listed tablet
        Key defaultTabletRow = new Key(tableId + '<');
        Key start = new Key(tableId);
        Key end = defaultTabletRow.followingKey(PartialKey.ROW);
        scanner.setRange(new Range(start, end));

        Optional<String> location = Optional.empty();
        if (key == null) {
            // if the key is null, then it is -inf, so get first tablet location
            Iterator<Entry<Key, Value>> iter = scanner.iterator();
            if (iter.hasNext()) {
                location = Optional.of(iter.next().getValue().toString());
            }
        }
        else {
            // Else, we will need to scan through the tablet location data and find the location

            // Create some text objects to do comparison for what we are looking for
            Text splitCompareKey = new Text();
            key.getRow(splitCompareKey);
            Text scannedCompareKey = new Text();

            // Scan the table!
            for (Entry<Key, Value> entry : scanner) {
                // Get the bytes of the key
                byte[] keyBytes = entry.getKey().getRow().copyBytes();

                // If the last byte is <, then we have hit the default tablet, so use this location
                if (keyBytes[keyBytes.length - 1] == '<') {
                    location = Optional.of(entry.getValue().toString());
                    break;
                }
                else {
                    // Chop off some magic nonsense
                    scannedCompareKey.set(keyBytes, 3, keyBytes.length - 3);

                    // Compare the keys, moving along the tablets until the location is found
                    if (scannedCompareKey.getLength() > 0) {
                        int compareTo = splitCompareKey.compareTo(scannedCompareKey);
                        if (compareTo <= 0) {
                            location = Optional.of(entry.getValue().toString());
                        }
                        else {
                            // all future tablets will be greater than this key
                            break;
                        }
                    }
                }
            }
            scanner.close();
        }

        // If we were unable to find the location for some reason, return the default tablet
        // location
        return location.isPresent() ? location : getDefaultTabletLocation(table);
    }
    catch (Exception e) {
        // Swallow this exception so the query does not fail due to being unable
        // to locate the tablet server for the provided Key.
        // This is purely an optimization, but we will want to log the error.
        LOG.error("Failed to get tablet location, returning dummy location", e);
        return Optional.empty();
    }
}
 
Example 18
Source File: FileCount.java    From accumulo-examples with Apache License 2.0 4 votes vote down vote up
private void calculateCounts(Scanner scanner, int depth, BatchWriter batchWriter)
    throws Exception {

  scanner.setRange(
      new Range(String.format("%03d", depth), true, String.format("%03d", depth + 1), false));

  CountValue countVal = new CountValue();

  Iterator<Entry<Key,Value>> iterator = scanner.iterator();

  String currentDir = null;

  Entry<Key,Value> entry = null;
  if (iterator.hasNext()) {
    entry = iterator.next();
    entriesScanned++;
  }

  while (entry != null) {
    Key key = entry.getKey();

    String dir = extractDir(key);

    if (currentDir == null) {
      currentDir = dir;
    } else if (!currentDir.equals(dir)) {
      batchWriter.addMutation(createMutation(depth - 1, currentDir, countVal));
      inserts++;
      currentDir = dir;
      countVal.clear();
    }

    // process a whole row
    if (key.compareColumnFamily(QueryUtil.DIR_COLF) == 0) {
      CountValue tmpCount = new CountValue();
      entry = findCount(entry, iterator, tmpCount);

      if (tmpCount.dirCount == 0 && tmpCount.fileCount == 0) {
        // in this case the higher depth will not insert anything if the
        // dir has no children, so insert something here
        Mutation m = new Mutation(key.getRow());
        m.put(QueryUtil.DIR_COLF, QueryUtil.COUNTS_COLQ, visibility, tmpCount.toValue());
        batchWriter.addMutation(m);
        inserts++;
      }

      countVal.incrementRecursive(tmpCount);
      countVal.incrementDirs();
    } else {
      entry = consumeRow(entry, iterator);
      countVal.incrementFiles();
    }
  }

  if (currentDir != null) {
    batchWriter.addMutation(createMutation(depth - 1, currentDir, countVal));
    inserts++;
  }
}
 
Example 19
Source File: ProspectorService.java    From rya with Apache License 2.0 3 votes vote down vote up
/**
 * Get a list of timestamps that represents all of the Prospect runs that
 * have been performed inclusively between two timestamps.
 *
 * @param beginTime - The start of the time range.
 * @param endTime - The end of the time range.
 * @param auths - The authorizations used to scan the table for prospects.
 * @return A list of timestamps representing each Prospect run that was found.
 * @throws TableNotFoundException The table name that was provided when this
 *   class was constructed does not match a table that the connector has access to.
 */
public Iterator<Long> getProspectsInRange(long beginTime, long endTime, String[] auths) throws TableNotFoundException {
    final Scanner scanner = connector.createScanner(tableName, new Authorizations(auths));
    scanner.setRange(new Range(
            new Key(METADATA, PROSPECT_TIME, ProspectorUtils.getReverseIndexDateTime(new Date(endTime)), "", Long.MAX_VALUE),
            new Key(METADATA, PROSPECT_TIME, ProspectorUtils.getReverseIndexDateTime(new Date(beginTime)), "", 0l)
    ));

    return new ProspectTimestampIterator( scanner.iterator() );
}
 
Example 20
Source File: DocumentIndexIntersectingIteratorTest.java    From rya with Apache License 2.0 2 votes vote down vote up
@Test
public void testFixedRangeColumnValidateExact() throws Exception {

    BatchWriter bw = null;

    bw = accCon.createBatchWriter(tablename, 500L * 1024L * 1024L, Long.MAX_VALUE, 30);



    for (int i = 0; i < 100; i++) {

        Mutation m = new Mutation(new Text("" + i));

        m.put(new Text("cf" + 1), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 1 ), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 2), new Value(new byte[0]));
        m.put(new Text("cf" + 1), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 1), new Value(new byte[0]));
        m.put(new Text("cf" + 2), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 2), new Value(new byte[0]));



        if(i == 30 || i == 60 || i == 90 || i == 99) {
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 3), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 3), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 4), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 4), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"obj" + "\u0000" + "cq" + 5), new Value(new byte[0]));
            m.put(new Text("cf" + 3), new Text(null + "\u0000" +"subj" + "\u0000" + "cq" + 5), new Value(new byte[0]));
        }

        bw.addMutation(m);

    }



    TextColumn tc1 = new TextColumn(new Text("cf" + 1 ), new Text("obj" + "\u0000" + "cq" + 1));
    TextColumn tc2 = new TextColumn(new Text("cf" + 2), new Text("obj" + "\u0000" + "cq" + 2));
    TextColumn tc3 = new TextColumn(new Text("cf" + 3), new Text("subj" + "\u0000" + "cq" + 3));
    TextColumn tc4 = new TextColumn(new Text("cf" + 3), new Text("subj" + "\u0000" + "cq" + 4));
    TextColumn tc5 = new TextColumn(new Text("cf" + 3), new Text("subj" + "\u0000" + "cq" + 5));



    TextColumn[] tc = new TextColumn[5];
    tc[0] = tc1;
    tc[1] = tc2;
    tc[2] = tc3;
    tc[3] = tc4;
    tc[4] = tc5;


    IteratorSetting is = new IteratorSetting(30, "fii", DocumentIndexIntersectingIterator.class);

    DocumentIndexIntersectingIterator.setColumnFamilies(is, tc);

    Scanner scan = accCon.createScanner(tablename, new Authorizations("auths"));
    scan.setRange(Range.exact(new Text("" + 30)));
    scan.addScanIterator(is);

    int results = 0;
    System.out.println("************************Test 14****************************");
    for (Map.Entry<Key, Value> e : scan) {
        System.out.println(e);
        results++;
    }


    Assert.assertEquals(1, results);




}