getTableNames() public méthode

public getTableNames ( ) : List
Résultat List
Exemple #1
0
        static void Main(string[] args)
        {
            // Connection
            var socket    = new TSocket("hdp1.localdomain", 9090);
            var transport = new TBufferedTransport(socket);
            var protocol  = new TBinaryProtocol(transport);

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

            // Get table names
            Console.WriteLine("<-GET LIST OF TABLES->");
            var tableNames = hba.getTableNames();

            foreach (var tableName in tableNames)
            {
                Console.WriteLine(Encoding.UTF8.GetString(tableName, 0, tableName.Length));
            }

            // Insert rows
            Console.WriteLine("<-INSERT->");
            Mutation _mutation = new Mutation();

            _mutation.IsDelete = false;
            _mutation.Column   = Encoding.UTF8.GetBytes("image:bodyimage");
            _mutation.Value    = Encoding.UTF8.GetBytes("newnew image 2.jpg");

            hba.mutateRow(Encoding.UTF8.GetBytes("blogposts"), Encoding.UTF8.GetBytes("post1"), new List <Mutation> {
                _mutation
            }, null);

            // Finished
            Console.WriteLine("<-FINISHED->");
            Console.ReadKey();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            TSerializer.RegisterSerializer(new SelfTSerializer());

            Man man = new Man();

            man.Name = "李金川";
            man.Sex  = 1;
            man.Age  = 30;
            man.Fei  = new int[] { 1, 2, 3 };
            man.Addr = new List <string> {
                "老师", "学生", "朋友"
            };
            Thrift2ClientWarpper.Put <Man>("hbaseclient1", "test", "man", man.Name, man, (m) =>
            {
                var tps  = LJC.FrameWork.EntityBuf.EntityBufCore.GetTypeEntityBufType(typeof(Man));
                var list = new List <KeyValuePair <string, object> >();
                foreach (Tuple <LJC.FrameWork.EntityBuf.EntityBufType, bool> it in tps)
                {
                    list.Add(new KeyValuePair <string, object>(it.Item1.Property.PropertyInfo.Name, it.Item1.Property.PropertyInfo.GetValue(m)));
                }
                return(list);
            });

            Thrift2ClientWarpper.CheckAndDelete("hbaseclient1", "test", man.Name, "man", "Name", "李金川", new[] { "Sex" });
            var resultljc = Thrift2ClientWarpper.Get <Man>("hbaseclient1", "test", man.Name, (t, s) =>
            {
                var tps = LJC.FrameWork.EntityBuf.EntityBufCore.GetTypeEntityBufType(t);
                var pop = tps.First(p => p.Item1.Property.PropertyInfo.Name.Equals(s));

                return(pop.Item1.Property.PropertyInfo);
            });


            man.Name = "张三丰";
            man.Age  = 100;
            Thrift2ClientWarpper.Append <Man>("hbaseclient1", "test", man.Name, "man", man, (m) =>
            {
                var tps  = LJC.FrameWork.EntityBuf.EntityBufCore.GetTypeEntityBufType(typeof(Man));
                var list = new List <KeyValuePair <string, object> >();
                foreach (Tuple <LJC.FrameWork.EntityBuf.EntityBufType, bool> it in tps)
                {
                    list.Add(new KeyValuePair <string, object>(it.Item1.Property.PropertyInfo.Name, it.Item1.Property.PropertyInfo.GetValue(m)));
                }
                return(list);
            });

            Thrift2ClientWarpper.Delete("hbaseclient1", "test", man.Name);

            var result = Thrift2ClientWarpper.Get <Man>("hbaseclient1", "test", man.Name, (t, s) =>
            {
                var tps = LJC.FrameWork.EntityBuf.EntityBufCore.GetTypeEntityBufType(t);
                var pop = tps.First(p => p.Item1.Property.PropertyInfo.Name.Equals(s));

                return(pop.Item1.Property.PropertyInfo);
            });

            return;


            TTransport transport = null;

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

                Console.Write("已连接上");
                //client.disableTable(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat"));
                //client.deleteTable(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat"));
                //client.createTable(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat"), new List<ColumnDescriptor> { new ColumnDescriptor { Name = Encoding.UTF8.GetBytes("col1") } });
                //Console.Write("创建表");

                //var boo=client.checkAndPut(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat"), Encoding.UTF8.GetBytes("201310_001_0_1100"), Encoding.UTF8.GetBytes("col1"), Encoding.UTF8.GetBytes("val"), null, null);
                //Console.WriteLine("写数据:" + boo);

                //根据表名,RowKey名来获取结果集
                //List<TRowResult> reslut = client.getRow(Encoding.UTF8.GetBytes("dz_CDN_Ip_Stat"), Encoding.UTF8.GetBytes("row1"), null);
                //Console.WriteLine("读数据:" + reslut.Count);

                ////遍历结果集
                //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("Family:Qualifier:" + "\n" + Encoding.UTF8.GetString(k.Key));
                //        Console.WriteLine("Value:" + Encoding.UTF8.GetString(k.Value.Value));
                //    }
                //}

                var tables = client.getTableNames();


                foreach (var bi in tables)
                {
                    transport.Close();
                    transport.Open();
                    client.disableTable(bi);
                    client.deleteTable(bi);

                    //var tb = Encoding.UTF8.GetString(bi);
                    //Console.WriteLine(tb);
                    //transport.Close();
                    //transport.Open();
                    //var dic = client.getColumnDescriptors(bi);
                    //foreach (var kv in dic)
                    //{
                    //    Console.WriteLine(string.Format("{0}:{1}", Encoding.UTF8.GetString(kv.Key), Encoding.UTF8.GetString(kv.Value.Name)));
                    //}
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e);
            }
            finally
            {
                if (null != transport)
                {
                    transport.Close();
                }
            }
            Console.ReadLine();
        }
    protected void 创建数据表_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();


            #region 创建表
            //判断 表是不是存在
            if (!client.getTableNames().Select(p => p.ToUTF8String()).Contains(txt表名.Text))
            {
                //数据列
                var cols = new List <ColumnDescriptor>();

                foreach (var item in txt列名集合.Text.Split(','))
                {
                    //创建列
                    if (!string.IsNullOrEmpty(item))
                    {
                        string coln = item;
                        if (!coln.Contains(":"))
                        {
                            coln = item + ":";
                        }
                        var col = new ColumnDescriptor()
                        {
                            Name = coln.ToUTF8Bytes(), MaxVersions = 3
                        };

                        cols.Add(col);
                    }
                }

                //创建数据表
                client.createTable(txt表名.Text.ToUTF8Bytes(), cols);
                lab创建表信息状态.Text = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;创建成功..";
            }
            else
            {
                lab创建表信息状态.Text = "创建失败..表:" + txt表名.Text + "已经存在";
                //return;
            }

            //向表里加数据
            #region 向表里加数据

            当前创建表示例(txt表名.Text, client);

            #endregion


            当前所有表(client);


            #endregion
        }
        catch (Exception ex)
        {
            lab创建表信息状态.Text  = "创建失败..";
            lab创建表信息状态.Text += ex;
        }

        finally
        {
            if (transport != null)
            {
                transport.Close();
            }
        }
    }
 /// <summary>
 /// 当前数据库所有表
 /// </summary>
 public void 当前所有表(Hbase.Client client)
 {
     gri当前数据库所有表.DataSource = client.getTableNames().Select(p => p.ToUTF8String());
     gri当前数据库所有表.DataBind();
 }
Exemple #5
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();
            }
        }
    }
Exemple #6
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();
            }
        }
    }