Exemplo n.º 1
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());
            }
        }
Exemplo n.º 2
0
        public void Test_MCorr()
        {
            DBConnection db = new DBConnection();

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

            obj.Add("x", (IEntity) new BasicIntVector(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }));
            obj.Add("y", (IEntity) new BasicIntVector(new int[] { 9, 5, 3, 4, 5, 4, 7, 1, 3, 4 }));
            db.upload(obj);
            BasicDoubleVector t = (BasicDoubleVector)db.run("ttt = nullFill!(mcorr(x,y,5),0);ttt");
        }
Exemplo n.º 3
0
        public void Test_Function_Double()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            List <IEntity>    args = new List <IEntity>(1);
            BasicDoubleVector vec  = new BasicDoubleVector(3);

            vec.setDouble(0, 1.5);
            vec.setDouble(1, 2.5);
            vec.setDouble(2, 7);

            args.Add(vec);
            BasicDouble result = (BasicDouble)db.run("sum", args);

            Assert.AreEqual(11, result.getValue());
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public void Test_GetList()
        {
            DBConnection db = new DBConnection();

            db.connect(SERVER, PORT);
            BasicIntVector iv = (BasicIntVector)db.run("1 2 3 4");

            int[] r = (int[])iv.getList();
            Assert.AreEqual(4, r.Length);

            BasicDoubleVector dv = (BasicDoubleVector)db.run("1.1 2.01 3.25 4.251441 3.32222");

            double[] dr = (double[])dv.getList();
            Assert.AreEqual(5, dr.Length);
            Assert.AreEqual(1.1, dr[0]);

            BasicLongVector lv = (BasicLongVector)db.run("102012522 12345678900 12221114455");

            long[] lr = (long[])lv.getList();
            Assert.AreEqual(3, lr.Length);
            Assert.AreEqual(12345678900, lr[1]);
        }
Exemplo n.º 6
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);
    }