C++ Example

The following is an example of using the API to create a scanner and read data from an accumulo instance.

    //This code shows an example of reading data from an Accumulo instance.

    //TODO unsure about assignments below
    string instance = argv[1];
    string zookeepers = argv[2];
    string username = argv[3];
    string password = argv[4];

    ZookeeperInstance *instance = new ZookeeperInstance(instance, zookeepers, 1000);

    AuthInfo creds(username, password, instance->getInstanceId());

    interconnect::MasterConnect *master = new MasterConnect(&creds, instance);

    std::unique_ptr<interconnect::AccumuloTableOperations> ops = master->tableOps(
    // create the scanner with ten threads.
    std::unique_ptr<scanners::BatchScanner> scanner = ops->createScanner (&auths, 10);
    // range from a to d
    Key startkey;
    startkey.setRow("a", 1);
    Key stopKey;
    stopKey.setRow("d", 1);
    Range *range = new Range(startkey, true, stopKey, true); 
    // build your range.

    scanners::Iterator<cclient::data::KeyValue> *results =
                        scanner->getResultSet ();

    for (auto iter : results) {
        KeyValue *kv = *iter;
        if (kv != NULL && kv->getKey() != NULL)
            cout << "got -- " << (*iter)->getKey() << endl;
            cout << "Key is null" << endl;

Leave a Reply

Your email address will not be published. Required fields are marked *