Beispiel #1
0
        /**
         * Gets the current size of all table write queue, number of rows already sended to server, whether a
         * table is being removed, and whether the backgroud thread is returned because of error.
         */
        public BasicTable getAllStatus()
        {
            int                columnNum  = 6;
            List <string>      colNames   = new List <string>(new String[] { "DatabaseName", "TableName", "WriteQueueDepth", "SendedRows", "Removing", "Finished" });
            List <DATA_TYPE>   colTypes   = new List <DATA_TYPE>(new DATA_TYPE[] { DATA_TYPE.DT_STRING, DATA_TYPE.DT_STRING, DATA_TYPE.DT_INT, DATA_TYPE.DT_INT, DATA_TYPE.DT_BOOL, DATA_TYPE.DT_BOOL });
            List <IVector>     columnVecs = new List <IVector>();
            BasicEntityFactory factory    = new BasicEntityFactory();

            for (int i = 0; i < columnNum; ++i)
            {
                columnVecs.Add(factory.createVectorWithDefaultValue(colTypes[i], 0));
            }

            try
            {
                rwLock_.EnterReadLock();
                int rowNum = destTables_.Count();
                foreach (KeyValuePair <Tuple <string, string>, DestTable> t in destTables_)
                {
                    columnVecs[0].add(t.Value.dbName);
                    columnVecs[1].add(t.Value.tableName);
                    columnVecs[2].add(t.Value.writeQueue.Count());
                    columnVecs[3].add(t.Value.sendedRows);
                    columnVecs[4].add(t.Value.destroy);
                    columnVecs[5].add(t.Value.finished);
                }
            }
            finally
            {
                rwLock_.ExitReadLock();
            }
            BasicTable ret = new BasicTable(colNames, columnVecs);

            return(ret);
        }
Beispiel #2
0
        public void blob_imemory_table_upload()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            db.run("share table(100:0, `id`memo, [INT,  BLOB])as st");
            List <String> colNames = new List <String>(2);

            colNames.Add("id");
            colNames.Add("str");
            List <IVector> cols = new List <IVector>(2);
            BasicIntVector id   = new BasicIntVector(2);

            id.setInt(1, 1);
            id.setInt(0, 1);

            BasicStringVector str = new BasicStringVector(2);
            String            tmp = "534656 unuk6.太阳能与看见了和和 规划局广告费 hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金dd,/5额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技hudfgdg TYF  FEW 867R 8T至于金额及计划一 至于科技";

            str.setString(0, tmp);
            str.setString(1, tmp);
            cols.Add(id);
            cols.Add(str);
            BasicTable     t   = new BasicTable(colNames, cols);
            List <IEntity> arg = new List <IEntity>()
            {
                t
            };

            db.run("tableInsert{st}", arg);

            BasicTable st = (BasicTable)db.run("st");
            // Console.WriteLine(((BasicTable)st).getColumn(2).get(0).getValue());
        }
Beispiel #3
0
        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());
            }
        }
Beispiel #4
0
        private static IList <DbObjectInfo> UpdateSessionObjs(DBConnection conn)
        {
            BasicTable objs = (BasicTable)conn.tryRun("objs(true)");

            if (objs == null)
            {
                return(null);
            }

            var listObjs = new List <DbObjectInfo>(objs.rows());

            for (int i = 0; i != objs.rows(); i++)
            {
                DbObjectInfo obj = new DbObjectInfo
                {
                    name    = objs.getColumn("name").get(i).getString(),
                    type    = objs.getColumn("type").get(i).getString(),
                    forms   = objs.getColumn("form").get(i).getString(),
                    rows    = (objs.getColumn("rows").get(i) as BasicInt).getValue(),
                    columns = (objs.getColumn("columns").get(i) as BasicInt).getValue(),
                    shared  = (objs.getColumn("shared").get(i) as BasicBoolean).getValue(),
                    bytes   = (objs.getColumn("bytes").get(i) as BasicLong).getValue()
                };

                listObjs.Add(obj);
            }
            return(listObjs);
        }
Beispiel #5
0
        public void Test_run_return_table_toDataTable_char()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable tb = (BasicTable)db.run("table(1 as id,'a' as name)");
            DataTable  dt = tb.toDataTable();
        }
Beispiel #6
0
        public static string GetString(int index)
        {
            var stream = GetDataStream();

            stream.Skip(EntrySize * index);
            var data = stream.GetBytes(EntrySize);
            var name = string.Join("", data.Where(x => x != BufferByte).Select(x => BasicTable.Lookup(x)));

            return(name);
        }
        public void Test_getObject()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            EntityBlockReader bt    = (EntityBlockReader)db.run("table(1..100000 as id)", (ProgressListener)null, 4, 4, 10000);
            BasicTable        table = (BasicTable)bt.getObject();

            table = (BasicTable)bt.getObject();
        }
        public IEntity append(BasicTable table)
        {
            BasicTable     bt   = Utils.fillSchema(table, schema);
            List <IEntity> args = new List <IEntity>(1);

            args.Add(bt);
            string appendScript = "tableInsert{loadTable('" + dbUrl + "', '" + tableName + "')}";

            return(conn.run(appendScript, args));
        }
        public static void ExportDDBTableToWorksheet(BasicTable tb, ImportOpt opt)
        {
            List <string> format = new List <string>();

            for (int i = 0; i != tb.columns(); i++)
            {
                DATA_TYPE colType = tb.getColumn(i).getDataType();
                format.Add(DDBExcelNumericFormater.GetFormat(colType));
            }
            ExportDataTableToWorksheet(tb.toDataTable(), opt, format);
        }
Beispiel #10
0
        public void TestMethod1()
        {
            DBConnection db = new DBConnection();

            db.connect("40.76.68.158", 8848);
            string     script = @"t = loadTable('/root/DolphinDB/Data/valuedb/TradeDB','table_candles');select time, nullFill!(mcorr(BTCUSD, ETHUSD, 60),0) as mcorrResult   from (select first(close) from t where product = 'ETH-USD' or product = 'BTC-USD', granularity = 900 pivot by time, product)";
            DateTime   dts    = DateTime.Now;
            BasicTable bt     = (BasicTable)db.run(script);
            TimeSpan   ts     = DateTime.Now - dts;

            Assert.AreEqual(0, ts);
        }
Beispiel #11
0
        public void Test_run_return_table_toDataTable()
        {
            string       script = @"table(take(0b 1b, 10) as tBOOL, char(1..10) as tCHAR, short(1..10) as tSHORT, int(1..10) as tINT, long(1..10) as tLONG, 2000.01.01 + 1..10 as tDATE, 2000.01M + 1..10 as tMONTH, 13:30:10.008 + 1..10 as tTIME, 13:30m + 1..10 as tMINUTE, 13:30:10 + 1..10 as tSECOND, 2012.06.13T13:30:10 + 1..10 as tDATETIME, 2012.06.13T13:30:10.008 + 1..10 as tTIMESTAMP,09:00:01.000100001 + 1..10 as tNANOTIME,2016.12.30T09:00:01.000100001 + 1..10 as tNANOTIMESTAMP, 2.1f + 1..10 as tFLOAT, 2.1 + 1..10 as tDOUBLE, take(`A`B`C`D, 10) as tSYMBOL)";
            DBConnection db     = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable tb = (BasicTable)db.run(script);
            DataTable  dt = tb.toDataTable();

            Assert.AreEqual(10, dt.Rows.Count);
            Assert.AreEqual("3", dt.Rows[2]["tSHORT"].ToString());
        }
Beispiel #12
0
        public void Test_run_return_table_int()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable tb = (BasicTable)db.run("table(1..100 as id,take(`aaa,100) as name)");

            Assert.IsTrue(tb.isTable());
            Assert.AreEqual(100, tb.rows());
            Assert.AreEqual(2, tb.columns());
            Assert.AreEqual(3, ((BasicInt)tb.getColumn(0).get(2)).getValue());
        }
Beispiel #13
0
        public static string AttemptTranslate(ByteArrayStream stream, int depthLeft = 2)
        {
            var code = stream.Byte();

            if (code >= 0x80)
            {
                return(BasicTable.Lookup(code));
            }

            if (code < 0x30)
            {
                if (code == 0x01)
                {
                    return($"{{windowbreak}}");
                }
                if (code == 0x05)
                {
                    return($"{{05:{stream.Byte().ToString("x2")}}}");
                }
                if (code == 0x1b)
                {
                    return($"{{swapspeaker:{stream.Byte().ToString("x2")}}}");
                }
                if (code == 0x1d)
                {
                    return($"{{character:{CharacterNames.GetString(stream.Byte())}}}");
                }
                if (code == 0x1e)
                {
                    return($"{{item:{ItemNames.GetString(stream.Byte())}}}");
                }
                if (code == 0x1f)
                {
                    return($"{{location:{LocationNames.GetString(stream.Byte())}}}");
                }
                //if (code == 0x2f) {
                //	return $"{{if:{stream.Byte().ToString("x2")} {stream.Byte().ToString("x2")} {stream.Byte().ToString("x2")}}}";
                //}


                return($"{{{code.ToString("x2")}}}");
            }

            if (depthLeft == 0)
            {
                return($"{{{code.ToString("x2")}}}");
            }

            //var text = string.Join("", LookupBytes(code).Select(x => AttemptTranslate(x, depthLeft - 1)));
            var text = AttemptTranslateLine(LookupBytes(code), depthLeft - 1);

            return(text);
        }
Beispiel #14
0
        public void Test_GetNullTable()
        {
            string       sql = "t=table(10:0,`id`str`long`double,[INT,STRING,LONG,DOUBLE]);insert into t values(1,NULL,NULL,NULL);t";
            DBConnection db  = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable bt = (BasicTable)db.run(sql);
            DataTable  dt = bt.toDataTable();

            Assert.AreEqual(DBNull.Value, dt.Rows[0][1]);
            Assert.AreEqual(DBNull.Value, dt.Rows[0][2]);
            Assert.AreEqual(DBNull.Value, dt.Rows[0][3]);
        }
Beispiel #15
0
        public void Test_upload_table()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable tb = (BasicTable)db.run("table(1..100 as id,take(`aaa,100) as name,rand(1.01,100) as dbl)");
            Dictionary <string, IEntity> upObj = new Dictionary <string, IEntity>();

            upObj.Add("table_uploaded", (IEntity)tb);
            db.upload(upObj);
            BasicIntVector v = (BasicIntVector)db.run("table_uploaded.id");

            Assert.AreEqual(100, v.rows());
        }
Beispiel #16
0
 public BasicTable getUnwrittenData(string dbName, string tableName)
 {
     try
     {
         List <IVector>         cols = new List <IVector>();
         List <List <IScalar> > data = new List <List <IScalar> >();
         rwLock_.EnterReadLock();
         if (!destTables_.ContainsKey(Tuple.Create <string, string>(dbName, tableName)))
         {
             throw new Exception("Failed to get unwritten data.Please use addTable to add infomation of database and table first.");
         }
         DestTable destTable = destTables_[Tuple.Create <string, string>(dbName, tableName)];
         int       columns   = destTable.colTypes.Count();
         lock (destTable.failQueue)
         {
             while (destTable.failQueue.Count() != 0)
             {
                 if (destTable.failQueue.TryDequeue(out List <IScalar> queueData))
                 {
                     data.Add(queueData);
                 }
             }
         }
         while (destTable.writeQueue.Count() != 0)
         {
             if (destTable.writeQueue.TryDequeue(out List <IScalar> queueData))
             {
                 data.Add(queueData);
             }
         }
         int size = data.Count();
         BasicEntityFactory factory = new BasicEntityFactory();
         for (int i = 0; i < destTable.colTypes.Count(); ++i)
         {
             IVector vector = factory.createVectorWithDefaultValue(destTable.colTypes[i], size);
             for (int j = 0; j < size; ++j)
             {
                 vector.set(j, data[j][i]);
             }
             cols.Add(vector);
         }
         BasicTable ret = new BasicTable(destTable.colNames, cols);
         return(ret);
     }
     finally
     {
         rwLock_.ExitReadLock();
     }
 }
Beispiel #17
0
        public void Initialice(string applicationPath, string applicationDataPath)
        {
            this.m_comLockObj          = Guid.NewGuid();
            this.m_applicationPath     = applicationPath;
            this.m_applicationDataPath = applicationDataPath;

            this.m_masterData = new Working.MasterData();
            this.m_supplier   = new Working.Supplier();
            this.m_position   = new Working.Positions();

            this.m_materialCategoryTable = BasicTable.OpenDataTable <MaterialCategoryTable>(applicationDataPath);
            this.m_manufacturerTable     = BasicTable.OpenDataTable <ManufacturerTable>(applicationDataPath);
            this.m_supplierTable         = BasicTable.OpenDataTable <SupplierTable>(applicationDataPath);
            this.m_positionsTable        = BasicTable.OpenDataTable <PositionsTable>(applicationDataPath);
        }
        public void Test_run_return_table_toDataTable()
        {
            DBConnection db = new DBConnection();

            db.connect("192.168.1.61", 8702);
            BasicTable tb = (BasicTable)db.run("table(1..100 as id,take(`aaa,100) as name)");
            DataTable  dt = tb.ToDataTable();

            Assert.AreEqual(100, dt.Rows.Count);
            Assert.AreEqual(100, dt.DefaultView.Count);
            dt.Rows[0].Delete();
            Assert.AreEqual(99, dt.Rows.Count);
            DataRow[] drs = dt.Select("id > 50");
            Assert.AreEqual(50, drs.Length);
            dt.DefaultView.RowFilter = "id > 50 and name = 'abc'";
            Assert.AreEqual(0, dt.DefaultView.Count);
        }
Beispiel #19
0
        public void blob_imemory_table_download()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);

            db.run("a=table(100:0, `id`value`memo, [INT, DOUBLE, BLOB])");
            db.run("insert into a values(10,0.5, '[{\"name\":\"shily\",\"sex\":\"女\",\"age\":\"23\"},{\"name\":\"shily\",\"sex\":\"女\",\"age\":\"23\"},{\"name\":\"shily\",\"sex\":\"女\",\"age\":\"23\"}]')");
            BasicTable tb = (BasicTable)db.run("a");

            Assert.IsTrue(tb.isTable());
            Assert.AreEqual(1, tb.rows());
            Assert.AreEqual(3, tb.columns());
            Assert.AreEqual("[{\"name\":\"shily\",\"sex\":\"女\",\"age\":\"23\"},{\"name\":\"shily\",\"sex\":\"女\",\"age\":\"23\"},{\"name\":\"shily\",\"sex\":\"女\",\"age\":\"23\"}]", ((BasicString)tb.getColumn(2).get(0)).getValue());

            db.close();
        }
Beispiel #20
0
        public void Test_Upload_DataTable()
        {
            DataTable  dt = new DataTable();
            DataColumn dc = new DataColumn("dt_string", Type.GetType("System.String"));

            dt.Columns.Add(dc);
            dc = new DataColumn("dt_short", Type.GetType("System.Int16"));
            dt.Columns.Add(dc);
            dc = new DataColumn("dt_int", Type.GetType("System.Int32"));
            dt.Columns.Add(dc);
            dc = new DataColumn("dt_long", Type.GetType("System.Int64"));
            dt.Columns.Add(dc);
            dc = new DataColumn("dt_double", Type.GetType("System.Int32"));
            dt.Columns.Add(dc);
            dc = new DataColumn("dt_datetime", Type.GetType("System.DateTime"));
            dt.Columns.Add(dc);
            dc = new DataColumn("dt_bool", Type.GetType("System.Boolean"));
            dt.Columns.Add(dc);
            dc = new DataColumn("dt_byte", Type.GetType("System.Byte"));
            dt.Columns.Add(dc);
            dc = new DataColumn("dt_string", Type.GetType("System.String"));
            dt.Columns.Add(dc);
            DataRow dr = dt.NewRow();

            dr["dt_short"]    = 1;
            dr["dt_int"]      = 2147483646;
            dr["dt_long"]     = 2147483649;
            dr["dt_double"]   = 3.14159893984;
            dr["dt_datetime"] = new DateTime(2018, 03, 30, 14, 59, 02, 111);
            dr["dt_bool"]     = false;
            dr["dt_byte"]     = (byte)97;
            dr["dt_string"]   = "test_string";
            dt.Rows.Add(dr);
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            BasicTable bt = new BasicTable(dt);
            Dictionary <string, IEntity> obj = new Dictionary <string, IEntity>();

            obj.Add("up_datatable", (IEntity)bt);
            db.upload(obj);
            BasicIntVector v = (BasicIntVector)db.run("up_datatable.dt_int");

            Assert.AreEqual(2147483646, v.get(0));
        }
Beispiel #21
0
        public static string AttemptTranslate(byte code, int depthLeft = 2)
        {
            if (code < 0x30)
            {
                return($"{{{code.ToString("x2")}}}");
            }
            else if (code >= 0x80)
            {
                return(BasicTable.Lookup(code));
            }
            else if (depthLeft == 0)
            {
                return($"{{{code.ToString("x2")}}}");
            }
            var text = string.Join("", LookupBytes(code).Select(x => AttemptTranslate(x, depthLeft - 1)));

            return(text);
        }
Beispiel #22
0
        private BasicTable scanTable(string tableName, Row schema)
        {
            long tbid     = Database.BaseTables.sysschobjs.Where(x => x.name == tableName).SingleOrDefault().id;
            long rowsetid = Database.BaseTables.sysidxstats.Where(x => x.id == tbid).SingleOrDefault().rowset;
            long size     = Database.BaseTables.sysrowsets.Where(x => x.rowsetid == rowsetid).SingleOrDefault().rcrows;

            cols = getAllColumn(schema, (int)size);
            // Get object
            var tableObject = Database.BaseTables.sysschobjs
                              .Where(x => x.name == tableName)
                              .Where(x => x.type.Trim() == ObjectType.INTERNAL_TABLE || x.type.Trim() == ObjectType.SYSTEM_TABLE || x.type.Trim() == ObjectType.USER_TABLE)
                              .SingleOrDefault();

            if (tableObject == null)
            {
                throw new ArgumentException("Table does not exist.");
            }

            // Get rowset, prefer clustered index if exists
            var partitions = Database.Dmvs.Partitions
                             .Where(x => x.ObjectID == tableObject.id && x.IndexID <= 1)
                             .OrderBy(x => x.PartitionNumber);

            if (partitions.Count() == 0)
            {
                throw new ArgumentException("Table has no partitions.");
            }

            // Loop all partitions and return results one by one
            List <string> colNames = new List <string>();

            foreach (var n in schema.Columns)
            {
                colNames.Add(n.Name);
            }

            foreach (var partition in partitions)
            {
                scanPartition(partition.PartitionID, partition.PartitionNumber, schema);
            }
            BasicTable bt = new BasicTable(colNames, cols);

            return(bt);
        }
Beispiel #23
0
        public void Test_WriteLocalTableToDfs()
        {
            //=======================prepare data to writing into dfs database =======================
            List <string> colNames = new List <string>()
            {
                "sym", "dt", "prc", "cnt"
            };
            BasicStringVector symVec = new BasicStringVector(new List <string>()
            {
                "MS", "GOOG", "FB"
            });
            BasicDateTimeVector dtVec = new BasicDateTimeVector(new List <int?>()
            {
                Utils.countSeconds(DateTime.Now), Utils.countSeconds(DateTime.Now), Utils.countSeconds(DateTime.Now)
            });
            BasicDoubleVector prcVec = new BasicDoubleVector(new double[] { 101.5, 132.75, 37.96 });
            BasicIntVector    cntVec = new BasicIntVector(new int[] { 50, 78, 88 });

            List <IVector> cols = new List <IVector>()
            {
                (IVector)symVec, (IVector)dtVec, (IVector)prcVec, (IVector)cntVec
            };
            BasicTable table1 = new BasicTable(colNames, cols);
            //======================================================================================

            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            db.login("admin", "123456", false);//login
            //prepare dfs database and table
            db.run("if(existsDatabase('dfs://testDatabase')){dropDatabase('dfs://testDatabase')}");
            db.run("db = database('dfs://testDatabase',VALUE,'MS' 'GOOG' 'FB')");
            db.run("tb= table('MS' as sym,datetime(now()) as dt,1.01 as prc,1 as cnt)");
            db.run("db.createPartitionedTable(tb,'tb1','sym')");

            db.run("def saveQuotes(t){ loadTable('dfs://testDatabase','tb1').append!(t)}");
            List <IEntity> args = new List <IEntity>(1);

            args.Add(table1);
            db.run("saveQuotes", args);
        }
Beispiel #24
0
        ///
        /// <param name="tableName"> name of the shared table </param>
        /// <param name="host"> host </param>
        /// <param name="port"> port </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public TableAppender(String tableName, String host, int port) throws java.io.IOException
        public TableAppender(string tableName, string host, int port)
        {
            this.tableName = new BasicString(tableName);
            this.conn      = new DBConnection();
            try
            {
                this.conn.connect(host, port);
                tableInfo = (BasicDictionary)conn.run("schema(" + tableName + ")");
                int partitionColumnIdx = ((BasicInt)tableInfo.get(new BasicString("partitionColumnIndex"))).Int;
                if (partitionColumnIdx != -1)
                {
                    throw new Exception("Table '" + tableName + "' is partitioned");
                }
                BasicTable colDefs = ((BasicTable)tableInfo.get(new BasicString("colDefs")));
                this.cols = colDefs.getColumn(0).rows();
            }
            catch (IOException e)
            {
                throw e;
            }
        }
Beispiel #25
0
    public void writeDfsTable()
    {
        BasicTable table1 = createBasicTable();

        conn.login("admin", "123456", false);
        conn.run("t = table(10000:0,`cbool`cchar`cshort`cint`clong`cdate`cmonth`ctime`cminute`csecond`cdatetime`ctimestamp`cnanotime`cnanotimestamp`cfloat`cdouble`csymbol`cstring,[BOOL,CHAR,SHORT,INT,LONG,DATE,MONTH,TIME,MINUTE,SECOND,DATETIME,TIMESTAMP,NANOTIME,NANOTIMESTAMP,FLOAT,DOUBLE,SYMBOL,STRING])\n");
        conn.run("if(existsDatabase('dfs://testDatabase')){dropDatabase('dfs://testDatabase')}");
        conn.run("db = database('dfs://testDatabase',RANGE,2018.01.01..2018.12.31)");
        conn.run("db.createPartitionedTable(t,'tb1','cdate')");
        conn.run("def saveData(data){ loadTable('dfs://testDatabase','tb1').tableInsert(data)}");
        List <IEntity> args = new List <IEntity>(1);

        args.Add(table1);
        conn.run("saveData", args);
        BasicTable dt = (BasicTable)conn.run("select * from loadTable('dfs://testDatabase','tb1')");

        if (dt.rows() != 2)
        {
            Console.WriteLine("failed");
        }
    }
Beispiel #26
0
        public void Test_ContructBasicTableByDataTable()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("dt", Type.GetType("System.DateTime"));
            dt.Columns.Add("bl", Type.GetType("System.Boolean"));
            dt.Columns.Add("sb", Type.GetType("System.Byte"));
            dt.Columns.Add("db", Type.GetType("System.Double"));
            dt.Columns.Add("ts", Type.GetType("System.TimeSpan"));
            dt.Columns.Add("i1", Type.GetType("System.Int16"));
            dt.Columns.Add("i3", Type.GetType("System.Int32"));
            dt.Columns.Add("i6", Type.GetType("System.Int64"));
            dt.Columns.Add("s", Type.GetType("System.String"));
            DataRow dr = dt.NewRow();

            dr["dt"] = DBNull.Value;
            dr["bl"] = DBNull.Value;
            dr["sb"] = DBNull.Value;
            dr["db"] = DBNull.Value;
            dr["ts"] = DBNull.Value;
            dr["i1"] = DBNull.Value;
            dr["i3"] = DBNull.Value;
            dr["i6"] = DBNull.Value;
            dr["s"]  = DBNull.Value;
            dt.Rows.Add(dr);
            BasicTable bt = new BasicTable(dt);

            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            Dictionary <string, IEntity> obj = new Dictionary <string, IEntity>();

            obj.Add("up_datatable", (IEntity)bt);
            db.upload(obj);
            db.run("share up_datatable as tb1");

            BasicStringVector bsv = (BasicStringVector)bt.getColumn(8);

            Assert.AreEqual("", bsv.get(0).getString());
        }
Beispiel #27
0
        public void blob_imemory_table_upload_download_bigdata()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            db.run("share table(blob(`d`f) as blob)as st");
            List <String> colNames = new List <String>(1);

            colNames.Add("str");
            List <IVector>    cols = new List <IVector>(1);
            BasicStringVector vec  = new BasicStringVector(1000);
            BasicString       str  = (BasicString)db.run("mt=table(take(1..1000000,1000) as id,take(`fyf``ftf`ddtjtydtyty`通常都是,1000) as str,take(`fyf``ftf`ddtjtydtyty`通常都是,1000) as str1," +
                                                         "take(`fyf``ftf`ddtjtydtyty`通常都是,1000) as str2);mt.toStdJson()");
            String tmp = str.getString();

            for (int i = 0; i < 1000; i++)
            {
                vec.setString(i, tmp + i.ToString());
            }
            cols.Add(vec);
            BasicTable     tb  = new BasicTable(colNames, cols);
            List <IEntity> arg = new List <IEntity>()
            {
                tb
            };

            // for (int i = 0; i < 100; i++)
            //  {
            db.run("tableInsert{st}", arg);
            // }

            BasicTable st = (BasicTable)db.run("st");

            Assert.AreEqual(1000, tb.rows());
            Assert.AreEqual(1, tb.columns());
            Assert.AreEqual(tmp + 8.ToString(), ((BasicTable)st).getColumn(0).get(10).getString());
        }
Beispiel #28
0
        public void Test_ConstructBasicTableWithDataTable()
        {
            DataTable dt = new DataTable();

            dt.Columns.Add("col_string", Type.GetType("System.String"));
            dt.Columns.Add("col_date", Type.GetType("System.DateTime"));
            dt.Columns.Add("col_time", Type.GetType("System.TimeSpan"));
            dt.Columns.Add("col_int", Type.GetType("System.Int16"));
            dt.Columns.Add("col_double", Type.GetType("System.Double"));
            dt.Columns.Add("col_long", Type.GetType("System.Int64"));
            dt.Columns.Add("col_char", Type.GetType("System.Char"));
            dt.Columns.Add("col_bool", Type.GetType("System.Boolean"));

            DataRow dr = dt.NewRow();

            dr["col_string"] = "test";
            dr["col_date"]   = new DateTime(2018, 07, 25, 15, 14, 23);
            dr["col_time"]   = new TimeSpan(25, 15, 15, 14, 123);
            dr["col_int"]    = 123;
            dr["col_double"] = 3.1415926;
            dr["col_long"]   = 2147483647;
            dr["col_char"]   = 'X';
            dr["col_bool"]   = true;
            dt.Rows.Add(dr);

            BasicTable bt = new BasicTable(dt);

            double[] a = (double[])bt.getColumn(4).getList();
            long[]   b = (long[])bt.getColumn(5).getList();


            Assert.AreEqual(DATA_TYPE.DT_STRING, bt.getColumn(0).getDataType());
            Assert.AreEqual(DATA_TYPE.DT_DATETIME, bt.getColumn(1).getDataType());
            Assert.AreEqual(DATA_TYPE.DT_TIME, bt.getColumn(2).getDataType());
            Assert.AreEqual(DATA_TYPE.DT_SHORT, bt.getColumn(3).getDataType());
        }
Beispiel #29
0
    private BasicTable createBasicTable()
    {
        List <string> colNames = new List <string>();

        colNames.Add("cbool");
        colNames.Add("cchar");
        colNames.Add("cshort");
        colNames.Add("cint");
        colNames.Add("clong");
        colNames.Add("cdate");
        colNames.Add("cmonth");
        colNames.Add("ctime");
        colNames.Add("cminute");
        colNames.Add("csecond");
        colNames.Add("cdatetime");
        colNames.Add("ctimestamp");
        colNames.Add("cnanotime");
        colNames.Add("cnanotimestamp");
        colNames.Add("cfloat");
        colNames.Add("cdouble");
        colNames.Add("csymbol");
        colNames.Add("cstring");
        List <IVector> cols = new List <IVector>();


        //boolean
        byte[]             vbool = new byte[] { 1, 0 };
        BasicBooleanVector bbv   = new BasicBooleanVector(vbool);

        cols.Add(bbv);
        //char
        byte[]          vchar = new byte[] { (byte)'c', (byte)'a' };
        BasicByteVector bcv   = new BasicByteVector(vchar);

        cols.Add(bcv);
        //cshort
        short[]          vshort = new short[] { 32767, 29 };
        BasicShortVector bshv   = new BasicShortVector(vshort);

        cols.Add(bshv);
        //cint
        int[]          vint  = new int[] { 2147483647, 483647 };
        BasicIntVector bintv = new BasicIntVector(vint);

        cols.Add(bintv);
        //clong
        long[]          vlong  = new long[] { 2147483647, 483647 };
        BasicLongVector blongv = new BasicLongVector(vlong);

        cols.Add(blongv);
        //cdate
        int[]           vdate  = new int[] { Utils.countDays(new DateTime(2018, 2, 14)), Utils.countDays(new DateTime(2018, 8, 15)) };
        BasicDateVector bdatev = new BasicDateVector(vdate);

        cols.Add(bdatev);
        //cmonth
        int[]            vmonth  = new int[] { Utils.countMonths(new DateTime(2018, 2, 6)), Utils.countMonths(new DateTime(2018, 8, 11)) };
        BasicMonthVector bmonthv = new BasicMonthVector(vmonth);

        cols.Add(bmonthv);
        //ctime
        int[]           vtime  = new int[] { Utils.countMilliseconds(16, 46, 05, 123), Utils.countMilliseconds(18, 32, 05, 321) };
        BasicTimeVector btimev = new BasicTimeVector(vtime);

        cols.Add(btimev);
        //cminute
        int[]             vminute  = new int[] { Utils.countMinutes(new TimeSpan(16, 30, 00)), Utils.countMinutes(new TimeSpan(9, 30, 00)) };
        BasicMinuteVector bminutev = new BasicMinuteVector(vminute);

        cols.Add(bminutev);
        //csecond
        int[]             vsecond  = new int[] { Utils.countSeconds(new TimeSpan(16, 30, 00)), Utils.countSeconds(new TimeSpan(16, 30, 50)) };
        BasicSecondVector bsecondv = new BasicSecondVector(vsecond);

        cols.Add(bsecondv);
        //cdatetime
        int[] vdatetime = new int[] { Utils.countSeconds(new DateTime(2018, 9, 8, 9, 30, 01)), Utils.countSeconds(new DateTime(2018, 11, 8, 16, 30, 01)) };
        BasicDateTimeVector bdatetimev = new BasicDateTimeVector(vdatetime);

        cols.Add(bdatetimev);
        //ctimestamp
        long[] vtimestamp = new long[] { Utils.countMilliseconds(2018, 11, 12, 9, 30, 01, 123), Utils.countMilliseconds(2018, 11, 12, 16, 30, 01, 123) };
        BasicTimestampVector btimestampv = new BasicTimestampVector(vtimestamp);

        cols.Add(btimestampv);
        //cnanotime
        long[] vnanotime = new long[] { Utils.countNanoseconds(new TimeSpan(9, 30, 05, 1234567)), Utils.countNanoseconds(new TimeSpan(16, 30, 05, 9876543)) };
        BasicNanoTimeVector bnanotimev = new BasicNanoTimeVector(vnanotime);

        cols.Add(bnanotimev);
        //cnanotimestamp
        long[] vnanotimestamp = new long[] { Utils.countNanoseconds(new DateTime(2018, 11, 12, 9, 30, 05, 123)), Utils.countNanoseconds(new DateTime(2018, 11, 13, 16, 30, 05, 987)) };
        BasicNanoTimestampVector bnanotimestampv = new BasicNanoTimestampVector(vnanotimestamp);

        cols.Add(bnanotimestampv);
        //cfloat
        float[]          vfloat  = new float[] { 2147.483647f, 483.647f };
        BasicFloatVector bfloatv = new BasicFloatVector(vfloat);

        cols.Add(bfloatv);
        //cdouble
        double[]          vdouble  = new double[] { 214.7483647, 48.3647 };
        BasicDoubleVector bdoublev = new BasicDoubleVector(vdouble);

        cols.Add(bdoublev);
        //csymbol
        String[]          vsymbol  = new String[] { "GOOG", "MS" };
        BasicStringVector bsymbolv = new BasicStringVector(vsymbol);

        cols.Add(bsymbolv);
        //cstring
        String[]          vstring  = new String[] { "", "test string" };
        BasicStringVector bstringv = new BasicStringVector(vstring);

        cols.Add(bstringv);
        BasicTable t1 = new BasicTable(colNames, cols);

        return(t1);
    }
Beispiel #30
0
        /**
         * Add the name of the database and table that you want to insert data into before actually call insert.
         * The parameter partitioned indicates whether the added table is a partitioned table. If this function
         * is called to add an in-memory table, the parameter dbName indicates the name of the shared in-memory
         * table, and the parameter tableName should be a null string. If error is raised on the server, this
         * function throws an exception.
         */
        public void addTable(string dbName, string tableName = "", bool partitioned = true)
        {
            try
            {
                rwLock_.EnterReadLock();
                if (destTables_.ContainsKey(Tuple.Create <string, string>(dbName, tableName)))
                {
                    throw new Exception("Failed to add table, the specified table has not been removed yet.");
                }
            }
            finally
            {
                rwLock_.ExitReadLock();
            }
            DBConnection conn = new DBConnection(false, false);
            bool         ret  = conn.connect(hostName_, port_, userId_, password_);

            if (!ret)
            {
                throw new Exception("Failed to connect to server.");
            }
            string          tableInsert;
            string          saveTable = "";
            BasicDictionary schema;
            string          tmpDiskGlobal = "tmpDiskGlobal";

            if (tableName == "")
            {
                tableInsert = "tableInsert{" + dbName + "}";
                schema      = (BasicDictionary)conn.run("schema(" + dbName + ")");
            }
            else if (partitioned)
            {
                tableInsert = "tableInsert{loadTable(\"" + dbName + "\",\"" + tableName + "\")}";
                schema      = (BasicDictionary)conn.run("schema(loadTable(\"" + dbName + "\",\"" + tableName + "\"))");
            }
            else
            {
                throw new Exception("The target table must be an in-memory table or a table in a distributed database.");
            }

            BasicTable colDefs = (BasicTable)schema.get(new BasicString("colDefs"));

            DestTable destTable;

            if (destTables_.ContainsKey(Tuple.Create <string, string>(dbName, tableName)))
            {
                throw new Exception("Failed to add table, the specified table has not been removed yet.");
            }
            destTable = new DestTable();

            destTable.dbName         = dbName;
            destTable.tableName      = tableName;
            destTable.conn           = conn;
            destTable.tableInsert    = tableInsert;
            destTable.saveTable      = saveTable;
            destTable.colDefs        = colDefs;
            destTable.columnNum      = colDefs.rows();
            destTable.colDefsTypeInt = (BasicIntVector)colDefs.getColumn("typeInt");
            destTable.destroy        = false;
            destTable.writeQueue     = new ConcurrentQueue <List <IScalar> >();
            destTable.failQueue      = new ConcurrentQueue <List <IScalar> >();

            List <string>     colNames    = new List <string>();
            List <DATA_TYPE>  colTypes    = new List <DATA_TYPE>();
            BasicStringVector colDefsName = (BasicStringVector)colDefs.getColumn("name");

            for (int i = 0; i < destTable.columnNum; i++)
            {
                colNames.Add(colDefsName.getString(i));
                colTypes.Add((DATA_TYPE)destTable.colDefsTypeInt.getInt(i));
            }
            destTable.colNames = colNames;
            destTable.colTypes = colTypes;

            if (!partitioned)
            {
                string            colName           = "";
                string            colType           = "";
                BasicStringVector colDefsTypeString = (BasicStringVector)colDefs.getColumn("typeString");
                for (int i = 0; i < destTable.columnNum; i++)
                {
                    colName = colName + "`" + colDefsName.getString(i);
                    colType = colType + "`" + colDefsTypeString.getString(i);
                }
                destTable.createTmpSharedTable = "share table(" + "1000:0," + colName + "," + colType + ") as " + tmpDiskGlobal;
            }
            try
            {
                rwLock_.EnterWriteLock();
                if (destTables_.ContainsKey(Tuple.Create <string, string>(dbName, tableName)))
                {
                    throw new Exception("Failed to add table, the specified table has not been removed yet.");
                }
                destTables_[Tuple.Create <string, string>(dbName, tableName)] = destTable;
                WriteThread writeThreadFuc = new WriteThread(destTable, partitioned);
                destTable.writeThread = new Thread(writeThreadFuc.run);
                destTable.writeThread.Start();
            }

            finally
            {
                rwLock_.ExitWriteLock();
            }
        }