2010-03-06 57 views
2

如何在C#/ VB.NET中使用Hbase數據庫? (使用=連接,查詢,獲得結果,插入,更新,刪除)使用Hbase和C#

我沒有找到有用的答案與谷歌。

回答

4

我剛剛發佈了HBase C#Thrift綁定作爲nuget包。 另外,你可以從bitbucket抓取代碼/二進制文件:https://bitbucket.org/vadim/hbase-sharp/downloads

+0

這就是偉大的瓦迪姆運行!它似乎已經很老了。我在哪裏可以獲得HBase-Sharp的更新版本以支持HBase的最新版本? – 2015-02-03 08:56:38

2

description

一個REST-FUL Web服務網關 支持XML,的Protobuf和二進制 數據編碼選項

有一個protobuf port for .NET,有許多XML操作的API內置。

0

HBase C#Thrift很好用。只需在Windows機器上下載最新的thrift-0.9.2.exe,thrift.dll和Hbase.thrift文件即可。您可以生成使用以下命令所需的C#文件:

thrift-0.9.2.exe -gen csharp Hbase.thrift 

你會得到以下文件的結果:

AlreadyExists.cs 
BatchMutation.cs 
ColumnDescriptor.cs 
Hbase.cs 
IllegalArgument.cs 
IOError.cs 
Mutation.cs 
TAppend.cs 
TCell.cs 
TColumn.cs 
TIncrement.cs 
TRegionInfo.cs 
TRowResult.cs 
TScan.cs 

包括他們在您的項目,thrift.dll添加到您的項目引用。簡短的示例代碼(清單表和插入/更新單元格值):

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Thrift.Protocol; 
using Thrift.Transport; 

namespace bdc 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     {    
      // Connection 
      var socket = new TSocket("hdp1.localdomain", 9090); 
      var transport =new TBufferedTransport(socket); 
      var protocol = new TBinaryProtocol(transport); 
      Hbase.Client hba = new Hbase.Client(protocol); 
      transport.Open();    

      // Get table names 
      Console.WriteLine("<-GET LIST OF TABLES->");  
      var tableNames = hba.getTableNames(); 
      foreach (var tableName in tableNames) 
      Console.WriteLine(Encoding.UTF8.GetString(tableName, 0, tableName.Length));    

      // Insert rows  
      Console.WriteLine("<-INSERT->");  
      Mutation _mutation = new Mutation(); 
      _mutation.IsDelete = false; 
      _mutation.Column = Encoding.UTF8.GetBytes("image:bodyimage"); 
      _mutation.Value = Encoding.UTF8.GetBytes("newnew image 2.jpg"); 

      hba.mutateRow(Encoding.UTF8.GetBytes("blogposts"), Encoding.UTF8.GetBytes("post1"), new List<Mutation> { _mutation }, null); 

      // Finished 
      Console.WriteLine("<-FINISHED->"); 
      Console.ReadKey();       
     }   
    } 
} 

上面的代碼工作很好地與HBase的安裝最新的Hortonworks數據平臺,在CentOS 7

+0

不幸的是,至於thrift-0.9.3.exe,我沒有得到TAppend,TColumn或TIncrement文件,我在VS中收到關於名稱空間TException未找到的異常。 – SDillon 2015-10-27 12:00:18

+0

我也從版本0.9.2中獲得了相同的結果。 – SDillon 2015-10-27 12:18:48

+1

我沒有用0.9.3做全面測試(但會在幾天內完成)。雖然我測試了最新0.9.3的命令(生成cs文件),但它工作正常。我得到了所有的文件。請嘗試從http://svn.apache.org/viewvc/hbase/trunk/hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift?revision下載Hbase.thrift。 = 1590152&view = co – user3330535 2015-10-27 21:38:02