使用thrift和hbase.thrift更新hbase行

3ks5zfa0  于 2021-06-10  发布在  Hbase
关注(0)|答案(1)|浏览(478)

我正在尝试从mvc站点更新hbase中的一行。我使用的是.NET4.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();
        }

虽然这会在给定的列中创建一个新图像,但我还没有找到一种方法让它覆盖现有的列。有没有人成功地做到了这一点,或者有没有其他的客户端工具,我应该使用来实现我的目标?

li9yvcax

li9yvcax1#

我无法让这个设置工作,所以我继续使用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);
        }

相关问题