in backup-core/src/main/java/org/apache/iotdb/backup/core/service/CsvFileValidationService.java [129:196]
protected void doValidateData(
Map<Long, CSVRecord> recordMap,
Long begin,
Long end,
List<String> timeseries,
Map<String, String> headMap,
Session session,
ValidationType validationType)
throws StatementExecutionException, IoTDBConnectionException {
int dataSetCount = 0;
SessionDataSet dataSet = getSessionDataSet(timeseries, begin, end, session);
List<String> typeList = dataSet.getColumnTypes();
List<String> columnNameList = dataSet.getColumnNames();
for (int i = 0; i < timeseries.size(); i++) {
if (!timeseries.get(i).equals(columnNameList.get(i + 1))) {
assert false
: "datavalidation failed, because the num of timeseries in the csv is more than the num of the database; the timeseries is :"
+ timeseries.get(i);
}
}
if (columnNameList.indexOf("Time") == 0) {
columnNameList.remove(0);
typeList.remove(0);
}
while (dataSet.hasNext()) {
dataSetCount++;
RowRecord sdataRecord = dataSet.next();
if (recordMap.get(sdataRecord.getTimestamp()) != null) {
CSVRecord csvRecord = recordMap.get(sdataRecord.getTimestamp());
for (int i = 0; i < columnNameList.size(); i++) {
StringBuilder validateFailedMsg = new StringBuilder();
String cname = columnNameList.get(i);
String ctype = typeList.get(i);
Field field = sdataRecord.getFields().get(i);
assert compare(csvRecord.get(headMap.get(cname)), field, ctype)
: validateFailedMsg
.append("\n data validation failed; Timeļ¼")
.append(sdataRecord.getTimestamp())
.append(",\ntype:")
.append(ctype)
.append(",\ncloumn name:")
.append(cname)
.append(",\nexpected value:")
.append(csvRecord.get(headMap.get(cname)))
.append(",actural value :[")
.append(field.getStringValue())
.append("]")
.toString();
recordMap.remove(sdataRecord.getTimestamp());
}
} else {
if (validationType.equals(ValidationType.EQUAL)) {
throw new AssertionError(
" data validation failed, the num of the cvs file is not equals the nums in the database;Time:"
+ sdataRecord.getTimestamp());
}
continue;
}
}
if (recordMap.size() != 0) {
throw new AssertionError(
" data validation failed, the num of the cvs file more than the nums in the database;");
}
if (dataSetCount == 0) {
throw new AssertionError(" data validation failed, dataSetCount is 0");
}
}