createTable() public method

public createTable ( byte tableName, List columnFamilies ) : void
tableName byte
columnFamilies List
return void
示例#1
0
        static void _CreateDataBase(string baseName, string columnFamily)
        {
            if (string.IsNullOrWhiteSpace(baseName))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(columnFamily))
            {
                return;
            }

            var socket    = null as TSocket;
            var transport = null as TBufferedTransport;

            try
            {
                // Сделаем вычисление апи хоста по базе данных
                socket    = new TSocket(getHost(baseName, columnFamily), Port);
                transport = new TBufferedTransport(socket);
                var proto = new TBinaryProtocol(transport);
                var hbase = new Hbase.Client(proto);

                transport.Open();

                hbase.createTable(
                    getBaseTableHbase(baseName, columnFamily),
                    new List <ColumnDescriptor>()
                {
                    new ColumnDescriptor {
                        Name = getAttrNameHbase(columnFamily), BlockCacheEnabled = true, MaxVersions = 1, InMemory = true
                    }
                });
            }
            finally
            {
                if (transport != null)
                {
                    transport.Close();
                    transport = null;
                }
            }
        }
    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();
            }
        }
    }
示例#3
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();
            }
        }
    }