我正在尝试从MVC站点更新Hbase中的行。我使用的是Thrift4.5,我找到的最好的解决方案就是使用.NET包和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();
}虽然这会在给定的列中创建一个新图像,但我还没有找到覆盖现有列的方法。有没有人成功地做到了这一点,或者有没有其他我应该使用的客户端工具来实现我的目标?
发布于 2016-09-06 21:12:47
我无法让这个设置正常工作,所以我继续使用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);
}https://stackoverflow.com/questions/39215348
复制相似问题