public virtual void write(ExtendedDataOutput @out, SymbolBaseCollection collection)
        {
            int dataType = (int)getDataType() + 128;
            int flag     = ((int)DATA_FORM.DF_VECTOR << 8) + dataType;

            @out.writeShort(flag);
            @out.writeInt(rows());
            @out.writeInt(columns());
            collection.write(@out, @base);
            @out.writeIntArray(values.ToArray());
        }
        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();
            }
        }
Exemple #3
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();
            VectorDecompressor   decompressor = null;
            SymbolBaseCollection collection   = null;

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

                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);
                }
                IVector vector;
                if (dt == DATA_TYPE.DT_SYMBOL && extended)
                {
                    if (collection == null)
                    {
                        collection = new SymbolBaseCollection();
                    }
                    vector = new BasicSymbolVector(df, @in, collection);
                }
                else if (dt == DATA_TYPE.DT_COMPRESS)
                {
                    if (decompressor == null)
                    {
                        decompressor = new VectorDecompressor();
                    }
                    vector = decompressor.Decompress(factory, @in, false, true);
                }
                else
                {
                    vector = (IVector)factory.createEntity(df, dt, @in, extended);
                }
                if (vector.rows() != rows && vector.rows() != 1)
                {
                    int tmp = vector.rows();
                    throw new IOException("The number of rows for column " + names_[i] + " is not consistent with other columns");
                }
                columns_.Add(vector);
            }
        }