コード例 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                #region Creating connection

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

                #endregion Creating connection

                #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

                #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;
                table = HBaseOperation.ScanTable(tableName, con);

                #endregion Scan values

                #region closing connection

                //closing the HBase connection
                con.Close();

                #endregion closing connection
            }
コード例 #2
0
        public MainWindow()
        {
            InitializeComponent();
            try
            {
                string path = System.AppDomain.CurrentDomain.BaseDirectory;
                path = path + "..\\..\\..\\..\\..\\..\\..\\..\\Data\\AdventureWorks\\AdventureWorks_Person_Contact.csv";

                #region Creating connection

                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 Creating table

                #region Inserting Values

                #region Parsing csv input file

                csv csvObj = new csv();
                object[,] cells = csvObj.Table(path, 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

                //Fetches the result from the reader and store it in a object
                HBaseOperation.FetchSize = 100;
                result = HBaseOperation.ScanTable(tableName, con);

                //Closing the HBase connection
                con.Close();
            }
            catch (HBaseConnectionException)
            {
                if (MessageBox.Show("Could not establish a connection to the HBase thrift server. Please run HBase thrift server from the Syncfusion service manager dashboard.", "Could not establish a connection to the HBase thrift server", MessageBoxButton.OK, MessageBoxImage.Warning) == MessageBoxResult.OK)
                {
                    Application.Current.Shutdown();
                }
            }
            catch (HBaseException hbase_ex)
            {
                if (MessageBox.Show(hbase_ex.Message.ToString(), "HBaseException", MessageBoxButton.OK, MessageBoxImage.Warning) == MessageBoxResult.OK)
                {
                    Application.Current.Shutdown();
                }
            }
            catch (Exception ex)
            {
                if (MessageBox.Show(ex.Message.ToString(), "Exception", MessageBoxButton.OK, MessageBoxImage.Warning) == MessageBoxResult.OK)
                {
                    Application.Current.Shutdown();
                }
            }
        }