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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
    //This code shows an example of reading data from an Accumulo instance.

    //TODO unsure about assignments below

    string instancestr = argv[1];

    string zookeepers = argv[2];

    string username = argv[3];

    string password = argv[4];



    auto instance = new ZookeeperInstance(instancestr, zookeepers, 1000);



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



    auto master = new MasterConnect(&creds, instance);



    auto ops = master->tableOps(table);

    // create the scanner with ten threads.

    auto scanner = ops->createScanner (&auths, 10);

    // range from a to d

    Key startkey;

    startkey.setRow("a", 1);

    Key stopKey;

    stopKey.setRow("d", 1);

    Range range(startkey, true, stopKey, true); 

    // build your range.

    scanner->addRange(&range);



    auto results = scanner->getResultSet ();



    for (const auto &iter : results) {

	auto kv = *iter;

	if (kv != NULL && kv->getKey() != NULL)

	    cout << "got -- " << (*iter)->getKey() << endl;

	else

	    cout << "Key is null" << endl;

    }


older variant

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    //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-&gt;tableOps(

	    table);

    // create the scanner with ten threads.

    std::unique_ptr<scanners::BatchScanner> scanner = ops-&gt;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.

    scanner->addRange(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;

	else

	    cout << "Key is null" << endl;

    }