Package org.apache.accumulo.core.client

Examples of org.apache.accumulo.core.client.BatchScanner


      int numThreads = 20;
      if (cl.hasOption(numThreadsOpt.getOpt())) {
        numThreads = Integer.parseInt(cl.getOptionValue(numThreadsOpt.getOpt()));
      }
      Authorizations auths = getAuths(cl, shellState);
      BatchScanner scanner = shellState.connector.createBatchScanner(shellState.tableName, auths, numThreads);
      scanner.setRanges(Collections.singletonList(getRange(cl)));
     
      for (int i = 0; i < cl.getArgs().length; i++)
        setUpIterator(Integer.MAX_VALUE, "grep" + i, cl.getArgs()[i], scanner);
     
      try {
        // handle columns
        fetchColumns(cl, scanner);
       
        // output the records
        printRecords(cl, shellState, scanner);
      } finally {
        scanner.close();
      }
      return 0;
    }
View Full Code Here


      Mutation m = new Mutation(asText(r));
      m.put(asText(random.nextInt()), asText(random.nextInt()), new Value(Integer.toHexString(r).getBytes()));
      bw.addMutation(m);
    }
    bw.close();
    BatchScanner s = c.createBatchScanner("test", Constants.NO_AUTHS, 2);
    s.setRanges(Collections.singletonList(new Range()));
    Key key = null;
    int count = 0;
    for (Entry<Key,Value> entry : s) {
      if (key != null)
        assertTrue(key.compareTo(entry.getKey()) < 0);
View Full Code Here

        results.put(override, tr);
    }
   
    if (log.isDebugEnabled())
      log.debug("Querying global index table: " + tableName + ", range: " + rangeSuperSet.toString() + " colf: " + specificFieldName);
    BatchScanner bs = this.c.createBatchScanner(tableName, this.auths, this.queryThreads);
    bs.setRanges(rangeSuperSet);
    if (null != specificFieldName) {
      bs.fetchColumnFamily(new Text(specificFieldName));
    }
   
    for (Entry<Key,Value> entry : bs) {
      if (log.isDebugEnabled()) {
        log.debug("Index entry: " + entry.getKey().toString());
      }
      String fieldValue = null;
      if (!isReverse) {
        fieldValue = entry.getKey().getRow().toString();
      } else {
        StringBuilder buf = new StringBuilder(entry.getKey().getRow().toString());
        fieldValue = buf.reverse().toString();
      }
     
      String fieldName = entry.getKey().getColumnFamily().toString();
      // Get the shard id and datatype from the colq
      String colq = entry.getKey().getColumnQualifier().toString();
      int separator = colq.indexOf(EvaluatingIterator.NULL_BYTE_STRING);
      String shardId = null;
      String datatype = null;
      if (separator != -1) {
        shardId = colq.substring(0, separator);
        datatype = colq.substring(separator + 1);
      } else {
        shardId = colq;
      }
      // Skip this entry if the type is not correct
      if (null != datatype && null != typeFilter && !typeFilter.contains(datatype))
        continue;
      // Parse the UID.List object from the value
      Uid.List uidList = null;
      try {
        uidList = Uid.List.parseFrom(entry.getValue().get());
      } catch (InvalidProtocolBufferException e) {
        // Don't add UID information, at least we know what shards
        // it is located in.
      }
     
      // Add the count for this shard to the total count for the term.
      long count = 0;
      Long storedCount = termCardinalities.get(fieldName);
      if (null == storedCount || 0 == storedCount) {
        count = uidList.getCOUNT();
      } else {
        count = uidList.getCOUNT() + storedCount;
      }
      termCardinalities.put(fieldName, count);
      this.indexEntries.put(fieldName, fieldValue);
     
      if (null == override)
        this.indexValues.put(fieldValue, fieldValue);
      else
        this.indexValues.put(fieldValue, override.getOriginalQueryValue());
     
      // Create the keys
      Text shard = new Text(shardId);
      if (uidList.getIGNORE()) {
        // Then we create a scan range that is the entire shard
        if (null == override)
          results.get(new MapKey(fieldName, fieldValue)).add(new Range(shard));
        else
          results.get(override).add(new Range(shard));
      } else {
        // We should have UUIDs, create event ranges
        for (String uuid : uidList.getUIDList()) {
          Text cf = new Text(datatype);
          TextUtil.textAppend(cf, uuid);
          Key startKey = new Key(shard, cf);
          Key endKey = new Key(shard, new Text(cf.toString() + EvaluatingIterator.NULL_BYTE_STRING));
          Range eventRange = new Range(startKey, true, endKey, false);
          if (null == override)
            results.get(new MapKey(fieldName, fieldValue)).add(eventRange);
          else
            results.get(override).add(eventRange);
        }
      }
    }
    bs.close();
    return results;
  }
View Full Code Here

 
  private void verify(ByteArraySet nss, String... expected) throws Exception {
    Scanner scanner = getConnector().createScanner("vt", new Authorizations(nss));
    verify(scanner.iterator(), expected);
   
    BatchScanner bs = getConnector().createBatchScanner("vt", new Authorizations(nss), 3);
    bs.setRanges(Collections.singleton(new Range()));
    verify(bs.iterator(), expected);
    bs.close();
  }
View Full Code Here

    Scanner scanner = null;/*
                            * connector.createScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS); ColumnFQ.fetch(scanner,
                            * Constants.METADATA_LOCATION_COLUMN); ColumnFQ.fetch(scanner, Constants.METADATA_PREV_ROW_COLUMN);
                            */
   
    BatchScanner bs = connector.createBatchScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS, 1);
    bs.fetchColumnFamily(Constants.METADATA_CURRENT_LOCATION_COLUMN_FAMILY);
    ColumnFQ.fetch(bs, Constants.METADATA_PREV_ROW_COLUMN);
   
    bs.setRanges(ranges);
   
    // System.out.println(ranges);
   
    ScanStats stats = new ScanStats();
    for (int i = 0; i < numLoop; i++) {
View Full Code Here

    int refCount = 0;
   
    try {
      // look for other tables that references this tables files
      Connector conn = instance.getConnector(SecurityConstants.getSystemCredentials());
      BatchScanner bs = conn.createBatchScanner(Constants.METADATA_TABLE_NAME, Constants.NO_AUTHS, 8);
      try {
        bs.setRanges(Collections.singleton(Constants.NON_ROOT_METADATA_KEYSPACE));
        bs.fetchColumnFamily(Constants.METADATA_DATAFILE_COLUMN_FAMILY);
        IteratorSetting cfg = new IteratorSetting(40, "grep", GrepIterator.class);
        GrepIterator.setTerm(cfg, "../" + tableId + "/");
        bs.addScanIterator(cfg);
       
        for (Entry<Key,Value> entry : bs) {
          if (entry.getKey().getColumnQualifier().toString().startsWith("../" + tableId + "/")) {
            refCount++;
          }
        }
      } finally {
        bs.close();
      }
     
    } catch (Exception e) {
      refCount = -1;
      log.error("Failed to scan !METADATA looking for references to deleted table " + tableId, e);
View Full Code Here

      undefs.add(new UndefinedNode(undef, ref));
    }
   
    ZooKeeperInstance zki = new ZooKeeperInstance(instanceName, zooKeepers);
    Connector conn = zki.getConnector(user, password.getBytes());
    BatchScanner bscanner = conn.createBatchScanner(table, Constants.NO_AUTHS, 20);
   
    List<Range> refs = new ArrayList<Range>();
   
    for (UndefinedNode undefinedNode : undefs)
      refs.add(new Range(new Text(undefinedNode.ref)));
   
    bscanner.setRanges(refs);
   
    HashMap<String,List<String>> refInfo = new HashMap<String,List<String>>();
   
    for (Entry<Key,Value> entry : bscanner) {
      String ref = entry.getKey().getRow().toString();
      List<String> vals = refInfo.get(ref);
      if (vals == null) {
        vals = new ArrayList<String>();
        refInfo.put(ref, vals);
      }
     
      vals.add(entry.getValue().toString());
    }
   
    bscanner.close();
   
    IngestInfo ingestInfo = new IngestInfo(logDir);
    TabletHistory tabletHistory = new TabletHistory(Tables.getTableId(zki, table), acuLogDir);
   
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
View Full Code Here

    RandomAuths randomAuths = new RandomAuths(authsFile);
    Authorizations auths = randomAuths.getAuths(r);

    Connector conn = new ZooKeeperInstance(instanceName, zooKeepers).getConnector(user, password.getBytes());
    Scanner scanner = conn.createScanner(table, auths);
    BatchScanner bs = conn.createBatchScanner(table, auths, numQueryThreads);

    while (true) {
      Set<Text> batch = getBatch(scanner, min, max, batchSize, r);
     
      List<Range> ranges = new ArrayList<Range>(batch.size());
View Full Code Here

    m.put("rvy", "5000000000000000", empty);
    m.put("15qh", "5000000000000000", empty);
    bw.addMutation(m);
    bw.close();
   
    BatchScanner bs = connector.createBatchScanner("index", Constants.NO_AUTHS, 10);
    IteratorSetting ii = new IteratorSetting(20, IntersectingIterator.class);
    IntersectingIterator.setColumnFamilies(ii, new Text[] {new Text("rvy"), new Text("15qh")});
    bs.addScanIterator(ii);
    bs.setRanges(Collections.singleton(new Range()));
    Iterator<Entry<Key,Value>> iterator = bs.iterator();
    Assert.assertTrue(iterator.hasNext());
    Entry<Key,Value> next = iterator.next();
    Key key = next.getKey();
    Assert.assertEquals(key.getColumnQualifier(), new Text("5000000000000000"));
    Assert.assertFalse(iterator.hasNext());
View Full Code Here

            w.close();
        }
    }
   
    protected void assertVersionable(Connector c, String tableName, int size) throws TableNotFoundException {
        BatchScanner s = c.createBatchScanner(tableName, Constants.NO_AUTHS, 1);
        s.setRanges(Collections.singleton(Range.exact("row1", "cf", "cq")));
        int count = 0;
        for (Map.Entry<Key, Value> e: s) {
            Assert.assertEquals("row1", e.getKey().getRow().toString());
            Assert.assertEquals("cf", e.getKey().getColumnFamily().toString());
            Assert.assertEquals("cq", e.getKey().getColumnQualifier().toString());
            count++;
           
        }
        Assert.assertEquals(size, count);
        s.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.accumulo.core.client.BatchScanner

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.