HTHou opened a new pull request, #11577:
URL: https://github.com/apache/iotdb/pull/11577
## Description
Currently insertTablets API didn't return schema validation error. This PR
is fixing it.
## How to test
Set `enable_auto_create_schema=false`
Execute the following code
```java
public static void main(String[] args)
throws IoTDBConnectionException, StatementExecutionException {
session =
new Session.Builder()
.host(LOCAL_HOST)
.port(6667)
.username("root")
.password("root")
.build();
session.open(false);
insertTablets();
session.close();
}
private static void insertTablets() throws IoTDBConnectionException,
StatementExecutionException {
// The schema of measurements of one device
// only measurementId and data type in MeasurementSchema take effects in
Tablet
List<MeasurementSchema> schemaList = new ArrayList<>();
schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));
schemaList.add(new MeasurementSchema("s2", TSDataType.INT64));
schemaList.add(new MeasurementSchema("s3", TSDataType.INT64));
Tablet tablet1 = new Tablet(ROOT_SG1_D1, schemaList, 100);
Tablet tablet2 = new Tablet("root.sg1.d2", schemaList, 100);
Tablet tablet3 = new Tablet("root.sg1.d3", schemaList, 100);
Map<String, Tablet> tabletMap = new HashMap<>();
tabletMap.put(ROOT_SG1_D1, tablet1);
tabletMap.put("root.sg1.d2", tablet2);
tabletMap.put("root.sg1.d3", tablet3);
// Method 1 to add tablet data
long timestamp = System.currentTimeMillis();
for (long row = 0; row < 100; row++) {
int row1 = tablet1.rowSize++;
int row2 = tablet2.rowSize++;
int row3 = tablet3.rowSize++;
tablet1.addTimestamp(row1, timestamp);
tablet2.addTimestamp(row2, timestamp);
tablet3.addTimestamp(row3, timestamp);
for (int i = 0; i < 3; i++) {
long value = random.nextLong();
tablet1.addValue(schemaList.get(i).getMeasurementId(), row1, value);
tablet2.addValue(schemaList.get(i).getMeasurementId(), row2, value);
tablet3.addValue(schemaList.get(i).getMeasurementId(), row3, value);
}
if (tablet1.rowSize == tablet1.getMaxRowNumber()) {
session.insertTablets(tabletMap, true);
tablet1.reset();
tablet2.reset();
tablet3.reset();
}
timestamp++;
}
if (tablet1.rowSize != 0) {
session.insertTablets(tabletMap, true);
tablet1.reset();
tablet2.reset();
tablet3.reset();
}
// Method 2 to add tablet data
long[] timestamps1 = tablet1.timestamps;
Object[] values1 = tablet1.values;
long[] timestamps2 = tablet2.timestamps;
Object[] values2 = tablet2.values;
long[] timestamps3 = tablet3.timestamps;
Object[] values3 = tablet3.values;
for (long time = 0; time < 100; time++) {
int row1 = tablet1.rowSize++;
int row2 = tablet2.rowSize++;
int row3 = tablet3.rowSize++;
timestamps1[row1] = time;
timestamps2[row2] = time;
timestamps3[row3] = time;
for (int i = 0; i < 3; i++) {
long[] sensor1 = (long[]) values1[i];
sensor1[row1] = i;
long[] sensor2 = (long[]) values2[i];
sensor2[row2] = i;
long[] sensor3 = (long[]) values3[i];
sensor3[row3] = i;
}
if (tablet1.rowSize == tablet1.getMaxRowNumber()) {
session.insertTablets(tabletMap, true);
tablet1.reset();
tablet2.reset();
tablet3.reset();
}
}
if (tablet1.rowSize != 0) {
session.insertTablets(tabletMap, true);
tablet1.reset();
tablet2.reset();
tablet3.reset();
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]