Skip to content

Commit 8c43d8b

Browse files
author
chengyitian
committed
AJ-774: modify to new serialize logic for iotAnyVector;
1 parent d638135 commit 8c43d8b

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

src/com/xxdb/data/BasicIotAnyVector.java

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,27 @@ public BasicIotAnyVector(Scalar[] scalars) {
5252

5353
protected BasicIotAnyVector(ExtendedDataInput in) throws IOException {
5454
super(DATA_FORM.DF_VECTOR);
55-
int rows = in.readInt();
56-
int cols = in.readInt(); // 1
57-
long size = in.readInt();
55+
BasicAnyVector anyVector = new BasicAnyVector(in);
56+
BasicIntVector intVector = (BasicIntVector) anyVector.get(0);
57+
int indexsLen = ((BasicInt) intVector.get(0)).getInt();
58+
int subVecNum = ((BasicInt) intVector.get(1)).getInt();
59+
int[] tmpIntArray = new int[indexsLen];
60+
System.arraycopy(intVector.getdataArray(), 2, tmpIntArray,0, indexsLen);
61+
indexs = new BasicIntVector(tmpIntArray);
62+
tmpIntArray = new int[indexsLen];
63+
System.arraycopy(intVector.getdataArray(), (indexsLen) + 2, tmpIntArray,0, indexsLen);
64+
indexsDataType = new BasicIntVector(tmpIntArray);
5865

59-
indexsDataType = new BasicIntVector(0);
60-
indexs = new BasicIntVector(0);
61-
for(long i = 0; i < size; i++){
62-
int type = in.readInt();
63-
int idx = in.readInt();
64-
indexsDataType.add(type);
65-
indexs.add(idx);
66-
}
67-
68-
int typeSize = in.readInt();
6966
subVector = new HashMap<>();
70-
for (int i = 0; i < typeSize; i++) {
71-
short flag = in.readShort();
72-
int form = flag>>8;
73-
int type = flag & 0xff;
74-
boolean extended = type >= 128;
75-
if(type >= 128)
76-
type -= 128;
77-
Entity obj = BasicEntityFactory.instance().createEntity(DATA_FORM.values()[form], DATA_TYPE.valueOf(type), in, extended);
78-
subVector.put(type, obj);
67+
for (int i = 1; i <= subVecNum; i++) {
68+
DATA_TYPE dataType = anyVector.get(i).getDataType();
69+
subVector.put(dataType.getValue(), anyVector.get(i));
7970
}
8071
}
8172

8273
public Entity get(int index) {
83-
if (index >= rows())
84-
throw new RuntimeException(String.format("index %s out of rows %s.", index, rows()));
74+
if (index >= indexs.rows())
75+
throw new RuntimeException(String.format("index %s out of %s.", index, indexs.rows()));
8576

8677
BasicInt curDataType = (BasicInt) indexsDataType.get(index);
8778
BasicInt curIndex = (BasicInt) indexs.get(index);
@@ -128,7 +119,7 @@ public DATA_TYPE getDataType() {
128119

129120
@Override
130121
public int rows() {
131-
return indexs.rows();
122+
return subVector.size() + 1;
132123
}
133124

134125
@JsonIgnore
@@ -153,7 +144,7 @@ public void Append(Vector value) {
153144

154145
public String getString(){
155146
StringBuilder sb = new StringBuilder("[");
156-
for (int i = 0; i < rows(); i++)
147+
for (int i = 0; i < indexs.rows(); i++)
157148
sb.append(getString(i)).append(",");
158149

159150
sb.setLength(sb.length() - 1);
@@ -178,20 +169,26 @@ public int serialize(int indexStart, int offect, int targetNumElement, AbstractV
178169

179170
@Override
180171
protected void writeVectorToOutputStream(ExtendedDataOutput out) throws IOException {
181-
int size = indexs.rows();
182-
out.writeInt(size);
172+
int[] tmpIntArray = new int[indexs.rows() * 2 + 2];
183173

184-
for (int i = 0; i < size; i++) {
185-
out.writeInt(indexsDataType.getInt(i));
186-
out.writeInt(indexs.getInt(i));
187-
}
174+
tmpIntArray[0] = indexs.rows();
175+
tmpIntArray[1] = subVector.size();
176+
177+
System.arraycopy(indexs.getdataArray(), 0, tmpIntArray,2, indexs.rows());
178+
System.arraycopy(indexsDataType.getdataArray(), 0, tmpIntArray, indexs.rows() + 2, indexsDataType.size);
179+
BasicIntVector intVector = new BasicIntVector(tmpIntArray);
188180

189-
out.writeInt(subVector.size());
181+
Entity[] entities = new Entity[1 + subVector.size()];
182+
entities[0] = intVector;
190183

184+
int index = 1;
191185
for (Entity value : subVector.values()) {
192-
if (Objects.nonNull(value))
193-
value.write(out);
186+
entities[index] = value;
187+
index++;
194188
}
189+
190+
BasicAnyVector anyVector = new BasicAnyVector(entities, false);
191+
anyVector.writeVectorToOutputStream(out);
195192
}
196193

197194
@Override

src/com/xxdb/data/BasicTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public BasicTable(ExtendedDataInput in) throws IOException{
6262
else{
6363
vector = (Vector)BasicEntityFactory.instance().createEntity(df, dt, in, extended);
6464
}
65-
if(vector.rows() != rows && vector.rows()!= 1)
65+
if(vector.rows() != rows && vector.rows()!= 1 && vector.getDataType() != DATA_TYPE.DT_IOTANY)
6666
throw new IOException("The number of rows for column " + colNames.get(i) + " is not consistent with other columns");
6767
columns.add(vector);
6868
}

0 commit comments

Comments
 (0)