2013-09-27 40 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