public void writeCompressed(ExtendedDataOutput output) { short flag = ((short)(DATA_FORM.DF_TABLE) << 8 | 8 & 0xff); //8: table type TODO: add table type output.writeShort(flag); int rows = this.rows(); int cols = this.columns(); output.writeInt(rows); output.writeInt(cols); output.writeString(""); //table name for (int i = 0; i < cols; i++) { output.writeString(this.getColumnName(i)); } for (int i = 0; i < cols; i++) { AbstractVector v = (AbstractVector)this.getColumn(i); if (v.getDataType() == DATA_TYPE.DT_SYMBOL) { v.write((ExtendedDataOutput)output); } else { v.writeCompressed((ExtendedDataOutput)output); } output.flush(); } }
public BasicArrayVector(DATA_TYPE type) : base(DATA_FORM.DF_VECTOR) { this.type = type; this.rowIndices = new List <int>(); DATA_TYPE valueType = type - 64; valueVec = (AbstractVector)BasicEntityFactory.instance().createVectorWithDefaultValue(valueType, 0); this.baseUnitLength_ = valueVec.getUnitLength(); }
public BasicArrayVector(List <IVector> value) : base(DATA_FORM.DF_VECTOR) { DATA_TYPE valueType = value[0].getDataType(); this.type = valueType + 64; int count = 0; int indexCount = value.Count; foreach (IVector temp in value) { if (temp.rows() == 0) { count += 1; } else { count += temp.rows(); } } int indexPos = 0; this.rowIndices = new List <int>(new int[indexCount]); this.valueVec = (AbstractVector)BasicEntityFactory.instance().createVectorWithDefaultValue(valueType, count); int index = 0; int curRows = 0; for (int valuePos = 0; valuePos < indexCount; ++valuePos) { IVector temp = value[valuePos]; int size = temp.rows(); for (int i = 0; i < size; ++i) { this.valueVec.set(index, temp.get(i)); index++; } if (size == 0) { size = 1; this.valueVec.setNull(index); index++; } curRows += size; this.rowIndices[indexPos++] = curRows; } this.baseUnitLength_ = (this.valueVec).getUnitLength(); }
public BasicArrayVector(int[] index, IVector value) : base(DATA_FORM.DF_VECTOR) { DATA_TYPE valueType = value.getDataType(); this.type = valueType + 64; this.valueVec = (AbstractVector)value; int indexCount = index.Length; if (indexCount == 0) { throw new Exception("Index must be an array of size greater than 0."); } if (index[indexCount - 1] != value.rows()) { throw new Exception("The last element of index must be equal to the length of value. "); } this.baseUnitLength_ = ((AbstractVector)value).getUnitLength(); rowIndices = new List <int>(index); }
public BasicArrayVector(DATA_TYPE type, ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR) { this.type = type; int rows = @in.readInt(); int cols = @in.readInt(); rowIndices = new List <int>(new int[rows]); DATA_TYPE valueType = type - 64; valueVec = (AbstractVector)BasicEntityFactory.instance().createVectorWithDefaultValue(valueType, cols); this.baseUnitLength_ = valueVec.getUnitLength(); int rowsRead = 0; int rowsReadInBlock = 0; int prevIndex = 0; int totalBytes = 0; while (rowsRead < rows) { //read block header int blockRows = @in.readShort(); int countBytes = @in.readChar(); @in.skipBytes(1); //read array of count totalBytes = blockRows * countBytes; rowsReadInBlock = 0; int offect = 0; while (offect < totalBytes) { int len = Math.Min(BUF_SIZE, totalBytes - offect); @in.readFully(buf, 0, len); int curRows = len / countBytes; if (countBytes == 1) { for (int i = 0; i < curRows; i++) { int curRowCells = buf[i]; rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells; prevIndex += curRowCells; } } else if (countBytes == 2) { for (int i = 0; i < curRows; ++i) { int curRowCells = BitConverter.ToInt16(buf, i * 2); rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells; prevIndex += curRowCells; } } else { for (int i = 0; i < curRows; ++i) { int curRowCells = BitConverter.ToInt32(buf, i * 4); rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells; prevIndex += curRowCells; } } rowsReadInBlock += curRows; offect += len; } //read array of values int rowStart = rowsRead == 0 ? 0 : rowIndices[rowsRead - 1]; int valueCount = rowIndices[rowsRead + rowsReadInBlock - 1] - rowStart; valueVec.deserialize(rowStart, valueCount, @in); rowsRead += rowsReadInBlock; } }