Skip to content

Commit 6b62517

Browse files
author
chengyitian
committed
Merge branch 'dev' of dolphindb.net:dolphindb/api-java
2 parents 5bfc8f1 + ec5c132 commit 6b62517

29 files changed

+2121
-415
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>com.dolphindb</groupId>
44
<artifactId>dolphindb-javaapi</artifactId>
5-
<version>3.00.1.3</version>
5+
<version>3.00.2.0</version>
66
<packaging>jar</packaging>
77

88
<properties>
9-
<dolphindb.version>3.00.1.3</dolphindb.version>
9+
<dolphindb.version>3.00.2.0</dolphindb.version>
1010
</properties>
1111
<name>DolphinDB Java API</name>
1212
<description>The messaging and data conversion protocol between Java and DolphinDB server</description>
@@ -31,7 +31,7 @@
3131
<connection>scm:git:git@github.com:dolphindb/api-java.git</connection>
3232
<developerConnection>scm:git:git@github.com:dolphindb/api-java.git</developerConnection>
3333
<url>git@github.com:dolphindb/api-java.git</url>
34-
<tag>api-java-3.00.1.3</tag>
34+
<tag>api-java-3.00.2.0</tag>
3535
</scm>
3636
<dependencies>
3737
<dependency>

src/com/xxdb/DBConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ public boolean connect(String hostName, int port, String userId, String password
846846
}
847847

848848
if (attempt == totalConnectAttemptNums) {
849-
log.error("Connect failed after " + tryReconnectNums + " reconnect attemps for every node in high availability sites.");
849+
log.error("Connect failed after " + tryReconnectNums + " reconnect attempts for every node in high availability sites.");
850850
return false;
851851
}
852852
} else {
@@ -1023,7 +1023,7 @@ public void switchDataNode(Node node) throws IOException{
10231023
} while (!closed_ && (tryReconnectNums == -1 || attempt < tryReconnectNums));
10241024

10251025
if (!closed_ && !isConnected)
1026-
throw new RuntimeException("Connect to " + node.hostName + ":" + node.port + " failed after " + attempt + " reconnect attemps.");
1026+
throw new RuntimeException("Connect to " + node.hostName + ":" + node.port + " failed after " + attempt + " reconnect attempts.");
10271027

10281028
if (initialScript_!=null && initialScript_.length() > 0){
10291029
run(initialScript_);

src/com/xxdb/data/AbstractVector.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ public void write(ExtendedDataOutput out) throws IOException{
9292
if(this instanceof BasicSymbolVector)
9393
flag += 128;
9494
out.writeShort(flag);
95-
out.writeInt(rows());
95+
if (getDataType() == DATA_TYPE.DT_IOTANY)
96+
out.writeInt(((BasicIotAnyVector) this).serializeAnyVectorRows());
97+
else
98+
out.writeInt(rows());
9699
out.writeInt(columns());
97100
if (Entity.DATA_TYPE.valueOf(dataType) == DATA_TYPE.DT_DECIMAL32_ARRAY
98101
|| Entity.DATA_TYPE.valueOf(dataType) == DATA_TYPE.DT_DECIMAL64_ARRAY

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 == DT_IOTANY)
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: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
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 org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
import com.xxdb.io.ExtendedDataInput;
11+
import com.xxdb.io.ExtendedDataOutput;
12+
import com.fasterxml.jackson.annotation.JsonIgnore;
13+
14+
public class BasicIotAnyVector extends AbstractVector {
15+
16+
private Map<Integer, Entity> subVector;
17+
private BasicIntVector indexsDataType;
18+
private BasicIntVector indexs;
19+
20+
private static final Logger log = LoggerFactory.getLogger(BasicIotAnyVector.class);
21+
22+
23+
public BasicIotAnyVector(Scalar[] scalars) {
24+
super(DATA_FORM.DF_VECTOR);
25+
26+
if (Objects.isNull(scalars) || scalars.length == 0)
27+
throw new RuntimeException("The param 'scalars' cannot be null or empty.");
28+
29+
subVector = new HashMap<>();
30+
indexsDataType = new BasicIntVector(0);
31+
indexs = new BasicIntVector(0);
32+
33+
try {
34+
for (Scalar scalar : scalars) {
35+
int curDataTypeValue = scalar.getDataType().getValue();
36+
37+
if (Objects.isNull(subVector.get(curDataTypeValue))) {
38+
Vector curVector = BasicEntityFactory.instance().createVectorWithDefaultValue(scalar.getDataType(), 0, -1);
39+
curVector.Append(scalar);
40+
subVector.put(curDataTypeValue, curVector);
41+
} else {
42+
((Vector) subVector.get(curDataTypeValue)).Append(scalar);
43+
}
44+
45+
indexsDataType.add(curDataTypeValue);
46+
indexs.add(subVector.get(curDataTypeValue).rows() - 1);
47+
}
48+
} catch (Exception e) {
49+
log.error(e.getMessage());
50+
}
51+
}
52+
53+
protected BasicIotAnyVector(ExtendedDataInput in) throws IOException {
54+
super(DATA_FORM.DF_VECTOR);
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);
65+
66+
subVector = new HashMap<>();
67+
for (int i = 1; i <= subVecNum; i++) {
68+
DATA_TYPE dataType = anyVector.get(i).getDataType();
69+
subVector.put(dataType.getValue(), anyVector.get(i));
70+
}
71+
}
72+
73+
public Entity get(int index) {
74+
if (index >=rows())
75+
throw new RuntimeException(String.format("index %s out of rows %s.", index, rows()));
76+
77+
BasicInt curDataType = (BasicInt) indexsDataType.get(index);
78+
BasicInt curIndex = (BasicInt) indexs.get(index);
79+
80+
return ((Vector) subVector.get(curDataType.getInt())).get(curIndex.getInt());
81+
}
82+
83+
public String getString(int index) {
84+
return get(index).getString();
85+
}
86+
87+
public Vector getSubVector(int[] indices){
88+
throw new RuntimeException("BasicIotAnyVector.getSubVector not supported.");
89+
}
90+
91+
public void set(int index, Entity value) throws Exception {
92+
throw new RuntimeException("BasicIotAnyVector.set not supported.");
93+
}
94+
95+
@Override
96+
public Vector combine(Vector vector) {
97+
throw new UnsupportedOperationException();
98+
}
99+
100+
@Override
101+
public boolean isNull(int index) {
102+
throw new RuntimeException("BasicIotAnyVector.isNull not supported.");
103+
}
104+
105+
@Override
106+
public void setNull(int index) {
107+
throw new RuntimeException("BasicIotAnyVector.setNull not supported.");
108+
}
109+
110+
@Override
111+
public DATA_CATEGORY getDataCategory() {
112+
return Entity.DATA_CATEGORY.MIXED;
113+
}
114+
115+
@Override
116+
public DATA_TYPE getDataType() {
117+
return DATA_TYPE.DT_IOTANY;
118+
}
119+
120+
@Override
121+
public int rows() {
122+
return indexs.rows();
123+
}
124+
125+
protected int serializeAnyVectorRows() {
126+
return subVector.size() + 1;
127+
}
128+
129+
@JsonIgnore
130+
@Override
131+
public int getUnitLength(){
132+
throw new RuntimeException("IotAnyVector.getUnitLength not supported.");
133+
}
134+
135+
public void addRange(Object[] valueList) {
136+
throw new RuntimeException("IotAnyVector.addRange not supported.");
137+
}
138+
139+
@Override
140+
public void Append(Scalar value) {
141+
throw new RuntimeException("IotAnyVector.Append not supported.");
142+
}
143+
144+
@Override
145+
public void Append(Vector value) {
146+
throw new RuntimeException("IotAnyVector.Append not supported.");
147+
}
148+
149+
public String getString(){
150+
StringBuilder sb = new StringBuilder("[");
151+
for (int i = 0; i < rows(); i++)
152+
sb.append(getString(i)).append(",");
153+
154+
sb.setLength(sb.length() - 1);
155+
sb.append("]");
156+
157+
return sb.toString();
158+
}
159+
160+
public Class<?> getElementClass(){
161+
return Entity.class;
162+
}
163+
164+
@Override
165+
public void serialize(int start, int count, ExtendedDataOutput out) throws IOException {
166+
throw new RuntimeException("BasicIotAnyVector.serialize not supported.");
167+
}
168+
169+
@Override
170+
public int serialize(int indexStart, int offect, int targetNumElement, AbstractVector.NumElementAndPartial numElementAndPartial, ByteBuffer out) throws IOException{
171+
throw new RuntimeException("BasicIotAnyVector.serialize not supported.");
172+
}
173+
174+
@Override
175+
protected void writeVectorToOutputStream(ExtendedDataOutput out) throws IOException {
176+
int[] tmpIntArray = new int[rows() * 2 + 2];
177+
178+
tmpIntArray[0] = rows();
179+
tmpIntArray[1] = subVector.size();
180+
181+
System.arraycopy(indexs.getdataArray(), 0, tmpIntArray,2, rows());
182+
System.arraycopy(indexsDataType.getdataArray(), 0, tmpIntArray, rows() + 2, indexsDataType.size);
183+
BasicIntVector intVector = new BasicIntVector(tmpIntArray);
184+
185+
Entity[] entities = new Entity[1 + subVector.size()];
186+
entities[0] = intVector;
187+
188+
int index = 1;
189+
for (Entity value : subVector.values()) {
190+
entities[index] = value;
191+
index++;
192+
}
193+
194+
BasicAnyVector anyVector = new BasicAnyVector(entities, false);
195+
anyVector.writeVectorToOutputStream(out);
196+
}
197+
198+
@Override
199+
public int asof(Scalar value) {
200+
throw new RuntimeException("BasicAnyVector.asof not supported.");
201+
}
202+
}

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
}

src/com/xxdb/data/Entity.java

Lines changed: 2 additions & 2 deletions
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_IOTANY("IOTANY", 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),
@@ -102,7 +102,7 @@ else if(type == Entity.DATA_TYPE.DT_STRING || type == Entity.DATA_TYPE.DT_SYMBOL
102102
return Entity.DATA_CATEGORY.LITERAL;
103103
else if(type==Entity.DATA_TYPE.DT_INT128 || type==Entity.DATA_TYPE.DT_UUID || type==Entity.DATA_TYPE.DT_IPADDR)
104104
return Entity.DATA_CATEGORY.BINARY;
105-
else if(type == Entity.DATA_TYPE.DT_ANY)
105+
else if(type == Entity.DATA_TYPE.DT_ANY || type == DATA_TYPE.DT_IOTANY)
106106
return Entity.DATA_CATEGORY.MIXED;
107107
else if(type == Entity.DATA_TYPE.DT_VOID)
108108
return Entity.DATA_CATEGORY.NOTHING;

src/com/xxdb/data/Utils.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
public class Utils {
1717

18-
public static final String JAVA_API_VERSION = "3.00.1.3";
18+
public static final String JAVA_API_VERSION = "3.00.2.0";
1919

2020
public static final int DISPLAY_ROWS = 20;
2121
public static final int DISPLAY_COLS = 100;
@@ -408,7 +408,7 @@ else if(type==DATA_TYPE.DT_STRING || type==DATA_TYPE.DT_SYMBOL || type == DATA_T
408408
return DATA_CATEGORY.LITERAL;
409409
else if(type==DATA_TYPE.DT_INT128 || type==DATA_TYPE.DT_UUID || type==DATA_TYPE.DT_IPADDR)
410410
return DATA_CATEGORY.BINARY;
411-
else if(type==DATA_TYPE.DT_ANY)
411+
else if(type==DATA_TYPE.DT_ANY || type == DATA_TYPE.DT_IOTANY)
412412
return DATA_CATEGORY.MIXED;
413413
else if(type==DATA_TYPE.DT_VOID)
414414
return DATA_CATEGORY.NOTHING;

src/com/xxdb/multithreadedtablewriter/MultithreadedTableWriter.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,9 @@ private List<Vector> createListVector(){
847847
int cols = colInfos_.length;
848848
for (int i = 0; i < cols; i++){
849849
Entity.DATA_TYPE type = colInfos_[i].type_;
850-
if (type.getValue() >= 65){
850+
if (type.getValue() >= 65) {
851851
tmp.add(new BasicArrayVector(type, 1, colInfos_[i].extra_));
852-
}
853-
else{
852+
} else {
854853
Vector value = BasicEntityFactory.instance().createVectorWithDefaultValue(type, 0, colInfos_[i].extra_);
855854
if (type == DT_DECIMAL32 || type == DT_DECIMAL64 || type == DT_DECIMAL128) {
856855
((AbstractVector)value).setExtraParamForType(colInfos_[i].extra_);

src/com/xxdb/route/AutoFitTableAppender.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,8 @@ public Entity append(BasicTable table) {
5454

5555
int rowSize = table.rows();
5656
for (int i = 0; i < columns; ++i) {
57-
String name = nameList.getString(i);
5857
String dstType = typeList.get(i).getString();
59-
Vector colOrigin = table.getColumn(name);
58+
Vector colOrigin = table.getColumn(i);
6059
Vector dstVector;
6160
switch (dstType) {
6261
case "DATE": {

src/com/xxdb/route/AutoFitTableUpsert.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,13 @@ private String defineInsertScript (String dbUrl, String tableName, boolean ignor
9494
}
9595

9696
private void checkColumnType(int col, Entity.DATA_CATEGORY category, Entity.DATA_TYPE type){
97-
if (columnTypes_.get(col) != type){
98-
Entity.DATA_CATEGORY expectCateGory = columnCategories_.get(col);
99-
if (category != expectCateGory)
100-
throw new RuntimeException("column " + col + ", expect category " + expectCateGory + ", got category " + category);
101-
}
97+
Entity.DATA_TYPE expectedType = columnTypes_.get(col);
98+
Entity.DATA_CATEGORY expectedCategory = columnCategories_.get(col);
99+
100+
if (expectedType == type || (expectedType == Entity.DATA_TYPE.DT_IOTANY && expectedCategory == Entity.DATA_CATEGORY.MIXED))
101+
return;
102+
103+
if (category != expectedCategory)
104+
throw new RuntimeException(String.format("Column %d: expected category %s, got %s", col, expectedCategory, category));
102105
}
103106
}

src/com/xxdb/route/PartitionedTableAppender.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public int append(Table table) throws IOException {
160160
private void checkColumnType(int col, Entity.DATA_CATEGORY category, Entity.DATA_TYPE type) {
161161
Entity.DATA_CATEGORY expectCategory = this.columnCategories[col];
162162
Entity.DATA_TYPE expectType = this.columnTypes[col];
163-
if (category != expectCategory) {
163+
if (category != expectCategory && expectCategory != Entity.DATA_CATEGORY.MIXED) {
164164
throw new RuntimeException("column " + col + ", expect category " + expectCategory.name() + ", got category " + category.name());
165165
} else if (category == Entity.DATA_CATEGORY.TEMPORAL && type != expectType) {
166166
throw new RuntimeException("column " + col + ", temporal column must have exactly the same type, expect " + expectType.name() + ", got " + type.name() );

src/com/xxdb/streaming/client/cep/EventClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public class EventClient extends AbstractClient {
2828

2929
private static final Logger log = LoggerFactory.getLogger(DBConnection.class);
3030

31-
public EventClient(List<EventSchema> eventSchemas, List<String> eventTimeKeys, List<String> commonKeys) throws SocketException {
31+
public EventClient(List<EventSchema> eventSchemas, List<String> eventTimeFields, List<String> commonFields) throws SocketException {
3232
super(0);
33-
eventHandler = new EventHandler(eventSchemas, eventTimeKeys, commonKeys);
33+
eventHandler = new EventHandler(eventSchemas, eventTimeFields, commonFields);
3434
}
3535

3636
public void subscribe(String host, int port, String tableName, String actionName, MessageHandler handler, long offset, boolean reconnect, String userName, String password) throws IOException {

0 commit comments

Comments
 (0)