org.apache.accumulo.core.client.Scanner Java Examples

The following examples show how to use org.apache.accumulo.core.client.Scanner. 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: ARS.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
public List<String> list(String what, String when) throws Exception {
  String row = what + ":" + when;

  // its important to use an isolated scanner so that only whole mutations are seen
  try (
      Scanner scanner = new IsolatedScanner(client.createScanner(rTable, Authorizations.EMPTY))) {
    scanner.setRange(new Range(row));
    scanner.fetchColumnFamily(new Text("res"));

    List<String> reservations = new ArrayList<>();

    for (Entry<Key,Value> entry : scanner) {
      String val = entry.getValue().toString();
      reservations.add(val);
    }

    return reservations;
  }
}
 
Example #2
Source File: TracingExample.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
private void readEntries(Opts opts) throws TableNotFoundException {

    Scanner scanner = client.createScanner(opts.getTableName(), opts.auths);

    // Trace the read operation.
    TraceScope readScope = Trace.startSpan("Client Read", Sampler.ALWAYS);
    System.out.println("TraceID: " + Long.toHexString(readScope.getSpan().getTraceId()));

    int numberOfEntriesRead = 0;
    for (Entry<Key,Value> entry : scanner) {
      System.out.println(entry.getKey().toString() + " -> " + entry.getValue().toString());
      ++numberOfEntriesRead;
    }
    // You can add additional metadata (key, values) to Spans which will be able to be viewed in the
    // Monitor
    readScope.getSpan().addKVAnnotation("Number of Entries Read".getBytes(UTF_8),
        String.valueOf(numberOfEntriesRead).getBytes(UTF_8));

    readScope.close();
  }
 
Example #3
Source File: PrintUtility.java    From datawave with Apache License 2.0 6 votes vote down vote up
public static void printTable(final Connector conn, final Authorizations authorizations, final String tableName, final PrintStream out)
                throws TableNotFoundException {
    final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HHmmss");
    
    final StringBuilder sb = new StringBuilder("--Begin entire " + tableName + " table--");
    
    sb.append("\n");
    
    final Scanner scanner = conn.createScanner(tableName, authorizations);
    for (final Entry<Key,Value> e : scanner) {
        sb.append(e.getKey().toStringNoTime());
        sb.append(' ');
        sb.append(dateFormat.format(new Date(e.getKey().getTimestamp())));
        sb.append('\t');
        sb.append(getPrintableValue(e.getValue()));
        sb.append("\n");
    }
    
    sb.append("--End entire ").append(tableName).append(" table--").append("\n");
    
    out.println(sb);
}
 
Example #4
Source File: FailureIT.java    From fluo with Apache License 2.0 6 votes vote down vote up
private boolean wasRolledBackPrimary(long startTs, String rolledBackRow)
    throws TableNotFoundException {
  boolean sawExpected = false;
  Scanner scanner = aClient.createScanner(getCurTableName(), Authorizations.EMPTY);

  for (Entry<Key, Value> entry : scanner) {
    ColumnType colType = ColumnType.from(entry.getKey());
    long ts = entry.getKey().getTimestamp() & ColumnConstants.TIMESTAMP_MASK;
    String row = entry.getKey().getRowData().toString();
    byte[] val = entry.getValue().get();

    if (row.equals(rolledBackRow) && colType == ColumnType.DEL_LOCK && ts == startTs
        && DelLockValue.isPrimary(val)) {
      sawExpected = true;
    }
  }
  return sawExpected;
}
 
Example #5
Source File: AccumuloTestHelper.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
public static AccumuloTuple getAccumuloTuple(String row, String colFam,
    String colName)
{
  Authorizations auths = new Authorizations();

  Scanner scan = null;
  try {
    scan = con.createScanner("tab1", auths);
  } catch (TableNotFoundException e) {
    logger.error("error in test helper");
    DTThrowable.rethrow(e);
  }

  scan.setRange(new Range(new Text(row)));
  scan.fetchColumn(new Text(colFam), new Text(colName));
  // assuming only one row
  for (Entry<Key, Value> entry : scan) {
    AccumuloTuple tuple = new AccumuloTuple();
    tuple.setRow(entry.getKey().getRow().toString());
    tuple.setColFamily(entry.getKey().getColumnFamily().toString());
    tuple.setColName(entry.getKey().getColumnQualifier().toString());
    tuple.setColValue(entry.getValue().toString());
    return tuple;
  }
  return null;
}
 
Example #6
Source File: AccumuloGraph.java    From vertexium with Apache License 2.0 6 votes vote down vote up
private long getRowCountFromTable(String tableName, Text signalColumn, Authorizations authorizations) {
    try {
        LOGGER.debug("BEGIN getRowCountFromTable(%s)", tableName);
        Scanner scanner = createScanner(tableName, null, authorizations);
        try {
            scanner.fetchColumnFamily(signalColumn);

            IteratorSetting countingIterator = new IteratorSetting(
                100,
                CountingIterator.class.getSimpleName(),
                CountingIterator.class
            );
            scanner.addScanIterator(countingIterator);

            GRAPH_LOGGER.logStartIterator(tableName, scanner);

            long count = 0;
            for (Map.Entry<Key, Value> entry : scanner) {
                Long countForKey = LongCombiner.FIXED_LEN_ENCODER.decode(entry.getValue().get());
                LOGGER.debug("getRowCountFromTable(%s): %s: %d", tableName, entry.getKey().getRow(), countForKey);
                count += countForKey;
            }
            LOGGER.debug("getRowCountFromTable(%s): TOTAL: %d", tableName, count);
            return count;
        } finally {
            scanner.close();
        }
    } catch (TableNotFoundException ex) {
        throw new VertexiumException("Could not get count from table: " + tableName, ex);
    }
}
 
Example #7
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 #8
Source File: AbstractFunctionalQuery.java    From datawave with Apache License 2.0 6 votes vote down vote up
protected Multimap<String,Key> removeMetadataEntries(Set<String> fields, Text cf) throws AccumuloSecurityException, AccumuloException,
                TableNotFoundException {
    Multimap<String,Key> metadataEntries = HashMultimap.create();
    MultiTableBatchWriter multiTableWriter = connector.createMultiTableBatchWriter(new BatchWriterConfig());
    BatchWriter writer = multiTableWriter.getBatchWriter(QueryTestTableHelper.METADATA_TABLE_NAME);
    for (String field : fields) {
        Mutation mutation = new Mutation(new Text(field));
        Scanner scanner = connector.createScanner(QueryTestTableHelper.METADATA_TABLE_NAME, new Authorizations());
        scanner.fetchColumnFamily(cf);
        scanner.setRange(new Range(new Text(field)));
        boolean foundEntries = false;
        for (Map.Entry<Key,Value> entry : scanner) {
            foundEntries = true;
            metadataEntries.put(field, entry.getKey());
            mutation.putDelete(entry.getKey().getColumnFamily(), entry.getKey().getColumnQualifier(), entry.getKey().getColumnVisibilityParsed());
        }
        scanner.close();
        if (foundEntries) {
            writer.addMutation(mutation);
        }
    }
    writer.close();
    connector.tableOperations().compact(QueryTestTableHelper.METADATA_TABLE_NAME, new Text("\0"), new Text("~"), true, true);
    return metadataEntries;
}
 
Example #9
Source File: IndexMetadataTableWrapper.java    From AccumuloGraph with Apache License 2.0 6 votes vote down vote up
public <T extends Element> Set<String> getIndexedKeys(Class<T> elementClass) {
  if (elementClass == null) {
    throw ExceptionFactory.classForElementCannotBeNull();
  }

  IndexedItemsListParser parser = new IndexedItemsListParser(elementClass);

  Scanner scan = null;
  try {
    scan = getScanner();
    scan.fetchColumnFamily(new Text(IndexMetadataEntryType.__INDEX_KEY__.name()));

    Set<String> keys = new HashSet<String>();
    for (IndexedItem item : parser.parse(scan)) {
      keys.add(item.getKey());
    }

    return keys;

  } finally {
    if (scan != null) {
      scan.close();
    }
  }
}
 
Example #10
Source File: CountIT.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws Exception {
  Scanner scanner = client.createScanner(tableName, new Authorizations());
  scanner.fetchColumn(new Text("dir"), new Text("counts"));
  assertFalse(scanner.iterator().hasNext());

  ScannerOpts scanOpts = new ScannerOpts();
  BatchWriterOpts bwOpts = new BatchWriterOpts();
  FileCount fc = new FileCount(client, tableName, Authorizations.EMPTY, new ColumnVisibility(),
      scanOpts, bwOpts);
  fc.run();

  ArrayList<Pair<String,String>> expected = new ArrayList<>();
  expected.add(new Pair<>(QueryUtil.getRow("").toString(), "1,0,3,3"));
  expected.add(new Pair<>(QueryUtil.getRow("/local").toString(), "2,1,2,3"));
  expected.add(new Pair<>(QueryUtil.getRow("/local/user1").toString(), "0,2,0,2"));
  expected.add(new Pair<>(QueryUtil.getRow("/local/user2").toString(), "0,0,0,0"));

  int i = 0;
  for (Entry<Key,Value> e : scanner) {
    assertEquals(e.getKey().getRow().toString(), expected.get(i).getFirst());
    assertEquals(e.getValue().toString(), expected.get(i).getSecond());
    i++;
  }
  assertEquals(i, expected.size());
}
 
Example #11
Source File: AccumuloIndexAgeDisplay.java    From datawave with Apache License 2.0 6 votes vote down vote up
/**
 * Add one or more column families or column family and qualifier to a scanner.
 * 
 * @param scanner
 *            to add columns to.
 * @return The scanner with columns
 */
private Scanner addColumnsToScanner(Scanner scanner) {
    if ((null != columns) && (!columns.equals(("")))) {
        String[] cols = columns.split(",");
        for (String colStr : cols) {
            String[] parts = colStr.split(":");
            if (parts.length == 1) {
                scanner.fetchColumnFamily(new Text(parts[0]));
            } else if (parts.length == 2) {
                scanner.fetchColumn(new Text(parts[0]), new Text(parts[1]));
            }
        }
    }
    
    return (scanner);
}
 
Example #12
Source File: QueryUtil.java    From accumulo-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Scans over the index table for files or directories with a given name, prefix, or suffix
 * (indicated by a wildcard '*' at the beginning or end of the term.
 *
 * @param exp
 *          the name a file or directory to search for with an optional wildcard '*' at the
 *          beginning or end
 */
public Iterable<Entry<Key,Value>> singleRestrictedWildCardSearch(String exp) throws Exception {
  if (exp.indexOf("/") >= 0)
    throw new Exception("this method only works with unqualified names");

  Scanner scanner = client.createScanner(tableName, auths);
  if (exp.startsWith("*")) {
    System.out.println("executing beginning wildcard search for " + exp);
    exp = exp.substring(1);
    scanner.setRange(Range.prefix(getReverseIndex(exp)));
  } else if (exp.endsWith("*")) {
    System.out.println("executing ending wildcard search for " + exp);
    exp = exp.substring(0, exp.length() - 1);
    scanner.setRange(Range.prefix(getForwardIndex(exp)));
  } else if (exp.indexOf("*") >= 0) {
    throw new Exception("this method only works for beginning or ending wild cards");
  } else {
    return exactTermSearch(exp);
  }
  return scanner;
}
 
Example #13
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 6 votes vote down vote up
/**
 * Interval after given interval.  Find intervals that begin after the endings of the given interval.
 * Use the special following prefix mechanism to avoid matching the beginning date.
 * Indexing Intervals  will probably change or be removed.
 * Currently predicate and subject and context constraints are filtered on the client.
 */
@Override
public CloseableIteration<Statement, QueryEvaluationException> queryIntervalAfter(
        final TemporalInterval queryInterval, final StatementConstraints constraints)
        throws QueryEvaluationException {

    final Scanner scanner = getScanner();
    if (scanner != null) {
        // get rows where the start date is greater than the queryInterval.getEnd()
        final Range range = new Range(new Key(Range.followingPrefix(new Text(queryInterval.getHasEnd().getAsKeyBytes()))), false, null, true);
        scanner.setRange(range);

        if (constraints.hasContext()) {
            scanner.fetchColumn(new Text(constraints.getContext().toString()), new Text(KeyParts.CQ_BEGIN));
        } else {
            scanner.fetchColumn(new Text(""), new Text(KeyParts.CQ_BEGIN));
        }
    }
    // TODO currently predicate, subject and context constraints are filtered on the clients
    return getIteratorWrapper(scanner);
}
 
Example #14
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 #15
Source File: BaseIndexValuesTableWrapper.java    From AccumuloGraph with Apache License 2.0 6 votes vote down vote up
/**
 * Get elements with the key/value pair.
 * @param key
 * @param value
 * @return
 */
@SuppressWarnings("unchecked")
public <T extends Element> CloseableIterable<T> readElementsFromIndex(String key, Object value) {
  Scanner scan = getScanner();
  byte[] id = AccumuloByteSerializer.serialize(value);
  scan.setRange(Range.exact(new Text(id)));
  scan.fetchColumnFamily(new Text(key));

  final ElementIndexParser<? extends AccumuloElement> parser =
      Vertex.class.equals(elementType) ? new VertexIndexParser(globals) :
        new EdgeIndexParser(globals);

      return new ScannerIterable<T>(scan) {
        @Override
        public T next(PeekingIterator<Entry<Key,Value>> iterator) {
          return (T) parser.parse(Arrays.asList(iterator.next()));
        }      
      };
}
 
Example #16
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 #17
Source File: AccumuloGraphLogger.java    From vertexium with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: Read.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws TableNotFoundException {
  ClientOpts opts = new ClientOpts();
  opts.parseArgs(Read.class.getName(), args);

  try (AccumuloClient client = Accumulo.newClient().from(opts.getClientPropsPath()).build();
      Scanner scan = client.createScanner("hellotable", Authorizations.EMPTY)) {
    scan.setRange(new Range(new Key("row_0"), new Key("row_1002")));
    for (Entry<Key,Value> e : scan) {
      Key key = e.getKey();
      log.trace(key.getRow() + " " + key.getColumnFamily() + " " + key.getColumnQualifier() + " "
          + e.getValue());
    }
  }
}
 
Example #19
Source File: AccumuloGraph.java    From vertexium with Apache License 2.0 5 votes vote down vote up
private Scanner createScanner(
    String tableName,
    org.apache.accumulo.core.data.Range range,
    Authorizations authorizations
) throws TableNotFoundException {
    org.apache.accumulo.core.security.Authorizations accumuloAuthorizations = toAccumuloAuthorizations(authorizations);
    return createScanner(tableName, range, accumuloAuthorizations);
}
 
Example #20
Source File: RowOperations.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
private static void printRow(String row, AccumuloClient client) throws TableNotFoundException {
  try (Scanner scanner = client.createScanner(table, Authorizations.EMPTY)) {
    scanner.setRange(Range.exact(row));
    for (Entry<Key,Value> entry : scanner) {
      log.info("Key: " + entry.getKey().toString() + " Value: " + entry.getValue().toString());
    }
  }
}
 
Example #21
Source File: ConfigUtils.java    From rya with Apache License 2.0 5 votes vote down vote up
public static Scanner createScanner(final String tablename, final Configuration conf)
        throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
    final Connector connector = ConfigUtils.getConnector(conf);
    final Authorizations auths = ConfigUtils.getAuthorizations(conf);
    return connector.createScanner(tablename, auths);

}
 
Example #22
Source File: QueryUtil.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
/**
 * Scans over the directory table and pulls out stat information about a path.
 *
 * @param path
 *          the full path of a file or directory
 */
public Map<String,String> getData(String path) throws TableNotFoundException {
  if (path.endsWith("/"))
    path = path.substring(0, path.length() - 1);
  Scanner scanner = client.createScanner(tableName, auths);
  scanner.setRange(new Range(getRow(path)));
  Map<String,String> data = new TreeMap<>();
  for (Entry<Key,Value> e : scanner) {
    String type = getType(e.getKey().getColumnFamily());
    data.put("fullname", e.getKey().getRow().toString().substring(3));
    data.put(type + e.getKey().getColumnQualifier().toString() + ":"
        + e.getKey().getColumnVisibility().toString(), new String(e.getValue().get()));
  }
  return data;
}
 
Example #23
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.
 *
 * @param term
 *          the name a file or directory to search for
 */
public Iterable<Entry<Key,Value>> exactTermSearch(String term) throws Exception {
  System.out.println("executing exactTermSearch for " + term);
  Scanner scanner = client.createScanner(tableName, auths);
  scanner.setRange(new Range(getForwardIndex(term)));
  return scanner;
}
 
Example #24
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 #25
Source File: FirstEntryInPrefixedRowTest.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
private Scanner buildScanner() throws TableNotFoundException {
  IteratorSetting setting = new IteratorSetting(5, TestFirstEntryInPrefixedRowIterator.class);
  Scanner scanner = connector.createScanner("test", new Authorizations());
  scanner.addScanIterator(setting);

  return scanner;
}
 
Example #26
Source File: FileCount.java    From accumulo-examples with Apache License 2.0 5 votes vote down vote up
public void run() throws Exception {

    entriesScanned = 0;
    inserts = 0;

    Scanner scanner = client.createScanner(tableName, auths);
    scanner.setBatchSize(scanOpts.scanBatchSize);
    BatchWriter bw = client.createBatchWriter(tableName, bwOpts.getBatchWriterConfig());

    long t1 = System.currentTimeMillis();

    int depth = findMaxDepth(scanner);

    long t2 = System.currentTimeMillis();

    for (int d = depth; d > 0; d--) {
      calculateCounts(scanner, d, bw);
      // must flush so next depth can read what prev depth wrote
      bw.flush();
    }

    bw.close();

    long t3 = System.currentTimeMillis();

    System.out.printf("Max depth              : %d%n", depth);
    System.out.printf("Time to find max depth : %,d ms%n", (t2 - t1));
    System.out.printf("Time to compute counts : %,d ms%n", (t3 - t2));
    System.out.printf("Entries scanned        : %,d %n", entriesScanned);
    System.out.printf("Counts inserted        : %,d %n", inserts);
  }
 
Example #27
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 #28
Source File: AccumuloTemporalIndexer.java    From rya with Apache License 2.0 5 votes vote down vote up
/**
 * An iteration wrapper for a loaded scanner that is returned for partially supported interval queries above.
 *
 * @param scanner  the results to iterate, then close.
 * @param constraints  limit statements returned by next() to those matching the constraints.
 * @return an anonymous object that will iterate the resulting statements from a given scanner.
 * @throws QueryEvaluationException
 */
private static CloseableIteration<Statement, QueryEvaluationException> getConstrainedIteratorWrapper(final Scanner scanner, final StatementConstraints constraints) {
    if (!constraints.hasContext() && !constraints.hasSubject() && !constraints.hasPredicates()) {
        return getIteratorWrapper(scanner);
    }
    return new ConstrainedIteratorWrapper(scanner) {
        @Override
        public boolean allowedBy(final Statement statement) {
            return allowedByConstraints(statement, constraints);
        }
    };
}
 
Example #29
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 #30
Source File: AccumuloOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public CloseableIterator<GeoWaveRow> getDataIndexResults(
    final byte[] startRow,
    final byte[] endRow,
    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(
        AccumuloUtils.byteArrayRangeToAccumuloRange(new ByteArrayRange(startRow, endRow)));
    scanner.fetchColumnFamily(new Text(family));
    return new CloseableIteratorWrapper(new Closeable() {
      @Override
      public void close() throws IOException {
        scanner.close();
      }
    },
        Streams.stream(scanner.iterator()).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<>();
}