Exemple #1
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);
        }
        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);
        }
Exemple #3
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());
        }
Exemple #4
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;
            }
        }
Exemple #5
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());
        }
Exemple #6
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());
        }
Exemple #7
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();
            }
        }
        /**
         * If fail to connect to the specified DolphinDB server, this function throw an exception.
         */
        public MultithreadedTableWriter(string hostName, int port, string userId, string password,
                                        string dbName, string tableName, bool useSSL, bool enableHighAvailability = false, string[] pHighAvailabilitySites = null,
                                        int batchSize = 1, float throttle = 0.01f, int threadCount = 5, string partitionCol = "", int[] pCompressMethods = null)
        {
            hostName_          = hostName;
            port_              = port;
            userId_            = userId;
            password_          = password;
            useSSL_            = useSSL;
            dbName_            = dbName;
            tableName_         = tableName;
            batchSize_         = batchSize;
            throttleMilsecond_ = (int)throttle * 1000;
            isExiting_         = false;
            if (threadCount < 1)
            {
                throw new Exception("The parameter threadCount must be greater than or equal to 1.");
            }
            if (batchSize < 1)
            {
                throw new Exception("The parameter batchSize must be greater than or equal to 1.");
            }
            if (throttle < 0)
            {
                throw new Exception("The parameter throttle must be positive.");
            }
            if (threadCount > 1 && partitionCol == String.Empty)
            {
                throw new Exception("The parameter partitionCol must be specified when threadCount is greater than 1.");
            }
            DBConnection pConn = new DBConnection(false, useSSL_, pCompressMethods != null);
            bool         ret   = pConn.connect(hostName_, port_, userId_, password_, "", enableHighAvailability, pHighAvailabilitySites);

            if (!ret)
            {
                throw new Exception(string.Format("Failed to connect to server {0}:{1}. ", hostName, port));
            }
            BasicDictionary schema;

            if (tableName == "")
            {
                schema = (BasicDictionary)pConn.run("schema(" + dbName + ")");
            }
            else
            {
                schema = (BasicDictionary)pConn.run("schema(loadTable(\"" + dbName + "\",\"" + tableName + "\"))");
            }
            IEntity partColNames = null;

            if (schema.ContainsKey("partitionColumnName"))
            {
                partColNames      = schema.get(new BasicString("partitionColumnName"));
                isPartionedTable_ = true;
            }
            else
            {
                isPartionedTable_ = false;
                if (tableName != "")
                {
                    if (threadCount > 1)
                    {//只有多线程的时候需要
                        throw new Exception("The parameter threadCount must be 1 for a dimension table.");
                    }
                }
            }
            BasicTable colDefs = (BasicTable)schema.get("colDefs");

            BasicIntVector colDefsTypeInt = (BasicIntVector)colDefs.getColumn("typeInt");

            BasicStringVector colDefsName       = (BasicStringVector)colDefs.getColumn("name");
            BasicStringVector colDefsTypeString = (BasicStringVector)colDefs.getColumn("typeString");

            colTypes_      = new List <DATA_TYPE>();
            colNames_      = new List <string>();
            colTypeString_ = new List <string>();
            int columnSize = colDefsName.rows();

            if (pCompressMethods != null)
            {
                if (columnSize != pCompressMethods.Length)
                {
                    throw new Exception(string.Format("The number of elements in parameter compressMethods does not match the column size {0}. ", columnSize));
                }
                this.compressTypes_ = new int[columnSize];
                Array.Copy(pCompressMethods, this.compressTypes_, columnSize);
            }
            for (int i = 0; i < columnSize; i++)
            {
                colNames_.Add(colDefsName.getString(i));
                colTypes_.Add((DATA_TYPE)colDefsTypeInt.getInt(i));
                colTypeString_.Add(colDefsTypeString.getString(i));
                if (compressTypes_ != null)
                {
                    AbstractVector.checkCompressedMethod(colTypes_[i], compressTypes_[i]);
                }
            }

            if (threadCount > 1)
            {
                if (isPartionedTable_)
                {
                    IEntity partitionSchema;
                    int     partitionType;
                    if (partColNames.isScalar())
                    {
                        if (partColNames.getString() != partitionCol)
                        {
                            throw new Exception(string.Format("The parameter partionCol must be the partitioning column \"{0}\" in the table. ", partitionCol));
                        }
                        partitionColumnIdx_ = ((BasicInt)schema.get("partitionColumnIndex")).getInt();
                        partitionSchema     = schema.get("partitionSchema");
                        partitionType       = ((BasicInt)schema.get("partitionType")).getInt();
                    }
                    else
                    {
                        int dims = ((BasicStringVector)partColNames).rows();
                        if (dims > 1 && partitionCol == "")
                        {
                            throw new Exception("The parameter partitionCol must be specified when threadCount is greater than 1.");
                        }
                        int index = -1;
                        for (int i = 0; i < dims; ++i)
                        {
                            if (((BasicStringVector)partColNames).getString(i) == partitionCol)
                            {
                                index = i;
                                break;
                            }
                        }
                        if (index < 0)
                        {
                            throw new Exception(string.Format("The parameter partionCol must be the partitioning column \"{0}\" in the table. ", partitionCol));
                        }
                        partitionColumnIdx_ = ((BasicIntVector)schema.get("partitionColumnIndex")).getInt(index);
                        partitionSchema     = ((BasicAnyVector)schema.get("partitionSchema")).get(index);
                        partitionType       = ((BasicIntVector)schema.get("partitionType")).getInt(index);
                    }
                    DATA_TYPE partitionColType = colTypes_[partitionColumnIdx_];
                    partitionDomain_ = DomainFactory.createDomain((PARTITION_TYPE)partitionType, partitionColType, partitionSchema);
                }
                else
                {//isPartionedTable_==false
                    if (partitionCol != "")
                    {
                        int threadcolindex = -1;
                        for (int i = 0; i < colNames_.Count; i++)
                        {
                            if (colNames_[i] == partitionCol)
                            {
                                threadcolindex = i;
                                break;
                            }
                        }
                        if (threadcolindex < 0)
                        {
                            throw new Exception(string.Format("No match found for {0}. ", partitionCol));
                        }
                        threadByColIndexForNonPartion_ = threadcolindex;
                    }
                }
            }

            // init done, start thread now.
            isExiting_ = false;
            threads_   = new List <WriterThread>(threadCount);
            for (int i = 0; i < threadCount; i++)
            {
                WriterThread writerThread = new WriterThread(this, pConn);
                if (i == 0)
                {
                    writerThread.conn_ = pConn;
                }
                else
                {
                    writerThread.conn_ = new DBConnection(useSSL_, false);
                    if (writerThread.conn_.connect(hostName_, port_, userId_, password_, "", enableHighAvailability, pHighAvailabilitySites) == false)
                    {
                        throw new Exception(string.Format("Failed to connect to server {0}:{1}. ", hostName, port));
                    }
                }
                threads_.Add(writerThread);
            }
        }
Exemple #9
0
        public void test_fillSchema()
        {
            DBConnection conn = new DBConnection();

            conn.connect(SERVER, PORT);
            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 < 10; 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(25, 15, 15, 14, 123);
                dt.Rows.Add(dr);
            }
            Dictionary <string, DATA_TYPE> var1 = new Dictionary <string, DATA_TYPE>();

            var1.Add("时间戳", DATA_TYPE.DT_DATE);
            BasicTable bt1 = Utils.fillSchema(dt, var1);

            Assert.AreEqual(bt1.getColumn("时间戳").getDataType(), var1["时间戳"]);
            Assert.AreEqual(((BasicDate)bt1.getColumn("时间戳").get(0)).getValue(), new DateTime(2021, 1, 26, 0, 0, 0));

            Dictionary <string, DATA_TYPE> var2 = new Dictionary <string, DATA_TYPE>();

            var2.Add("时间戳", DATA_TYPE.DT_MONTH);
            BasicTable bt2 = Utils.fillSchema(dt, var2);

            Assert.AreEqual(bt2.getColumn("时间戳").getDataType(), var2["时间戳"]);
            Assert.AreEqual(((BasicMonth)bt2.getColumn("时间戳").get(0)).getValue(), new DateTime(2021, 1, 1, 0, 0, 0));


            Dictionary <string, DATA_TYPE> var3 = new Dictionary <string, DATA_TYPE>();

            var3.Add("时间戳", DATA_TYPE.DT_TIME);
            var3.Add("timespan", DATA_TYPE.DT_TIME);
            BasicTable bt3 = Utils.fillSchema(dt, var3);

            Assert.AreEqual(bt3.getColumn("时间戳").getDataType(), var3["时间戳"]);
            Assert.AreEqual(((BasicTime)bt3.getColumn("时间戳").get(0)).getValue(), new TimeSpan(15, 1, 2));
            Assert.AreEqual(bt3.getColumn("timespan").getDataType(), var3["timespan"]);
            Assert.AreEqual(((BasicTime)bt3.getColumn("timespan").get(0)).getValue(), new TimeSpan(0, 15, 15, 14, 123));


            Dictionary <string, DATA_TYPE> var4 = new Dictionary <string, DATA_TYPE>();

            var4.Add("时间戳", DATA_TYPE.DT_MINUTE);
            var4.Add("timespan", DATA_TYPE.DT_MINUTE);
            BasicTable bt4 = Utils.fillSchema(dt, var4);

            Assert.AreEqual(bt4.getColumn("时间戳").getDataType(), var4["时间戳"]);
            Assert.AreEqual(((BasicMinute)bt4.getColumn("时间戳").get(0)).getValue(), new TimeSpan(15, 1, 0));
            Assert.AreEqual(bt4.getColumn("timespan").getDataType(), var4["timespan"]);
            Assert.AreEqual(((BasicMinute)bt4.getColumn("timespan").get(0)).getValue(), new TimeSpan(0, 15, 15, 0, 0));


            Dictionary <string, DATA_TYPE> var5 = new Dictionary <string, DATA_TYPE>();

            var5.Add("时间戳", DATA_TYPE.DT_SECOND);
            var5.Add("timespan", DATA_TYPE.DT_SECOND);
            BasicTable bt5 = Utils.fillSchema(dt, var5);

            Assert.AreEqual(bt5.getColumn("时间戳").getDataType(), var5["时间戳"]);
            Assert.AreEqual(((BasicSecond)bt5.getColumn("时间戳").get(0)).getValue(), new TimeSpan(15, 1, 2));
            Assert.AreEqual(bt5.getColumn("timespan").getDataType(), var5["timespan"]);
            Assert.AreEqual(((BasicSecond)bt5.getColumn("timespan").get(0)).getValue(), new TimeSpan(0, 15, 15, 14, 0));


            Dictionary <string, DATA_TYPE> var6 = new Dictionary <string, DATA_TYPE>();

            var6.Add("时间戳", DATA_TYPE.DT_DATETIME);
            BasicTable bt6 = Utils.fillSchema(dt, var6);

            Assert.AreEqual(bt6.getColumn("时间戳").getDataType(), var6["时间戳"]);
            Assert.AreEqual(((BasicDateTime)bt6.getColumn("时间戳").get(0)).getValue(), new DateTime(2021, 1, 26, 15, 1, 2));

            Dictionary <string, DATA_TYPE> var7 = new Dictionary <string, DATA_TYPE>();

            var7.Add("时间戳", DATA_TYPE.DT_TIMESTAMP);
            BasicTable bt7 = Utils.fillSchema(dt, var7);

            Assert.AreEqual(bt7.getColumn("时间戳").getDataType(), var7["时间戳"]);
            Assert.AreEqual(((BasicTimestamp)bt7.getColumn("时间戳").get(0)).getValue(), new DateTime(2021, 1, 26, 15, 1, 2));


            Dictionary <string, DATA_TYPE> var8 = new Dictionary <string, DATA_TYPE>();

            var8.Add("时间戳", DATA_TYPE.DT_TIMESTAMP);
            BasicTable bt8 = Utils.fillSchema(dt, var8);

            Assert.AreEqual(bt8.getColumn("时间戳").getDataType(), var8["时间戳"]);
            Assert.AreEqual(((BasicTimestamp)bt8.getColumn("时间戳").get(0)).getValue(), new DateTime(2021, 1, 26, 15, 1, 2));

            Dictionary <string, DATA_TYPE> var9 = new Dictionary <string, DATA_TYPE>();

            var9.Add("时间戳", DATA_TYPE.DT_NANOTIME);
            var9.Add("timespan", DATA_TYPE.DT_NANOTIME);
            BasicTable bt9 = Utils.fillSchema(dt, var9);

            Assert.AreEqual(bt9.getColumn("时间戳").getDataType(), var9["时间戳"]);
            Assert.AreEqual(((BasicNanoTime)bt9.getColumn("时间戳").get(0)).getValue(), new TimeSpan(15, 1, 2));
            Assert.AreEqual(bt9.getColumn("timespan").getDataType(), var9["timespan"]);
            Assert.AreEqual(((BasicNanoTime)bt9.getColumn("timespan").get(0)).getValue(), new TimeSpan(0, 15, 15, 14, 123));

            Dictionary <string, DATA_TYPE> var10 = new Dictionary <string, DATA_TYPE>();

            var10.Add("时间戳", DATA_TYPE.DT_NANOTIMESTAMP);
            BasicTable bt10 = Utils.fillSchema(dt, var10);

            Assert.AreEqual(bt10.getColumn("时间戳").getDataType(), var10["时间戳"]);
            Assert.AreEqual(((BasicNanoTimestamp)bt10.getColumn("时间戳").get(0)).getValue(), new DateTime(2021, 1, 26, 15, 1, 2));
        }
Exemple #10
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();
        }
Exemple #11
0
        /*
         *  return null if get DT_VOID
         *  return table or throw exception if not DT_VOID
         */
        public static TableResult RunScriptAndFetchResultAsDataTable(DBConnection conn, string script)
        {
            IEntity entity = RunScript(conn, script);

            if (entity.getDataType() == DATA_TYPE.DT_VOID)
            {
                return(null);
            }

            TableResult result = new TableResult
            {
                srcForm       = entity.getDataForm(),
                columnSrcType = new List <DATA_TYPE>()
            };

            if (entity.isTable())
            {
                BasicTable basicTable = entity as BasicTable;
                for (int i = 0; i != basicTable.columns(); i++)
                {
                    result.columnSrcType.Add(basicTable.getColumn(i).getDataType());
                }

                result.table = basicTable.toDataTable();
                return(result);
            }

            result.table = entity.toDataTable();

            if (entity.isDictionary())
            {
                BasicDictionary basicDictionary = entity as BasicDictionary;
                result.columnSrcType.Add(basicDictionary.KeyDataType);
                result.columnSrcType.Add(basicDictionary.getDataType());
                return(result);
            }

            if (entity.isMatrix())
            {
                IMatrix m         = entity as IMatrix;
                IVector colLabels = m.getColumnLabels();
                if (!(colLabels == null || colLabels.columns() == 0))
                {
                    result.matrix_ColumnLabels = new List <string>();
                    for (int i = 0; i != colLabels.rows(); i++)
                    {
                        result.matrix_ColumnLabels.Add(colLabels.get(i).getString());
                    }
                }

                IVector rowLabels = m.getRowLabels();
                if (!(rowLabels == null || rowLabels.columns() == 0))
                {
                    result.matrix_RowLabels = new List <string>();
                    for (int i = 0; i != rowLabels.rows(); i++)
                    {
                        result.matrix_RowLabels.Add(rowLabels.get(i).getString());
                    }
                }
            }

            for (int i = 0; i != result.table.Columns.Count; i++)
            {
                result.columnSrcType.Add(entity.getDataType());
            }
            return(result);
        }