Example #1
0
        public void Exec()
        {
            Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch

            WaitScreen.Splash();
            string command = CHBox.Text;

            using (ClickHouseCommand comm = con.CreateCommand(command))
            {
                try
                {
                    comm.ExecuteNonQuery();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Response.Content = "Wrong command.";
                    return;
                }

                stopwatch.Stop();

                var  elapsedBulkMs = stopwatch.ElapsedMilliseconds;
                Logs xd            = new DBUplader.Logs();

                xd.AddLog("--------------------------------------------");
                xd.AddLog("Execute ClickHouse Command");
                xd.AddLog(command);
                xd.AddLog("Execute time : " + elapsedBulkMs + "ms");

                Response.Content = "OK. " + elapsedBulkMs + "ms";
            }
        }
Example #2
0
        public static void CHConnection(Action myMethodName)
        {
            WaitScreen.Splash();

            try
            {
                con = new ClickHouseConnection(str);
                con.Open();
                Console.WriteLine("DBConnected");


                myMethodName();
            }
            catch (ClickHouseException err)
            {
                Console.WriteLine(err);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
        }
Example #3
0
        public void Preview(string table)
        {
            WaitScreen.Splash();

            using (ClickHouseCommand comm = con.CreateCommand($"SELECT * FROM {table} LIMIT 5"))
            {
                using (var reader = comm.ExecuteReader())
                {
                    List <object> result = new List <object>();
                    do
                    {
                        while (reader.Read())
                        {
                            for (var i = 0; i < reader.FieldCount; i++)
                            {
                                var val = reader.GetValue(i);
                                result.Add(val);
                                CHBox.AppendText(result[i].ToString() + ", ");
                            }
                            CHBox.AppendText(Environment.NewLine);
                            result.Clear();
                        }
                    } while (reader.NextResult());
                }
            }
        }
Example #4
0
        private void MigrateCHToMDB_Click(object sender, RoutedEventArgs e)
        {
            WaitScreen.Splash();
            string tableName = CHTablesComboBox.SelectedItem.ToString();

            Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch

            CHConnection(() => InsertToMDB(GetTableColumns(tableName), tableName));

            stopwatch.Stop();

            var elapsedBulkMs = stopwatch.ElapsedMilliseconds;
            int records       = CountMDB(tableName);

            Console.WriteLine("time : " + stopwatch.ElapsedMilliseconds);
            Timer.Content             = "Migration time : " + elapsedBulkMs + "ms";
            NumberOfRecordsCH.Content = "Records inserted : " + records;

            Logs xd = new DBUplader.Logs();

            xd.AddLog("--------------------------------------------");
            xd.AddLog("Migrate ClickHouse to MongoDB");
            xd.AddLog("       Data name : " + tableName);
            xd.AddLog("       Bulk time : " + elapsedBulkMs + "ms");
            xd.AddLog("Records inserted : " + records);
        }
        private void BulkToClickHouse_Click(object sender, RoutedEventArgs e)
        {
            WaitScreen.Splash();

            string filePath  = CSVPathTextBoxCH.Text;
            string tableName = TableNameTextBox.Text;

            CHConn(() => ReadCSV3(filePath, tableName));
        }
Example #6
0
        public void Exec1()
        {
            Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch

            WaitScreen.Splash();
            string command = CHBox.Text;

            using (ClickHouseCommand comm = con.CreateCommand(command))
            {
                try
                {
                    using (var reader = comm.ExecuteReader())
                    {
                        List <object> result = new List <object>();
                        do
                        {
                            while (reader.Read())
                            {
                                for (var i = 0; i < reader.FieldCount; i++)
                                {
                                    var val = reader.GetValue(i);
                                    result.Add(val);
                                    Resp.AppendText(result[i].ToString() + ", ");
                                }
                                Resp.AppendText(Environment.NewLine);
                                result.Clear();
                            }
                        } while (reader.NextResult());
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    Response.Content = "Wrong command.";
                    return;
                }

                stopwatch.Stop();

                var  elapsedBulkMs = stopwatch.ElapsedMilliseconds;
                Logs xd            = new DBUplader.Logs();

                xd.AddLog("--------------------------------------------");
                xd.AddLog("Execute ClickHouse Command");
                xd.AddLog(command);
                xd.AddLog("Execute time : " + elapsedBulkMs + "ms");

                Response.Content = "OK. " + elapsedBulkMs + "ms";
            }

            using (ClickHouseCommand comm = con.CreateCommand(command))
            {
            }
        }
Example #7
0
        private void Preview(string table)
        {
            WaitScreen.Splash();
            int limit    = int.Parse(Limit.Text);
            var server   = new MongoClient("mongodb://localhost:27017");
            var database = server.GetDatabase("test");

            var coll = database.GetCollection <BsonDocument>(table);
            var list = coll.Find(new BsonDocument()).Limit(limit).ToList();

            for (int i = 0; i < list.Count; i++)
            {
                MDBBox.AppendText(list[i].ToString() + (Environment.NewLine));
            }
        }
Example #8
0
        public static List <string> GetCollections()
        {
            WaitScreen.Splash();

            List <string> collections = new List <string>();
            var           db          = new MongoClient("mongodb://localhost:27017").GetDatabase("test");

            foreach (BsonDocument collection in db.ListCollectionsAsync().Result.ToListAsync <BsonDocument>().Result)
            {
                string name = collection["name"].AsString;
                collections.Add(name);
            }

            return(collections);
        }
Example #9
0
        private void MigrateMDBToCH_Click(object sender, RoutedEventArgs e)
        {
            WaitScreen.Splash();
            string    tableName = MDBTablesComboBox.SelectedItem.ToString();
            Stopwatch stopwatch = Stopwatch.StartNew();

            CSVToClickHouse.CHConn(() => GetData(tableName));
            stopwatch.Stop();
            var elapsedBulkMs = stopwatch.ElapsedMilliseconds;

            Timer.Content = "Migration time : " + elapsedBulkMs + "ms";

            NumberOfRecords.Content = "Records : " + (lineCount);

            Logs xd = new DBUplader.Logs();

            xd.AddLog("--------------------------------------------");
            xd.AddLog("Migrate MongoDB to ClickHouse");
            xd.AddLog("       Data name : " + tableName);
            xd.AddLog("       Bulk time : " + elapsedBulkMs + "ms");
            xd.AddLog("Records inserted : " + lineCount);
        }
Example #10
0
        public void GetData(string tableName)
        {
            WaitScreen.Splash();
            this._Types = null;
            this._Names = null;
            var db = new MongoClient("mongodb://localhost:27017").GetDatabase("test").GetCollection <BsonDocument>(tableName);

            var count    = db.CountDocuments(FilterDefinition <BsonDocument> .Empty);
            var stepSize = 1000;

            for (int i = 0; i < Math.Ceiling((double)count / stepSize); i++)
            {
                var list   = db.Find(new BsonDocument()).Skip(i * stepSize).Limit(stepSize).ToList();
                var values = this.getValues(list);
                if (i == 0)
                {
                    values = values.ToList();
                    CSVToClickHouse.CreateCHTable(this._Names, this._Types, tableName);
                }
                CSVToClickHouse.InsertValues(values, tableName, this._Names);
            }
            lineCount = (int)count;
        }
        private void BulkToMongoDB_Click(object sender, RoutedEventArgs e)

        {
            WaitScreen.Splash();
            UploadCSVToMongoDB();
        }
        private void Exec(string table, string filter)
        {
            Stopwatch stopwatch = Stopwatch.StartNew(); //creates and start the instance of Stopwatch

            WaitScreen.Splash();

            string command = MDBBox.Text;

            var server   = new MongoClient("mongodb://localhost:27017");
            var database = server.GetDatabase("test");

            var coll = database.GetCollection <BsonDocument>(table);

            //var list = coll.Find(command);

            //var list = coll.Find(new BsonDocument()).Limit(5).ToList();

            //filter = "{ price: '480'}";

            //var list = coll.Find("{},{\"name\":1}).limit(100)").ToList();


            try
            {
                int    lim = int.Parse(Limit.Text);
                string typ = Type.Text;
                List <BsonDocument> list = new List <BsonDocument>();



                if (lim > 0 && typ == "Find")
                {
                    list = coll.Find(filter).Limit(lim).ToList();
                }
                else if (lim <= 0 && typ == "Find")
                {
                    list = coll.Find(filter).ToList();
                }
                else if (lim > 0 && typ == "Group")
                {
                    list = coll.Aggregate().Group(filter).Limit(lim).ToList();
                }
                else if (lim <= 0 && typ == "Group")
                {
                    list = coll.Aggregate().Group(filter).ToList();
                }

                for (int i = 0; i < list.Count; i++)
                {
                    Resp.AppendText(list[i].ToString() + (Environment.NewLine));
                }
                stopwatch.Stop();

                var  elapsedBulkMs = stopwatch.ElapsedMilliseconds;
                Logs xd            = new DBUplader.Logs();

                xd.AddLog("--------------------------------------------");
                xd.AddLog("Execute MongoDB Command");
                xd.AddLog(command);
                xd.AddLog($"On table { table }");
                xd.AddLog($"Execute time : { elapsedBulkMs } ms");

                Response.Content = $"OK. { elapsedBulkMs } ms";
            }
            catch
            {
                Response.Content = "Wrong command.";
            }


            //var comm = new JsonCommand<BsonDocument>(command);
            //database.RunCommand(comm);

            //db.getCollection('asd').find({ })
        }