3

我不能让批处理扫描仪只扫描特定的行,当设置启动和停止键到同一件事时,我没有得到任何条目,当使用扫描仪时,我得到了这个异常:

“java.lang.IllegalArgumentException:开始键必须小于范围内的结束键(测试:[] 0 false,测试:[] 0 false)”...

我在 Visual Studio 2010 中用 C# 编写,并在项目中使用 Thrift(版本 0.9.1.1)和 Accumulo(版本 1.5.0)proxy.thrift 代码。

这是我的代码,一切“正常”,但我没有得到任何条目client.nextK

class Program
{
    static byte[] GetBytes(string str)
    {
        return Encoding.ASCII.GetBytes(str);
    }

    static string GetString(byte[] bytes)
    {
        return Encoding.ASCII.GetString(bytes);
    }

    static void Main(string[] args)
    {
        try
        {
            /** connect **/
            TTransport transport = new TSocket("192.168.58.62", 42424);
            transport = new TFramedTransport(transport);
            TCompactProtocol protocol = new TCompactProtocol(transport);
            transport.Open();

            AccumuloProxy.Client client = new AccumuloProxy.Client(protocol);

            Dictionary<string, string> passwd = new Dictionary<string,string>();
            passwd.Add("password", "password");

            var login = client.login("root", passwd);
            /** connect end **/

            /** Get all data from one "Row" **/
            var bScanner = new BatchScanOptions();

            Range range = new Range();

            range.Start = new Key();
            range.Start.Row = GetBytes("Test");

            range.Stop = new Key();
            range.Stop.Row = GetBytes("Test");

            bScanner.Ranges = new List<Range>();
            bScanner.Ranges.Add(range);

            var scanId = client.createBatchScanner(login, "firstTable", bScanner);

            var more = true;
            while (more)
            {
                var scan = client.nextK(scanId, 10);
                more = scan.More;
                foreach (var entry in scan.Results)
                {
                    Console.WriteLine("{0} {1}:{2} [{3}]  {4}", GetString(entry.Key.Row), GetString(entry.Key.ColFamily), GetString(entry.Key.ColQualifier), GetString(entry.Key.ColVisibility), GetString(entry.Value));
                }
            }

            client.closeScanner(scanId);
            Console.WriteLine();
            /** Get data end **/
        }
        catch (Exception e)
        {
            Console.WriteLine(e);
        }
    }
}

Accumulo 1.5 的用户手册显示了这个代码片段,这与我正在做的相同(但在 C# 中):(http://accumulo.apache.org/1.5/accumulo_user_manual.html#_basic_table

Range r = new Range(userid, userid); // single row
Scanner s = conn.createScanner("userdata", auths);
s.setRange(r);
s.fetchColumnFamily(new Text("age"));

for(Entry<Key,Value> entry : s)
    System.out.println(entry.getValue().toString());
4

2 回答 2

3

问题可能出在您的范围内。在 Java API 中,您可以为单行构造 Range,其中:

Range r = new Range("myRow");

在 thrift Proxy API 中,您只能将 Keys 提供给 Range 构造函数,而不仅仅是 RowID(这也是 Java API 中的一个选项,但它是 Proxy API 中的唯一选项)。键代表单个条目,因此扫描:

R1:CF1:CQ1:CV1 -> R1:CF1:CQ1:CV1

只会对那个确切的条目进行扫描(如果您没有为表配置 VersioningIterator,可能还有它的所有版本)。

因此,如果要扫描“a”行中的所有条目,则不要像这样扫描:

"a":null:null:null(inclusive) -> "a":null:null:null(inclusive)

相反,您可以像这样扫描 row == "a":

"a":null:null:null(inclusive) -> "a\0":null:null:null(exclusive)

或者这个,对于 row startsWith "a":

"a":null:null:null(inclusive) -> "b":null:null:null(exclusive)
于 2013-09-29T05:25:19.213 回答
0

您是否已经在这里检查过这种可能性? https://issues.apache.org/jira/browse/ACCUMULO-1189 它已在 Accumulo 1.5 中修复,您使用的是 1.4,所以看起来值得一看。

于 2013-09-27T18:14:42.577 回答