I am trying to update a row in Hbase from a MVC site. I am using .NET 4.5 and the best solution I have found to do this is using the Thrift package and Hbase.Thrift to do this.
I have :
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();
}
While this creates a new image in a given column I have not found a way for it to overwrite and existing column. Has anyone successfully pulled this off or is there another client tool I should be using to achieve what I am going for?
I was unable to get this setup to work so I went on to use Hbase Rest. Here is the code for the future lost souls looking for the solution as I was.
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);
}