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 #2
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 #3
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 #4
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());
        }
Exemple #5
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);
        }