使用 Thrift 和 Hbase.Thrift 更新 Hbase 行
Updating Hbase row with Thrift and Hbase.Thrift
我正在尝试从 MVC 站点更新 Hbase 中的一行。我正在使用 .NET 4.5,我发现最好的解决方案是使用 Thrift 包和 Hbase.Thrift 来做到这一点。
我有:
private static Hbase.Client _hbase; //this is actually a class header
var socket = new TSocket("localhost",9090);
var transport = new TBufferedTransport(socket);
var proto = new TBinaryProtocol(transport);
_hbase = new Hbase.Client(proto);
try
{
transport.Open();
_hbase.mutateRows(Encoding.UTF8.GetBytes("Images"), new List<BatchMutation>()
{
new BatchMutation()
{
Row = Guid.NewGuid().ToByteArray(),
Mutations = new List<Mutation> {
new Mutation{Column = Encoding.UTF8.GetBytes("Image"), IsDelete = false, Value = Encoding.UTF8.GetBytes(testImage) }
}
}
});
transport.Close();
}
虽然这会在给定列中创建新图像,但我还没有找到覆盖现有列的方法。有没有人成功解决这个问题,或者我应该使用另一个客户端工具来实现我的目标?
我无法让这个设置工作,所以我继续使用 Hbase Rest。这是为未来迷失的灵魂寻找解决方案的代码。
System.Diagnostics.Debug.WriteLine("Hbase_update");
//check your port number to make sure you have the right one
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://localhost:8080/Images/" + key + "?data=");
request.Method = "PUT";
//NOTE:The name of the column I am pushing to is int the Column Family "Image" and column "Binary"
string requestStr = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><CellSet><Row key=""" + Convert.ToBase64String(Encoding.UTF8.GetBytes(key)) + @"""><Cell column=""" + Convert.ToBase64String(Encoding.UTF8.GetBytes("Image:Binary")) + @""">"+ imageBinary + @"</Cell></Row></CellSet>";
var data = Encoding.ASCII.GetBytes(requestStr);
request.Accept = "text/xml";
request.ContentType = "text/xml; encoding='utf-8'";
request.ContentLength = data.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
try
{
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
System.Diagnostics.Debug.WriteLine(responseString);
}
catch (System.Net.WebException e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}
我正在尝试从 MVC 站点更新 Hbase 中的一行。我正在使用 .NET 4.5,我发现最好的解决方案是使用 Thrift 包和 Hbase.Thrift 来做到这一点。
我有:
private static Hbase.Client _hbase; //this is actually a class header
var socket = new TSocket("localhost",9090);
var transport = new TBufferedTransport(socket);
var proto = new TBinaryProtocol(transport);
_hbase = new Hbase.Client(proto);
try
{
transport.Open();
_hbase.mutateRows(Encoding.UTF8.GetBytes("Images"), new List<BatchMutation>()
{
new BatchMutation()
{
Row = Guid.NewGuid().ToByteArray(),
Mutations = new List<Mutation> {
new Mutation{Column = Encoding.UTF8.GetBytes("Image"), IsDelete = false, Value = Encoding.UTF8.GetBytes(testImage) }
}
}
});
transport.Close();
}
虽然这会在给定列中创建新图像,但我还没有找到覆盖现有列的方法。有没有人成功解决这个问题,或者我应该使用另一个客户端工具来实现我的目标?
我无法让这个设置工作,所以我继续使用 Hbase Rest。这是为未来迷失的灵魂寻找解决方案的代码。
System.Diagnostics.Debug.WriteLine("Hbase_update");
//check your port number to make sure you have the right one
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://localhost:8080/Images/" + key + "?data=");
request.Method = "PUT";
//NOTE:The name of the column I am pushing to is int the Column Family "Image" and column "Binary"
string requestStr = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?><CellSet><Row key=""" + Convert.ToBase64String(Encoding.UTF8.GetBytes(key)) + @"""><Cell column=""" + Convert.ToBase64String(Encoding.UTF8.GetBytes("Image:Binary")) + @""">"+ imageBinary + @"</Cell></Row></CellSet>";
var data = Encoding.ASCII.GetBytes(requestStr);
request.Accept = "text/xml";
request.ContentType = "text/xml; encoding='utf-8'";
request.ContentLength = data.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(data, 0, data.Length);
dataStream.Close();
try
{
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
System.Diagnostics.Debug.WriteLine(responseString);
}
catch (System.Net.WebException e)
{
System.Diagnostics.Debug.WriteLine(e.Message);
}