//2021.01.19 cwj
        protected internal BasicStringVector(DATA_FORM df, ExtendedDataInput @in, bool symbol, bool blob) : base(df)
        {
            isBlob   = blob;
            isSymbol = symbol;
            int rows    = @in.readInt();
            int columns = @in.readInt();
            int size    = rows * columns;

            values = new List <string>(size);
            values.AddRange(new string[size]);

            if (!blob)
            {
                for (int i = 0; i < size; ++i)
                {
                    values[i] = @in.readString();
                }
            }
            else
            {
                for (int i = 0; i < size; ++i)
                {
                    values[i] = @in.readBlob();
                }
            }
        }
 //2021.01.19 cwj
 protected internal BasicStringVector(DATA_FORM df, int size, bool isSymbol, bool blob) : base(df)
 {
     values = new List <string>(size);
     values.AddRange(new string[size]);
     this.isSymbol = isSymbol;
     this.isBlob   = blob;
 }
 internal BasicInt128Vector(DATA_FORM df, int size) : base(df)
 {
     values = new Long2[size];
     for (int i = 0; i < size; ++i)
     {
         values[i] = new Long2(0, 0);
     }
 }
 internal BasicInt128Vector(DATA_FORM df, int size) : base(df)
 {
     values = new List <Long2>();
     values.AddRange(new Long2[size]);
     for (int i = 0; i < size; ++i)
     {
         values[i] = new Long2(0, 0);
     }
 }
Beispiel #5
0
        protected internal BasicBooleanVector(DATA_FORM df, ExtendedDataInput @in) : base(df)
        {
            int rows = @in.readInt();
            int cols = @in.readInt();
            int size = rows * cols;

            values = new byte[size];
            for (int i = 0; i < size; ++i)
            {
                values[i] = @in.readByte();
            }
        }
        protected internal BasicStringVector(DATA_FORM df, ExtendedDataInput @in) : base(df)
        {
            int rows    = @in.readInt();
            int columns = @in.readInt();
            int size    = rows * columns;

            values = new string[size];
            for (int i = 0; i < size; ++i)
            {
                values[i] = @in.readString();
            }
        }
        protected internal BasicSymbolVector(DATA_FORM df, ExtendedDataInput @in, SymbolBaseCollection collection) : base(df)
        {
            int rows    = @in.readInt();
            int columns = @in.readInt();
            int size    = rows * columns;

            values = new List <int>(new int[rows]);
            @base  = collection.add(@in);
            for (int i = 0; i < size; ++i)
            {
                values[i] = @in.readInt();
            }
        }
Beispiel #8
0
        protected internal BasicByteVector(DATA_FORM df, ExtendedDataInput @in) : base(df)
        {
            int rows = @in.readInt();
            int cols = @in.readInt();
            int size = rows * cols;

            values = new List <byte>(size);
            values.AddRange(new byte[size]);
            for (int i = 0; i < size; ++i)
            {
                values[i] = @in.readByte();
            }
        }
Beispiel #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected BasicIntVector(Entity_DATA_FORM df, dolphindb.io.ExtendedDataInput in) throws java.io.IOException
        protected internal BasicIntVector(DATA_FORM df, ExtendedDataInput @in) : base(df)
        {
            int rows = @in.readInt();
            //if (rows != 1024)
            //assert(rows == 1024);
            int cols = @in.readInt();
            int size = rows * cols;

            values = new int[size];
            for (int i = 0; i < size; ++i)
            {
                values[i] = @in.readInt();
            }
        }
    internal BasicInt128Vector(DATA_FORM df, ExtendedDataInput @in) : base(df)
    {
        int rows = @in.readInt();
        int cols = @in.readInt();
        int size = rows * cols;

        values = new List <Long2>();
        values.AddRange(new Long2[size]);
        int  totalBytes = size * 16, off = 0;
        bool littleEndian = @in.isLittleEndian();

        while (off < totalBytes)
        {
            int len = System.Math.Min(BUF_SIZE, totalBytes - off);
            @in.readFully(buf, 0, len);
            int    start = off / 16, end = len / 16;
            Byte[] dst = new Byte[len];
            Buffer.BlockCopy(buf, 0, dst, 0, len);
            if (!littleEndian)
            {
                Array.Reverse(dst);
            }
            if (littleEndian)
            {
                for (int i = 0; i < end; i++)
                {
                    long low  = BitConverter.ToInt64(dst, i * 16);
                    long high = BitConverter.ToInt64(dst, i * 16 + 8);
                    values[i + start] = new Long2(high, low);
                }
            }
            else
            {
                for (int i = 0; i < end; i++)
                {
                    long high = BitConverter.ToInt64(dst, i * 16);
                    long low  = BitConverter.ToInt64(dst, i * 16 + 8);
                    values[i + start] = new Long2(high, low);
                }
            }
            off += len;
        }
    }
Beispiel #11
0
        public BasicTable(ExtendedDataInput @in)
        {
            int rows = @in.readInt();
            int cols = @in.readInt();

            _tableName = @in.readString();

            //read column names
            for (int i = 0; i < cols; ++i)
            {
                string name = @in.readString();
                name2index_[name] = name2index_.Count;
                names_.Add(name);
            }

            BasicEntityFactory factory = new BasicEntityFactory();

            //read columns
            for (int i = 0; i < cols; ++i)
            {
                short flag = @in.readShort();
                int   form = flag >> 8;
                int   type = flag & 0xff;

                DATA_FORM df = (DATA_FORM)form;
                DATA_TYPE dt = (DATA_TYPE)type;
                if (df != DATA_FORM.DF_VECTOR)
                {
                    throw new IOException("Invalid form for column [" + names_[i] + "] for table " + _tableName);
                }
                Console.WriteLine("vector create " + i + ":" + DateTime.Now);
                IVector vector = (IVector)factory.createEntity(df, dt, @in);
                Console.WriteLine("vector end create " + i + ":" + DateTime.Now);
                if (vector.rows() != rows && vector.rows() != 1)
                {
                    throw new IOException("The number of rows for column " + names_[i] + " is not consistent with other columns");
                }
                columns_.Add(vector);
            }
        }
 public IEntity createEntity(DATA_FORM form, DATA_TYPE type, ExtendedDataInput @in)
 {
     if (form == DATA_FORM.DF_TABLE)
     {
         return(new BasicTable(@in));
     }
     else if (form == DATA_FORM.DF_CHART)
     {
         //return new BasicChart(@in);
         return(null);
     }
     else if (form == DATA_FORM.DF_DICTIONARY)
     {
         //return new BasicDictionary(type, @in);
         return(null);
     }
     else if (form == DATA_FORM.DF_SET)
     {
         //return new BasicSet(type, @in);
         return(null);
     }
     else if (form == DATA_FORM.DF_CHUNK)
     {
         //return new BasicChunkMeta(@in);
         return(null);
     }
     else if (type == DATA_TYPE.DT_ANY && form == DATA_FORM.DF_VECTOR)
     {
         //return new BasicAnyVector(@in);
         return(null);
     }
     else if (type == DATA_TYPE.DT_VOID && form == DATA_FORM.DF_SCALAR)
     {
         @in.readBoolean();
         return(new Void());
     }
     else
     {
         int index = (int)type;
         if (factories[index] == null)
         {
             throw new IOException("Data type " + type.ToString() + " is not supported yet.");
         }
         else if (form == DATA_FORM.DF_VECTOR)
         {
             return(factories[index].createVector(@in));
         }
         else if (form == DATA_FORM.DF_SCALAR)
         {
             return(factories[index].createScalar(@in));
         }
         else if (form == DATA_FORM.DF_MATRIX)
         {
             return(factories[index].createMatrix(@in));
         }
         else if (form == DATA_FORM.DF_PAIR)
         {
             return(factories[index].createPair(@in));
         }
         else
         {
             throw new IOException("Data form " + form.ToString() + " is not supported yet.");
         }
     }
 }
Beispiel #13
0
 protected internal BasicLongVector(DATA_FORM df, int size) : base(df)
 {
     values = new long[size];
 }
Beispiel #14
0
 protected internal BasicShortVector(DATA_FORM df, int size) : base(df)
 {
     values = new short[size];
 }
Beispiel #15
0
 internal BasicUuidVector(DATA_FORM df, int size) : base(df, size)
 {
 }
 protected internal BasicStringVector(DATA_FORM df, int size, bool isSymbol) : base(df)
 {
     values        = new string[size];
     this.isSymbol = isSymbol;
 }
 protected internal BasicSecondVector(DATA_FORM df, int size) : base(df, size)
 {
 }
Beispiel #18
0
 protected internal BasicNanoTimestampVector(DATA_FORM df, ExtendedDataInput @in) : base(df, @in)
 {
 }
Beispiel #19
0
 internal BasicUuidVector(DATA_FORM df, ExtendedDataInput @in) : base(df, @in)
 {
 }
Beispiel #20
0
        public virtual IEntity run(string script, ProgressListener listener)
        {
            lock (threadLock)
            {
                bool reconnect = false;
                if (socket == null || !socket.Connected)
                {
                    if (sessionID.Length == 0)
                    {
                        throw new IOException("Database connection is not established yet.");
                    }
                    else
                    {
                        socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        socket.Connect(hostName, port);

                        @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket)));
                    }
                }

                string            body   = "script\n" + script;
                ExtendedDataInput @in    = null;
                string            header = null;
                try
                {
                    @out.writeBytes((listener != null ? "API2 " : "API ") + sessionID + " ");
                    @out.writeBytes(AbstractExtendedDataOutputStream.getUTFlength(body, 0, 0).ToString());
                    @out.writeByte('\n');
                    @out.writeBytes(body);
                    @out.flush();

                    @in = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket)));

                    header = @in.readLine();
                }
                catch (IOException ex)
                {
                    if (reconnect)
                    {
                        socket = null;
                        throw ex;
                    }

                    try
                    {
                        tryReconnect();
                        @out.writeBytes((listener != null ? "API2 " : "API ") + sessionID + " ");
                        @out.writeBytes(AbstractExtendedDataOutputStream.getUTFlength(body, 0, 0).ToString());
                        @out.writeByte('\n');
                        @out.writeBytes(body);
                        @out.flush();

                        @in       = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket)));
                        header    = @in.readLine();
                        reconnect = true;
                    }
                    catch (Exception e)
                    {
                        socket = null;
                        throw e;
                    }
                }
                string msg;

                while (header.Equals("MSG"))
                {
                    //read intermediate message to indicate the progress
                    msg = @in.readString();
                    if (listener != null)
                    {
                        listener.progress(msg);
                    }
                    header = @in.readLine();
                }

                string[] headers = header.Split(' ');
                if (headers.Length != 3)
                {
                    socket = null;
                    throw new IOException("Received invalid header: " + header);
                }

                if (reconnect)
                {
                    sessionID = headers[0];
                    if (this.userId.Length > 0 && this.password.Length > 0)
                    {
                        login();
                    }
                    if (this.initialScript != "")
                    {
                        run(initialScript);
                    }
                }
                int numObject = int.Parse(headers[1]);

                msg = @in.readLine();
                if (!msg.Equals("OK"))
                {
                    throw new IOException(msg);
                }

                if (numObject == 0)
                {
                    return(new data.Void());
                }
                try
                {
                    short flag = @in.readShort();
                    int   form = flag >> 8;
                    int   type = flag & 0xff;

                    if (form < 0 || form > MAX_FORM_VALUE)
                    {
                        throw new IOException("Invalid form value: " + form);
                    }
                    if (type < 0 || type > MAX_TYPE_VALUE)
                    {
                        throw new IOException("Invalid type value: " + type);
                    }

                    DATA_FORM df = (DATA_FORM)Enum.GetValues(typeof(DATA_FORM)).GetValue(form);
                    DATA_TYPE dt = (DATA_TYPE)Enum.GetValues(typeof(DATA_TYPE)).GetValue(type);

                    return(factory.createEntity(df, dt, @in));
                }
                catch (IOException ex)
                {
                    socket = null;
                    throw ex;
                }
            }
        }
Beispiel #21
0
 protected internal BasicDateTimeVector(DATA_FORM df, ExtendedDataInput @in) : base(df, @in)
 {
 }
Beispiel #22
0
 protected internal BasicFloatVector(DATA_FORM df, int size) : base(df)
 {
     values = new float[size];
 }
Beispiel #23
0
 protected internal BasicBooleanVector(DATA_FORM df, int size) : base(df)
 {
     values = new List <byte>(size);
     values.AddRange(new byte[size]);
 }
 protected internal BasicMinuteVector(DATA_FORM df, int size) : base(df, size)
 {
 }
Beispiel #25
0
 protected internal BasicDateTimeVector(DATA_FORM df, int size) : base(df, size)
 {
 }
Beispiel #26
0
        public virtual IEntity run(string function, IList <IEntity> arguments)
        {
            lock (threadLock)
            {
                try
                {
                    bool reconnect = false;
                    if (socket == null || !socket.Connected)
                    {
                        if (sessionID.Length == 0)
                        {
                            throw new IOException("Database connection is not established yet.");
                        }
                        else
                        {
                            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                            socket.Connect(hostName, port);
                            @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket)));
                        }
                    }

                    string body = "function\n" + function;
                    body += ("\n" + arguments.Count + "\n");
                    body += remoteLittleEndian ? "1" : "0";

                    ExtendedDataInput @in     = null;
                    string[]          headers = null;
                    try
                    {
                        @out.writeBytes("API " + sessionID + " ");
                        @out.writeBytes(body.Length.ToString());
                        @out.writeByte('\n');
                        @out.writeBytes(body);
                        for (int i = 0; i < arguments.Count; ++i)
                        {
                            arguments[i].write(@out);
                        }
                        @out.flush();

                        @in     = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket)));
                        headers = @in.readLine().Split(' ');
                    }
                    catch (IOException ex)
                    {
                        if (reconnect)
                        {
                            socket = null;
                            throw ex;
                        }

                        try
                        {
                            tryReconnect();
                            @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket)));
                            @out.writeBytes("API " + sessionID + " ");
                            @out.writeBytes(body.Length.ToString());
                            @out.writeByte('\n');
                            @out.writeBytes(body);
                            for (int i = 0; i < arguments.Count; ++i)
                            {
                                arguments[i].write(@out);
                            }
                            @out.flush();

                            @in       = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket)));
                            headers   = @in.readLine().Split(' ');
                            reconnect = true;
                        }
                        catch (Exception e)
                        {
                            socket = null;
                            throw e;
                        }
                    }

                    if (headers.Length != 3)
                    {
                        socket = null;
                        throw new IOException("Received invalid header.");
                    }

                    if (reconnect)
                    {
                        sessionID = headers[0];
                        if (this.userId.Length > 0 && this.password.Length > 0)
                        {
                            login();
                        }
                        if (this.initialScript != "")
                        {
                            run(initialScript);
                        }
                    }
                    int numObject = int.Parse(headers[1]);

                    string msg = @in.readLine();
                    if (!msg.Equals("OK"))
                    {
                        throw new IOException(msg);
                    }

                    if (numObject == 0)
                    {
                        return(new data.Void());
                    }

                    try
                    {
                        short flag = @in.readShort();
                        int   form = flag >> 8;
                        int   type = flag & 0xff;

                        if (form < 0 || form > MAX_FORM_VALUE)
                        {
                            throw new IOException("Invalid form value: " + form);
                        }
                        if (type < 0 || type > MAX_TYPE_VALUE)
                        {
                            throw new IOException("Invalid type value: " + type);
                        }

                        DATA_FORM df = (DATA_FORM)Enum.GetValues(typeof(DATA_FORM)).GetValue(form);
                        DATA_TYPE dt = (DATA_TYPE)Enum.GetValues(typeof(DATA_TYPE)).GetValue(type);

                        return(factory.createEntity(df, dt, @in));
                    }
                    catch (IOException ex)
                    {
                        socket = null;
                        throw ex;
                    }
                }
                finally
                {
                }
            }
        }
Beispiel #27
0
 protected internal BasicBooleanVector(DATA_FORM df, int size) : base(df)
 {
     values = new byte[size];
 }
Beispiel #28
0
 protected internal BasicDoubleVector(DATA_FORM df, int size) : base(df)
 {
     values = new double[size];
 }
 public AbstractVector(DATA_FORM df)
 {
     df_ = df;
 }
Beispiel #30
0
 protected internal BasicNanoTimestampVector(DATA_FORM df, int size) : base(df, size)
 {
 }