2013-09-27 44 views
3

我无法获得一个批处理扫描程序只扫描特定的行,当设置开始和停止键到同一件事情时我得不到条目的回来,当使用扫描仪我得到这个异常:Accumulo createBatchScanner范围不按预期工作

“java.lang.IllegalArgumentException异常:启动键必须大于结束键在较少范围(测试:[] 0假,测试:[] 0假)” ...

我写在Visual Studio 2010中使用C#,并在项目中使用Thrift(ver 0.9.1.1)和Accumulo(ver 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()); 

回答

3

问题可能是您的范围。在Java API,你可以构造一个范围为单列,带:

Range r = new Range("myRow"); 

在节俭代理API,你只能给钥匙的范围构造函数,而不是仅仅的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) 

相反,你扫描这样的排==“一”:

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

或者这一点,排startsWith“一”:

"a":null:null:null(inclusive) -> "b":null:null:null(exclusive) 
+1

谢谢,现在我得到它的工作:D我刚刚添加\ 0到Range.Stop的末尾。 – loliman

0

你已经在这里检查过这种可能吗? https://issues.apache.org/jira/browse/ACCUMULO-1189 它被固定在Accumulo 1.5中,你使用1.4,所以看起来很值得一看。

+0

我用Accumulo 1.5,我可以使用createScanner和createBatchScanner,但与具有相同启动了一系列nd停止键。 – loliman