public void testKeepWritingTask() { DBConnection conn = new DBConnection(); conn.connect(SERVER, PORT, USER, PASSWORD, WRITE_FUNCTION_SCRIPT, true, HA_SITES); int count = 0; Random rnd = new Random(); string funcScript = String.Format("saveData{{{0}}}", TBNAME); Console.WriteLine(funcScript); for (int i = 0; i < 86400000; i++) { IList <IEntity> args = new List <IEntity>(); DateTime dt = new DateTime(2021, 1, 1); BasicDateVector bdv = new BasicDateVector(new int[] { Utils.countDays(2021, 4, 7) }); BasicTimeVector btv = new BasicTimeVector(new int[] { i }); BasicStringVector bsv = new BasicStringVector(new string[] { SYMBOLS[rnd.Next(3)] }); BasicIntVector bqv = new BasicIntVector(new int[] { rnd.Next(80, 100) }); BasicDoubleVector bpv = new BasicDoubleVector(new double[] { rnd.NextDouble() }); List <String> colNames = new List <string>() { "date", "time", "sym", "qty", "price" }; List <IVector> cols = new List <IVector>() { bdv, btv, bsv, bqv, bpv }; BasicTable table1 = new BasicTable(colNames, cols); args.Add(table1); BasicInt re = (BasicInt)conn.run(funcScript, args); Console.WriteLine(re.getInt()); } }
public Projectile(string name) { damage = new BasicInt(name + " damage"); delay = new BasicInt(name + " delay"); // ms energy = new BasicInt(name + " energy"); speed = new StepInt(name + " speed"); bounces = new BasicInt(name + " bounces"); }
/// <summary> /// Append a list of columns to the table. </summary> /// <param name="row"> </param> /// <returns> number of rows appended. </returns> /// <exception cref="IOException"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public int append(java.util.List<Entity> row) throws java.io.IOException public virtual int append(IList <Entity> row) { if (row.Count != cols) { throw new Exception("expect " + cols + " columns of values, got " + row.Count + " columns of values"); } IList <Entity> args = new List <Entity>(); args.Add(tableName); ((List <Entity>)args).AddRange(row); BasicInt affected = (BasicInt)conn.run("tableInsert", args); return(affected.Int); }
bool writeAllData() { lock (writeAllDataLock_) { List <IVector> items; int addRowCount; lock (writeQueue_) { items = writeQueue_[0]; addRowCount = items[0].rows(); if (addRowCount < 1) { return(false); } writeQueue_.RemoveAt(0); if (writeQueue_.Count == 0) { writeQueue_.Add(tableWriter_.createListVector()); } } bool isWriteDone = true; string runscript = ""; BasicTable writeTable = null; writeTable = new BasicTable(tableWriter_.colNames_, items); if (writeTable != null && addRowCount > 0) { runscript = ""; try { List <IEntity> args = new List <IEntity>(); args.Add(writeTable); runscript = scriptTableInsert_; BasicInt result = (BasicInt)conn_.run(runscript, args); sentRows_ += addRowCount; } catch (Exception e) { Console.Out.WriteLine("threadid= {0}, Save Table error: {1}, script: {2}", threadId_, e.Message, runscript); //System.Console.Out.WriteLine(e.Message); //System.Console.Out.WriteLine(e.StackTrace); //tableWriter_.logger_.warning("threadid=" + writeThread_.getId() + " sendindex=" + sentRows_ + " Save table error: " + e + " script:" + runscript); tableWriter_.setError(ErrorCodeInfo.Code.EC_Server, "Save table error: " + e + " script: " + runscript); isWriteDone = false; //std::cerr << Util::createTimestamp(Util::getEpochTime())->getString() << " Backgroud thread of table (" << tableWriter_.dbName_ << " " << tableWriter_.tableName_ << "). Failed to send data to server, with exception: " << e.what() << std::endl; } } if (!isWriteDone) { lock (failedQueue_) { int cols = items.Count; int rows = items[0].rows(); for (int i = 0; i < rows; ++i) { List <IEntity> tmp = new List <IEntity>(); for (int j = 0; j < cols; ++j) { if ((int)tableWriter_.colTypes_[j] < AbstractVector.ARRAY_VECTOR_BASE) { tmp.Add(items[j].get(i)); } else { tmp.Add(((BasicArrayVector)items[j]).getSubVector(i)); } } failedQueue_.Enqueue(tmp); } } } } return(true); }
public void append_test() { DBConnection conn = new DBConnection(false); conn.connect(SERVER, PORT, USER, PASSWORD); conn.run("dbPath = \"dfs://demohash\";if(existsDatabase(dbPath)) dropDatabase(dbPath); db = database(dbPath, HASH,[STRING, 2]);t= table(100:0,`股票代码`股票日期`买方报价`卖方报价`时间戳`备注`timespan,[STRING,MONTH,DOUBLE,DOUBLE,DATE,STRING,TIME]);pt=db.createPartitionedTable(t,`pt,`股票代码);"); autoFitTableAppender aft = new autoFitTableAppender("dfs://demohash", "pt", false, conn); DataTable dt = new DataTable(); List <DataColumn> cols = new List <DataColumn>() { new DataColumn("股票代码", Type.GetType("System.String")), new DataColumn("股票日期", Type.GetType("System.DateTime")), new DataColumn("买方报价", Type.GetType("System.Double")), new DataColumn("卖方报价", Type.GetType("System.Double")), new DataColumn("时间戳", Type.GetType("System.DateTime")), new DataColumn("备注", Type.GetType("System.String")), new DataColumn("timespan", Type.GetType("System.TimeSpan")) }; dt.Columns.AddRange(cols.ToArray()); for (int i = 0; i < 1000; i++) { DataRow dr = dt.NewRow(); dr["股票代码"] = new string[] { "GGG", "MSSS", "FBBBB" }[i % 3]; dr["股票日期"] = DateTime.Now.Date; dr["买方报价"] = 22222.5544; dr["卖方报价"] = 3333.33322145; dr["时间戳"] = new DateTime(2021, 1, 26, 15, 1, 2); dr["备注"] = "备注" + i.ToString(); dr["timespan"] = new TimeSpan(0, 15, 15, 14, 123); dt.Rows.Add(dr); } IEntity res = aft.append(dt); //Assert.AreEqual(res, null); DBConnection db = new DBConnection(); db.connect(SERVER, PORT, USER, PASSWORD); for (int i = 0; i < 10; i++) { Thread.Sleep(1000); try { BasicLong x = (BasicLong)db.run("exec count(*) from loadTable(\"dfs://demohash\",`pt)"); if (x.getValue() == 1000) { break; } } catch (Exception ex) { BasicInt x = (BasicInt)db.run("exec count(*) from loadTable(\"dfs://demohash\",`pt)"); if (x.getValue() == 1000) { break; } } } BasicLong re = (BasicLong)db.run("exec count(*) from loadTable(\"dfs://demohash\",`pt)"); Assert.AreEqual(re.getValue(), 1000); db.run("dropDatabase(\"dfs://demohash\")"); db.close(); }