Ejemplo n.º 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                #region Creating connection

                HBaseConnection con = new HBaseConnection("localhost", 10003);
                con.Open();

                #endregion Creating connection

                #region Creating table

                string        tableName      = "AdventureWorks_Person_Contact";
                List <string> columnFamilies = new List <string>();
                columnFamilies.Add("info");
                columnFamilies.Add("contact");
                columnFamilies.Add("others");

                if (!HBaseOperation.IsTableExists(tableName, con))
                {
                    if (columnFamilies.Count > 0)
                    {
                        HBaseOperation.CreateTable(tableName, columnFamilies, con);
                    }
                    else
                    {
                        throw new HBaseException("ERROR: Table must have at least one column family");
                    }
                }

                # endregion

                #region Inserting Values

                #region Parsing csv input file

                csv csvObj = new csv();
                object[,] cells;
                cells = null;
                string path = System.AppDomain.CurrentDomain.BaseDirectory;
                cells = csvObj.Table(path + "..\\..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", false, ',');

                #endregion Parsing csv input file

                string[] column = new string[] { "CONTACTID", "FULLNAME", "AGE", "EMAILID", "PHONE", "MODIFIEDDATE" };
                Dictionary <string, IList <HMutation> > rowCollection = new Dictionary <string, IList <HMutation> >();
                string rowKey;

                for (int i = 0; i < cells.GetLength(0); i++)
                {
                    List <HMutation> mutations = new List <HMutation>();
                    rowKey = cells[i, 0].ToString();

                    for (int j = 1; j < column.Length; j++)
                    {
                        HMutation mutation = new HMutation();
                        mutation.ColumnFamily = j < 3 ? "info" : j < 5 ? "contact" : "others";
                        mutation.ColumnName   = column[j];
                        mutation.Value        = cells[i, j].ToString();
                        mutations.Add(mutation);
                    }

                    rowCollection[rowKey] = mutations;
                }

                HBaseOperation.InsertRows(tableName, rowCollection, con);

                #endregion Inserting Values

                #region Fetch result

                HBaseOperation.FetchSize = 100;
                HBaseResultSet result = HBaseOperation.ScanTable(tableName, con);

                #endregion Fetch result

                BindingList <adventureworks_person_contact> resultList = new BindingList <adventureworks_person_contact>();

                //Read each row from the fetched result
                foreach (HBaseRecord row in result)
                {
                    resultList = new BindingList <adventureworks_person_contact>(result.Select(rowvalue => new adventureworks_person_contact
                    {
                        CONTACTID    = rowvalue["rowKey"].ToString(),
                        FULLNAME     = rowvalue["info:FULLNAME"] != null ? rowvalue["info:FULLNAME"].ToString() : "",
                        AGE          = rowvalue["info:AGE"] != null ? rowvalue["info:AGE"].ToString() : "",
                        EMAILID      = rowvalue["contact:EMAILID"] != null ? rowvalue["contact:EMAILID"].ToString() : "",
                        PHONE        = rowvalue["contact:PHONE"] != null ? rowvalue["contact:PHONE"].ToString() : "",
                        MODIFIEDDATE = rowvalue["others:MODIFIEDDATE"] != null ? rowvalue["others:MODIFIEDDATE"].ToString() : "",
                    }).ToList());
                }

                //Binding the result to the grid
                gridGroupingControl1.DataSource = resultList;
                gridGroupingControl1.TableDescriptor.Columns["CONTACTID"].Width    = 85;
                gridGroupingControl1.TableDescriptor.Columns["FULLNAME"].Width     = 170;
                gridGroupingControl1.TableDescriptor.Columns["AGE"].Width          = 90;
                gridGroupingControl1.TableDescriptor.Columns["EMAILID"].Width      = 230;
                gridGroupingControl1.TableDescriptor.Columns["PHONE"].Width        = 170;
                gridGroupingControl1.TableDescriptor.Columns["MODIFIEDDATE"].Width = 170;
                //Closing the HBase connection
                con.Close();
            }
Ejemplo n.º 2
0
        private void BindDataSource()
        {
            ErrorMessage.InnerText = "";
            string path = string.Format("{0}\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv", Request.PhysicalPath.ToLower().Split(new string[] { "\\c# hbase samples" }, StringSplitOptions.None));

            try
            {
                #region creating connection

                HBaseConnection con = new HBaseConnection("localhost", 10003);
                con.Open();

                #endregion creating connection

                #region parsing csv input file

                csv csvObj = new csv();
                object[,] cells;
                cells = null;

                cells = csvObj.Table(path, false, ',');

                #endregion parsing csv input file

                #region creating table
                String        tableName      = "AdventureWorks_Person_Contact";
                List <string> columnFamilies = new List <string>();
                columnFamilies.Add("info");
                columnFamilies.Add("contact");
                columnFamilies.Add("others");
                if (!HBaseOperation.IsTableExists(tableName, con))
                {
                    if (columnFamilies.Count > 0)
                    {
                        HBaseOperation.CreateTable(tableName, columnFamilies, con);
                    }
                    else
                    {
                        throw new HBaseException("ERROR: Table must have at least one column family");
                    }
                }
                # endregion

                #region Inserting Values
                string[] column = new string[] { "CONTACTID", "FULLNAME", "AGE", "EMAILID", "PHONE", "MODIFIEDDATE" };
                Dictionary <string, IList <HMutation> > rowCollection = new Dictionary <string, IList <HMutation> >();
                string rowKey;
                for (int i = 0; i < cells.GetLength(0); i++)
                {
                    List <HMutation> mutations = new List <HMutation>();
                    rowKey = cells[i, 0].ToString();
                    for (int j = 1; j < column.Length; j++)
                    {
                        HMutation mutation = new HMutation();
                        mutation.ColumnFamily = j < 3 ? "info" : j < 5 ? "contact" : "others";
                        mutation.ColumnName   = column[j];
                        mutation.Value        = cells[i, j].ToString();
                        mutations.Add(mutation);
                    }
                    rowCollection[rowKey] = mutations;
                }
                HBaseOperation.InsertRows(tableName, rowCollection, con);
                #endregion Inserting Values

                #region scan values

                HBaseOperation.FetchSize = 100;
                HBaseResultSet table = HBaseOperation.ScanTable(tableName, con);

                //Initialize the list to add elements in each row
                BindingList <Customers> resultList = new BindingList <Customers>();

                //Read each row from the fetched result
                foreach (HBaseRecord rows in table)
                {
                    //Adding element of each row to the list
                    resultList = new BindingList <Customers>(table.Select(row => new Customers
                    {
                        ContactId    = row["rowKey"] != null?row["rowKey"].ToString():"",
                        FullName     = row["info:FULLNAME"] != null ? row["info:FULLNAME"].ToString() : "",
                        Age          = row["info:AGE"] != null ? row["info:AGE"].ToString() : "",
                        EmailId      = row["contact:EMAILID"] != null ? row["contact:EMAILID"].ToString() : "",
                        PhoneNumber  = row["contact:PHONE"] != null ? row["contact:PHONE"].ToString() : "",
                        ModifiedDate = row["others:MODIFIEDDATE"] != null ? row["others:MODIFIEDDATE"].ToString() : "",
                    }).ToList());
                }
                //Binding the result to the grid
                this.FlatGrid.DataSource = resultList;
                this.FlatGrid.DataBind();
                #endregion scan values

                #region close connection
                //Closing the hbase connection
                con.Close();
                #endregion close connection
            }