private void CreateTable(string tableName, string clusterUrl, string username, string password, string storage, string key) { string command = string.Format(@"CREATE TABLE {0} (column1 STRING, column2 STRING, column3 STRING) STORED AS TEXTFILE", tableName); using (var hiveConnection = new HiveConnection(new Uri(clusterUrl), username, password, storage, key)) { hiveConnection.ExecuteHiveQuery(command).WaitForResult(); } }
private void RunJob(string tableName, string clusterUrl, string username, string password, string storage, string key) { string command = string.Format(@"SELECT COUNT(*), column1 FROM {0} GROUP BY column1", tableName); using (var hiveConnection = new HiveConnection(new Uri(clusterUrl), username, password, storage, key)) { hiveConnection.ExecuteHiveQuery(command).WaitForResult(); } }
static void Test1() { var line = File.ReadLines("account.txt").First(); var ss = line.Split(","); ss = ss.Select(e => e.Trim()).ToArray(); using (var conn = new HiveConnection(ss[0], ss[1].ToInt(), ss[2], ss[3])) { var cmd = conn.CreateCommand(); cmd.Execute("use default"); cmd.Execute("select * from kbb"); var dt = cmd.Fetch(100); if (dt != null) { foreach (var item in dt.Columns) { Console.Write(item + ","); } Console.WriteLine(); foreach (var row in dt.Rows) { Console.WriteLine(row.Join(",")); } } for (var i = 0; i < 100_000; i++) { var sql = $"insert into kbb (id, name) values ({i + 1},'{DateTime.Now.ToFullString()}')"; var sb = new StringBuilder(); sb.Append(sql); for (var k = 0; k < 10; k++) { sb.Append(","); sb.Append($"({i + 1},'{DateTime.Now.ToFullString()}')"); } sql = sb.ToString(); XTrace.WriteLine(sql); cmd.Execute(sql); } } }