Skip to content

Commit df8b9bf

Browse files
author
chengyitian
committed
AJ-774: support iotAnyVector;
1 parent e0fd818 commit df8b9bf

File tree

3 files changed

+174
-1
lines changed

3 files changed

+174
-1
lines changed

src/com/xxdb/data/BasicEntityFactory.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ else if (form == Entity.DATA_FORM.DF_TENSOR)
8181
return new BasicTensor(type, in);
8282
else if(type == Entity.DATA_TYPE.DT_ANY && (form == Entity.DATA_FORM.DF_VECTOR || form == Entity.DATA_FORM.DF_PAIR))
8383
return new BasicAnyVector(in);
84+
else if (type == Entity.DATA_TYPE.DT_ANYIOT)
85+
return new BasicIotAnyVector(in);
8486
else if(type.getValue() >= Entity.DATA_TYPE.DT_BOOL_ARRAY.getValue() && type.getValue() <= DT_DECIMAL128_ARRAY.getValue())
8587
return new BasicArrayVector(type, in);
8688
else if(type == Entity.DATA_TYPE.DT_VOID && form == Entity.DATA_FORM.DF_SCALAR){
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.xxdb.data;
2+
3+
import java.io.IOException;
4+
import java.nio.ByteBuffer;
5+
import java.util.HashMap;
6+
import java.util.Map;
7+
import java.util.Objects;
8+
import com.xxdb.io.ExtendedDataInput;
9+
import com.xxdb.io.ExtendedDataOutput;
10+
import com.fasterxml.jackson.annotation.JsonIgnore;
11+
12+
public class BasicIotAnyVector extends AbstractVector {
13+
14+
private Map<Integer, Entity> subVector;
15+
private BasicIntVector indexsDataType;
16+
private BasicIntVector indexs;
17+
18+
protected BasicIotAnyVector(Entity[] array) {
19+
super(DATA_FORM.DF_VECTOR);
20+
subVector = new HashMap<>();
21+
indexsDataType = new BasicIntVector(0);
22+
indexs = new BasicIntVector(0);
23+
for (int i = 0; i < array.length; i++) {
24+
subVector.put(array[i].getDataType().getValue(), array[i]);
25+
for (int j = 0; j < array[i].rows(); j++ ) {
26+
indexsDataType.add(array[i].getDataType().getValue());
27+
indexs.add(j);
28+
}
29+
}
30+
}
31+
32+
protected BasicIotAnyVector(ExtendedDataInput in) throws IOException {
33+
super(DATA_FORM.DF_VECTOR);
34+
int rows = in.readInt();
35+
int cols = in.readInt(); // 1
36+
long size = in.readLong();
37+
38+
indexsDataType = new BasicIntVector(0);
39+
indexs = new BasicIntVector(0);
40+
for(long i = 0; i < size; i++){
41+
int type = in.readInt();
42+
int idx = in.readInt();
43+
indexsDataType.add(type);
44+
indexs.add(idx);
45+
}
46+
47+
int typeSize = in.readInt();
48+
subVector = new HashMap<>();
49+
for (int i = 0; i < typeSize; i++) {
50+
short flag = in.readShort();
51+
int form = flag>>8;
52+
int type = flag & 0xff;
53+
boolean extended = type >= 128;
54+
if(type >= 128)
55+
type -= 128;
56+
Entity obj = BasicEntityFactory.instance().createEntity(DATA_FORM.values()[form], DATA_TYPE.valueOf(type), in, extended);
57+
subVector.put(type, obj);
58+
}
59+
}
60+
61+
public Entity get(int index){
62+
BasicInt dataType = (BasicInt) indexsDataType.get(index);
63+
return subVector.get(dataType.getInt());
64+
}
65+
66+
public Vector getSubVector(int[] indices){
67+
throw new RuntimeException("BasicIotAnyVector.getSubVector not supported.");
68+
}
69+
70+
public void set(int index, Entity value) throws Exception {
71+
throw new RuntimeException("BasicIotAnyVector.set not supported.");
72+
}
73+
74+
@Override
75+
public Vector combine(Vector vector) {
76+
throw new UnsupportedOperationException();
77+
}
78+
79+
@Override
80+
public boolean isNull(int index) {
81+
throw new RuntimeException("BasicIotAnyVector.isNull not supported.");
82+
}
83+
84+
@Override
85+
public void setNull(int index) {
86+
throw new RuntimeException("BasicIotAnyVector.setNull not supported.");
87+
}
88+
89+
@Override
90+
public DATA_CATEGORY getDataCategory() {
91+
return Entity.DATA_CATEGORY.MIXED;
92+
}
93+
94+
@Override
95+
public DATA_TYPE getDataType() {
96+
return Entity.DATA_TYPE.DT_ANYIOT;
97+
}
98+
99+
@Override
100+
public int rows() {
101+
return indexs.rows();
102+
}
103+
104+
@JsonIgnore
105+
@Override
106+
public int getUnitLength(){
107+
throw new RuntimeException("IotAnyVector.getUnitLength not supported.");
108+
}
109+
110+
public void addRange(Object[] valueList) {
111+
throw new RuntimeException("IotAnyVector not support addRange");
112+
}
113+
114+
@Override
115+
public void Append(Scalar value) {
116+
throw new RuntimeException("IotAnyVector not support append");
117+
}
118+
119+
@Override
120+
public void Append(Vector value) {
121+
throw new RuntimeException("IotAnyVector not support append");
122+
}
123+
124+
public String getString(){
125+
StringBuilder sb = new StringBuilder("[");
126+
for (Entity value : subVector.values())
127+
sb.append(value.getString()).append(",");
128+
129+
sb.setLength(sb.length() - 1);
130+
sb.append("]");
131+
132+
return sb.toString();
133+
}
134+
135+
public Class<?> getElementClass(){
136+
return Entity.class;
137+
}
138+
139+
@Override
140+
public void serialize(int start, int count, ExtendedDataOutput out) throws IOException {
141+
throw new RuntimeException("BasicIotAnyVector.serialize not supported.");
142+
}
143+
144+
@Override
145+
public int serialize(int indexStart, int offect, int targetNumElement, AbstractVector.NumElementAndPartial numElementAndPartial, ByteBuffer out) throws IOException{
146+
throw new RuntimeException("BasicIotAnyVector.serialize not supported.");
147+
}
148+
149+
@Override
150+
protected void writeVectorToOutputStream(ExtendedDataOutput out) throws IOException {
151+
long size = indexs.rows();
152+
out.writeLong(size);
153+
154+
for (int i = 0; i < size; i++) {
155+
out.writeInt(indexsDataType.getInt(i));
156+
out.writeInt(indexs.getInt(i));
157+
}
158+
159+
out.writeInt(subVector.size());
160+
161+
for (Entity value : subVector.values()) {
162+
if (Objects.nonNull(value))
163+
value.write(out);
164+
}
165+
}
166+
167+
@Override
168+
public int asof(Scalar value) {
169+
throw new RuntimeException("BasicAnyVector.asof not supported.");
170+
}
171+
}

src/com/xxdb/data/Entity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum DATA_TYPE {DT_VOID("VOID", 0), DT_BOOL("BOOL", 1), DT_BYTE("CHAR", 2
1414
DT_HANDLE("HANDLE", 21), DT_CODE("CODE", 22), DT_DATASOURCE("DATASOURCE", 23), DT_RESOURCE("RESOURCE", 24), DT_ANY("ANY", 25),
1515
DT_COMPRESS("COMPRESSED", 26), DT_DICTIONARY("DICTIONARY", 27), DT_DATEHOUR("DATEHOUR", 28), DT_DATEMINUTE("DATEMINUTE", 29), DT_IPADDR("IPADDR", 30),
1616
DT_INT128("INT128", 31), DT_BLOB("BLOB", 32), DT_DECIMAL("DECIMAL", 33), DT_COMPLEX("COMPLEX", 34), DT_POINT("POINT", 35),
17-
DT_DURATION("DURATION", 36), DT_DECIMAL32("DECIMAL32", 37), DT_DECIMAL64("DECIMAL64", 38), DT_DECIMAL128("DECIMAL128", 39),DT_OBJECT("OBJECT", 40),
17+
DT_DURATION("DURATION", 36), DT_DECIMAL32("DECIMAL32", 37), DT_DECIMAL64("DECIMAL64", 38), DT_DECIMAL128("DECIMAL128", 39),DT_OBJECT("OBJECT", 40),DT_ANYIOT("DT_ANYIOT", 41),
1818

1919
DT_BOOL_ARRAY("BOOL[]", 65), DT_BYTE_ARRAY("CHAR[]", 66), DT_SHORT_ARRAY("SHORT[]", 67), DT_INT_ARRAY("INT[]", 68), DT_LONG_ARRAY("LONG[]", 69),
2020
DT_DATE_ARRAY("DATE[]", 70), DT_MONTH_ARRAY("MONTH[]", 71), DT_TIME_ARRAY("TIME[]", 72), DT_MINUTE_ARRAY("MINUTE[]", 73), DT_SECOND_ARRAY("SECOND[]", 74),

0 commit comments

Comments
 (0)