internal TDengineDataReader(TDengineCommand command, CommandBehavior behavior, IntPtr handler) { _command = command; _behavior = behavior; _handler = handler; _metas = TD.FetchFields(handler); _fieldCount = TD.FieldCount(handler); _rows = TD.AffectRows(handler); }
public void ExecuteInsert() { if (!this.isInsertData) { return; } System.DateTime start = new System.DateTime(); long loopCount = this.totalRows / this.batchRows; for (int table = 0; table < this.tableCount; ++table) { for (long loop = 0; loop < loopCount; loop++) { StringBuilder sql = new StringBuilder(); sql.Append("insert into ").Append(this.tablePrefix).Append(table).Append(" values"); for (int batch = 0; batch < this.batchRows; ++batch) { long rows = loop * this.batchRows + batch; sql.Append("(") .Append(this.beginTimestamp + rows) .Append(", 1, 2, 3,") .Append(rows) .Append(", 5, 6, 7, 'abc', 'def')"); } IntPtr res = TDengine.Query(this.conn, sql.ToString()); if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) { Console.Write(sql.ToString() + " failure, "); if (res != IntPtr.Zero) { Console.Write("reason: " + TDengine.Error(res)); } Console.WriteLine(""); } int affectRows = TDengine.AffectRows(res); this.rowsInserted += affectRows; TDengine.FreeResult(res); } } System.DateTime end = new System.DateTime(); TimeSpan ts = end - start; Console.Write("Total {0:G} rows inserted, {1:G} rows failed, time spend {2:G} seconds.\n" , this.rowsInserted, this.totalRows * this.tableCount - this.rowsInserted, ts.TotalSeconds); }
public void ExecuteInsert() { if (!this.isInsertData) { return; } System.DateTime start = new System.DateTime(); long loopCount = this.totalRows / this.batchRows; for (int table = 0; table < this.tableCount; ++table) { for (long loop = 0; loop < loopCount; loop++) { StringBuilder sql = new StringBuilder(); sql.Append("insert into ").Append(this.tablePrefix).Append(table).Append(" values"); for (int batch = 0; batch < this.batchRows; ++batch) { long rows = loop * this.batchRows + batch; sql.Append("(").Append(this.beginTimestamp + rows).Append(",").Append(rows).Append(")"); } int code = TDengine.Query(conn, sql.ToString()); if (code != TDengine.TSDB_CODE_SUCCESS) { Console.WriteLine(sql.ToString() + " failure, reason: " + TDengine.Error(conn)); } int affectRows = TDengine.AffectRows(conn); this.rowsInserted += affectRows; } } System.DateTime end = new System.DateTime(); TimeSpan ts = end - start; Console.Write("Total {0:G} rows inserted, {1:G} rows failed, time spend {2:G} seconds.\n" , this.rowsInserted, this.totalRows * this.tableCount - this.rowsInserted, ts.TotalSeconds); }
public void ThreadMain() { VerbosePrintFormat("InsertDataThread {0} from {1} to {2}\n", id, start, end); StringBuilder sql = new StringBuilder(); DateTime now = DateTime.Now; int h = now.Hour; int m = now.Minute; int s = now.Second; long baseTimestamp = 1609430400000; // 2021/01/01 0:0:0 VerbosePrintFormat("beginTime is {0} + {1}h:{2}m:{3}s\n", baseTimestamp, h, m, s); long beginTimestamp = baseTimestamp + ((h * 60 + m) * 60 + s) * 1000; Random random = new Random(); long rowsInserted = 0; long i = 0; while (i < recordsPerTable) { for (long table = start; table <= end; ++table) { long inserted = i; sql.Clear(); sql.Append("INSERT INTO "). Append(this.dbName).Append(".").Append(this.tablePrefix).Append(table). Append(" VALUES"); if (recordsPerTable < batchRows) { batchRows = recordsPerTable; } for (int batch = 0; batch < batchRows; ++batch) { long writeTimeStamp = beginTimestamp + i + batch; int rnd = 100; if (this.order == false) { rnd = random.Next(1, 100); if (rnd <= this.rateOfOutorder) { writeTimeStamp = writeTimeStamp + rnd * 10000; DebugPrint("### "); } DebugPrintFormat("order:{0} rnd:{1} timestamp:{2}\n", this.order, rnd, writeTimeStamp); } else { DebugPrintFormat("order:{0} timestamp:{1}\n", this.order, writeTimeStamp); } sql.Append("(") .Append(writeTimeStamp) .Append(", 1, 2, 3,") .Append(i + batch) .Append(", 5, 6, 7, 'abc', 'def')"); } IntPtr res = TDengine.Query(this.conn, sql.ToString()); if (res == IntPtr.Zero) { VerbosePrint(sql.ToString() + " failure, reason: " + TDengine.Error(res) + "\n"); } inserted += this.batchRows; int affectRows = TDengine.AffectRows(res); rowsInserted += affectRows; TDengine.FreeResult(res); if (table == end) { i = inserted; } } } }
public void ThreadMain() { VerbosePrintFormat("InsertDataThread {0} from {1} to {2}\n", id, start, end); StringBuilder sql = new StringBuilder(); DateTime now = DateTime.Now; int h = now.Hour; int m = now.Minute; int s = now.Second; long baseTimestamp = -16094340000; // 1969-06-29 01:21:00 VerbosePrintFormat("beginTime is {0} + {1}h:{2}m:{3}s\n", baseTimestamp, h, m, s); long beginTimestamp = baseTimestamp + ((h * 60 + m) * 60 + s) * 1000; Random random = new Random(); long rowsInserted = 0; long i = 0; while (i < recordsPerTable) { for (long table = start; table <= end; ++table) { long inserted = i; sql.Clear(); sql.Append("INSERT INTO "). Append(this.dbName).Append(".").Append(this.tablePrefix).Append(table). Append(" VALUES"); if (recordsPerTable < batchRows) { batchRows = recordsPerTable; } for (int batch = 0; batch < batchRows; ++batch) { long writeTimeStamp = beginTimestamp + i + batch; int rnd = 100; if (this.order == false) { rnd = random.Next(1, 100); if (rnd <= this.rateOfOutorder) { writeTimeStamp = writeTimeStamp + rnd * 10000; DebugPrint("### "); } DebugPrintFormat("order:{0} rnd:{1} timestamp:{2}\n", this.order, rnd, writeTimeStamp); } else { DebugPrintFormat("order:{0} timestamp:{1}\n", this.order, writeTimeStamp); } sql.Append("(") .Append(writeTimeStamp) .Append(", 1, -2, -3,") .Append(i + batch - 127) .Append(", -5, -6, -7, 'abc', 'def', 254, 65534,") .Append(4294967294 - (uint)i - (uint)batch) .Append(",") .Append(18446744073709551614 - (ulong)i - (ulong)batch) .Append(")"); } VerbosePrint(sql.ToString() + "\n"); IntPtr res = TDengine.Query(this.conn, sql.ToString()); if ((res == IntPtr.Zero) || (TDengine.ErrorNo(res) != 0)) { Console.Write(sql.ToString() + " failure, "); if (res != IntPtr.Zero) { Console.Write("reason: " + TDengine.Error(res)); } Console.WriteLine(""); } inserted += this.batchRows; int affectRows = TDengine.AffectRows(res); rowsInserted += affectRows; TDengine.FreeResult(res); if (table == end) { i = inserted; } } } }