getRow() публичный Метод

public getRow ( byte tableName, byte row ) : List
tableName byte
row byte
Результат List
Пример #1
0
 /// <summary>
 /// 读取单行
 /// </summary>
 public static void getattachmentSingle()
 {
     //     TTransport transport = null;
     try
     {
         tablename = table2name;
         //打开连接
         transport.Open();
         string rowkey = "k1";
         //根据表名,RowKey名来获取结果集
         List <TRowResult> reslut = client.getRow(Encoding.UTF8.GetBytes(tablename), Encoding.UTF8.GetBytes(rowkey), null);
         //遍历结果集
         foreach (var key in reslut)
         {
             Console.WriteLine("RowKey:\n{0}", Encoding.UTF8.GetString(key.Row));
             //打印Qualifier和对应的Value
             foreach (var k in key.Columns)
             {
                 Console.WriteLine("******************" + "\n" + Encoding.UTF8.GetString(k.Key));
                 Console.WriteLine("Value:" + Encoding.UTF8.GetString(k.Value.Value));
             }
         }
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e);
     }
     finally
     {
         if (null != transport)
         {
             transport.Close();
         }
     }
 }
Пример #2
0
        public void GetHBaseImage(string rowKey = "20150822180801118")
        {
            var socket = new TSocket(hbaseThrif, hbaseThrifPort);
            var transport = new TBufferedTransport(socket);
            var protocol = new TBinaryProtocol(transport);
            Hbase.Client hbaseClient = new Hbase.Client(protocol);
            transport.Open();

            //List<byte[]> tableNames = hc.getTableNames();

            byte[] table = Encoding.UTF8.GetBytes("FiservImages");
            byte[] row = Encoding.UTF8.GetBytes(rowKey);
            byte[] column = Encoding.UTF8.GetBytes("ImageData:Image");

            List<TRowResult> results = hbaseClient.getRow(table, row, null);
            TCell t = new TCell();
            //t.

            foreach (TRowResult result in results)
            {
                //result.Columns[column]
                //result.Columns;
                Dictionary<byte[], TCell> konj;
                konj = result.Columns;

                //string s = Encoding.UTF8.GetString(result.Columns[column].Value);

                foreach (KeyValuePair<byte[], TCell> singleRow in konj)
                {
                    //File.WriteAllBytes(@"c:\test\output.docx", singleRow.Value.Value);
                    OpenFile(singleRow.Value.Value, "output.docx");
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 读取Hbase数据
        /// </summary>
        /// <param name="tempList"></param>
        /// <param name="IPAddress"></param>
        /// <param name="Port"></param>
        /// <param name="strTableName"></param>
        /// <returns></returns>
        public static Dictionary <string, string> ReadKeyHbaseData(List <string> tempList, string IPAddress, int Port,
                                                                   string strTableName)
        {
            Dictionary <string, string> dis = new Dictionary <string, string>();

            try
            {
                int count = 0;
                if (transport == null)
                {
                    transport = new TSocket(IPAddress, Port);
                }

                //实例化一个协议对象
                TProtocol tProtocol = new TBinaryProtocol(transport);
                //实例化一个Hbase的Client对象
                var client = new Hbase.Client(tProtocol);
                //打开连接
                transport.Open();
                foreach (var temp in tempList)
                {
                    //根据表名,RowKey名来获取结果集
                    var reslut = client.getRow(Encoding.UTF8.GetBytes(strTableName),
                                               Encoding.UTF8.GetBytes(temp), null);
                    foreach (var keys in reslut)
                    {
                        foreach (var k in keys.Columns)
                        {
                            if (dis.ContainsKey(Encoding.UTF8.GetString(keys.Row)))
                            {
                                continue;
                            }
                            dis.Add(Encoding.UTF8.GetString(keys.Row), Encoding.UTF8.GetString(k.Value.Value));
                            ++count;
                            //LoggerManager.Create().InfoWrite(string.Format("已下载{0}条记录", ++count));
                            if (count % 1000 != 0)
                            {
                                continue;
                            }
                            LoggerManager.Create().InfoWrite(string.Format("已下载指定RowKey{0}条", count));
                        }
                    }
                }
                LoggerManager.Create().InfoWrite(string.Format("Hbases下载指定数据成功,共下载数据{0}条", count));
            }
            catch (Exception ex)
            {
                LoggerManager.Create().ErrorWrite(string.Format("Hbase读取指定数据失败,错误信息:{0}", ex.Message));
            }
            finally
            {
                if (transport != null)
                {
                    transport.Close();
                }
            }
            return(dis);
        }
Пример #4
0
        public Dictionary <byte[], TCell> GetHBaseImage()
        {
            var socket    = new TSocket(_hbaseThrif, _hbaseThrifPort);
            var transport = new TBufferedTransport(socket);
            var protocol  = new TBinaryProtocol(transport);

            Hbase.Client hbaseClient = new Hbase.Client(protocol);
            Dictionary <byte[], TCell> hbaseResult = new Dictionary <byte[], TCell>();

            transport.Open();

            //List<byte[]> tableNames = hc.getTableNames();

            byte[] table  = Encoding.UTF8.GetBytes("FiservImages");
            byte[] row    = Encoding.UTF8.GetBytes(_documentId);
            byte[] column = Encoding.UTF8.GetBytes("ImageData:Image");

            List <TRowResult> results = hbaseClient.getRow(table, row, null);
            TCell             t       = new TCell();

            //t.

            foreach (TRowResult result in results)
            {
                //result.Columns[column]
                //result.Columns;

                hbaseResult = result.Columns;

                //string s = Encoding.UTF8.GetString(result.Columns[column].Value);

                //foreach (KeyValuePair<byte[], TCell> singleRow in konj)
                //{
                //    //File.WriteAllBytes(@"c:\test\output.docx", singleRow.Value.Value);
                //    Main a = new Main();
                //    a.OpenFile(singleRow.Value.Value, "output.docx");
                //}
            }
            return(hbaseResult);
        }
Пример #5
0
        public Dictionary<byte[], TCell> GetHBaseImage()
        {
            var socket = new TSocket(_hbaseThrif, _hbaseThrifPort);
            var transport = new TBufferedTransport(socket);
            var protocol = new TBinaryProtocol(transport);
            Hbase.Client hbaseClient = new Hbase.Client(protocol);
            Dictionary<byte[], TCell> hbaseResult = new Dictionary<byte[], TCell>();
            transport.Open();

            //List<byte[]> tableNames = hc.getTableNames();

            byte[] table = Encoding.UTF8.GetBytes("FiservImages");
            byte[] row = Encoding.UTF8.GetBytes(_documentId);
            byte[] column = Encoding.UTF8.GetBytes("ImageData:Image");

            List<TRowResult> results = hbaseClient.getRow(table, row, null);
            TCell t = new TCell();
            //t.

            foreach (TRowResult result in results)
            {
                //result.Columns[column]
                //result.Columns;

                hbaseResult = result.Columns;

                //string s = Encoding.UTF8.GetString(result.Columns[column].Value);

                //foreach (KeyValuePair<byte[], TCell> singleRow in konj)
                //{
                //    //File.WriteAllBytes(@"c:\test\output.docx", singleRow.Value.Value);
                //    Main a = new Main();
                //    a.OpenFile(singleRow.Value.Value, "output.docx");
                //}
            }
            return hbaseResult;
        }
Пример #6
0
        public void GetHBaseImage(string rowKey = "20150822180801118")
        {
            var socket    = new TSocket(hbaseThrif, hbaseThrifPort);
            var transport = new TBufferedTransport(socket);
            var protocol  = new TBinaryProtocol(transport);

            Hbase.Client hbaseClient = new Hbase.Client(protocol);
            transport.Open();

            //List<byte[]> tableNames = hc.getTableNames();

            byte[] table  = Encoding.UTF8.GetBytes("FiservImages");
            byte[] row    = Encoding.UTF8.GetBytes(rowKey);
            byte[] column = Encoding.UTF8.GetBytes("ImageData:Image");

            List <TRowResult> results = hbaseClient.getRow(table, row, null);
            TCell             t       = new TCell();

            //t.

            foreach (TRowResult result in results)
            {
                //result.Columns[column]
                //result.Columns;
                Dictionary <byte[], TCell> konj;
                konj = result.Columns;

                //string s = Encoding.UTF8.GetString(result.Columns[column].Value);

                foreach (KeyValuePair <byte[], TCell> singleRow in konj)
                {
                    //File.WriteAllBytes(@"c:\test\output.docx", singleRow.Value.Value);
                    OpenFile(singleRow.Value.Value, "output.docx");
                }
            }
        }
Пример #7
0
    /// <summary>
    /// 获取数据,列表行
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Button5_Click1(object sender, EventArgs e)
    {
        string table = "abc";
        string key   = "aaaK";

        TTransport transport = null;

        try
        {
            //192.168.2.111:60010
            //实例化Socket连接
            transport = new TSocket("192.168.2.111", 9090);
            //实例化一个协议对象
            TProtocol tProtocol = new TBinaryProtocol(transport);
            //实例化一个Hbase的Client对象
            var client = new Hbase.Client(tProtocol);
            //打开连接
            transport.Open();

            //遍历结果集
            List <string> sss = new List <string>();
            foreach (var item in System.Linq.Enumerable.Range(1, 10))
            {
                string skey = (key + "_" + item);
                string scol = ("你好中文:" + item);
                string svla = (Guid.NewGuid().ToString());
                ///////////////删除单元格数据
                byte[] tableName = table.ToUTF8Bytes();
                byte[] row       = skey.ToUTF8Bytes();
                Dictionary <byte[], byte[]> encodedAttributes = new Dictionary <byte[], byte[]>();


                //获取表名:
                foreach (var itema in client.getTableNames())
                {
                    var strs = System.Text.ASCIIEncoding.ASCII.GetString(itema);
                    sss.Add("表名:" + strs);

                    //根据表名,RowKey名来获取结果集
                    List <TRowResult> reslut = client.getRow(Encoding.UTF8.GetBytes(strs), Encoding.UTF8.GetBytes(skey), null);
                    foreach (var keys in reslut)
                    {
                        sss.Add(string.Format("&nbsp;&nbsp;RowKey:\n{0}", Encoding.UTF8.GetString(keys.Row)));
                        //打印Qualifier和对应的Value
                        foreach (var k in keys.Columns)
                        {
                            sss.Add(string.Format("&nbsp;&nbsp;&nbsp;Family:Qualifier:" + "\n" + Encoding.UTF8.GetString(k.Key)));
                            sss.Add(string.Format("&nbsp;&nbsp;&nbsp;Value:" + Encoding.UTF8.GetString(k.Value.Value)));
                        }
                    }
                }
            }

            GridView1.DataSource = sss;
            GridView1.DataBind();
        }


        finally
        {
            if (transport != null)
            {
                transport.Close();
            }
        }
    }
Пример #8
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        TTransport transport = null;

        try
        {
            //192.168.2.111:60010
            //实例化Socket连接
            transport = new TSocket("192.168.2.111", 9090);
            //实例化一个协议对象
            TProtocol tProtocol = new TBinaryProtocol(transport);
            //实例化一个Hbase的Client对象

            var client = new Hbase.Client(tProtocol);



            //打开连接

            transport.Open();

            //判断 表是不是存在
            if (!client.getTableNames().Select(p => p.ToUTF8String()).Contains("abc"))
            {
                //创建数据表
                client.createTable("abc".ToUTF8Bytes(), new List <ColumnDescriptor>()
                {
                    new ColumnDescriptor()
                    {
                        Name = "你好中文".ToUTF8Bytes(), BloomFilterVectorSize = 30,
                    },
                    new ColumnDescriptor()
                    {
                        Name = "aa".ToUTF8Bytes(), BloomFilterVectorSize = 30,
                    }
                });
            }

            //向表里加数据
            #region 向表里加数据
            //代码错误.不会用
            //client.m("abc".ToUTF8Bytes(), new List<BatchMutation>() {
            //     new BatchMutation() { Mutations= new List<Mutation>() {
            //                        new Mutation() {  Column="你好中文".ToUTF8Bytes(), Value="我是,".ToUTF8Bytes() },
            //                        new Mutation() {  Column="aa".ToUTF8Bytes(), Value="我是,111".ToUTF8Bytes() },
            //                        new Mutation() {  Column="你好中文".ToUTF8Bytes(), Value="我是,Habse".ToUTF8Bytes() },

            //     }
            //     ,  Row = "aaaa_1".ToUTF8Bytes(),


            //      }

            //}, new Dictionary<byte[], byte[]>());
            client.mutateRow("abc".ToUTF8Bytes(), "aaaa_1".ToUTF8Bytes(), new List <Mutation>()
            {
                new Mutation()
                {
                    Column = "你好中文:11".ToUTF8Bytes(), Value = "abcdef".ToUTF8Bytes()
                }
            }, new Dictionary <byte[], byte[]>());

            #endregion


            //遍历结果集
            List <string> sss = new List <string>();

            //获取表名:
            foreach (var item in client.getTableNames())
            {
                var strs = System.Text.ASCIIEncoding.ASCII.GetString(item);
                sss.Add("表名:" + strs);
                //根据表名,RowKey名来获取结果集



                List <TRowResult> reslut = client.getRow(Encoding.UTF8.GetBytes(strs), Encoding.UTF8.GetBytes("aaaa_1"), null);

                foreach (var key in reslut)
                {
                    sss.Add(string.Format("&nbsp;&nbsp;RowKey:\n{0}", Encoding.UTF8.GetString(key.Row)));
                    //打印Qualifier和对应的Value
                    foreach (var k in key.Columns)
                    {
                        sss.Add(string.Format("&nbsp;&nbsp;&nbsp;Family:Qualifier:" + "\n" + Encoding.UTF8.GetString(k.Key)));
                        sss.Add(string.Format("&nbsp;&nbsp;&nbsp;Value:" + Encoding.UTF8.GetString(k.Value.Value)));
                    }
                }
            }
            GridView1.DataSource = sss;
            GridView1.DataBind();
        }

        catch (Exception exxx)

        {
            Response.Write(exxx);
        }

        finally

        {
            if (null != transport)

            {
                transport.Close();
            }
        }
    }