|
|
@@ -288,7 +288,7 @@ public class TdEngineService {
|
|
288
|
288
|
/**
|
|
289
|
289
|
* 根据列 key 首字符的 UTF-8 值拆分到多个超级表
|
|
290
|
290
|
*/
|
|
291
|
|
- private void splitAndInsertToMultipleStables(String dbName, String baseSuperTable, String baseTable,
|
|
|
291
|
+ private void splitAndInsertToMultipleStables(String dbName, String stableName, String tableName,
|
|
292
|
292
|
List<Map<String, Object>> dataList,
|
|
293
|
293
|
Map<String, String> columnTypes) throws SQLException {
|
|
294
|
294
|
// 按首字符 UTF-8 值分组
|
|
|
@@ -303,8 +303,9 @@ public class TdEngineService {
|
|
303
|
303
|
// 每个分组作为一个超级表,处理其对应的列和数据
|
|
304
|
304
|
for (Map.Entry<Integer, Map<String, String>> group : groupColumnTypes.entrySet()) {
|
|
305
|
305
|
int groupId = group.getKey();
|
|
306
|
|
- String stableName = "device_" + groupId;
|
|
307
|
|
- String tableName = baseTable + "_" + groupId;
|
|
|
306
|
+ // 超级表名 = superTableName + groupId (例如 charge + 3 = charge3)
|
|
|
307
|
+ String newStableName = stableName+"_"+groupId;
|
|
|
308
|
+ String newTableName = stableName+"_"+groupId+"_"+tableName;
|
|
308
|
309
|
|
|
309
|
310
|
// 筛选出该组列的数据
|
|
310
|
311
|
List<Map<String, Object>> filteredData = filterDataByColumnGroup(dataList, group.getValue().keySet());
|
|
|
@@ -313,10 +314,10 @@ public class TdEngineService {
|
|
313
|
314
|
int batchSize = DEFAULT_BATCH_SIZE;
|
|
314
|
315
|
for (int i = 0; i < filteredData.size(); i += batchSize) {
|
|
315
|
316
|
List<Map<String, Object>> batch = filteredData.subList(i, Math.min(i + batchSize, filteredData.size()));
|
|
316
|
|
- insertBatchInternal(dbName, stableName, tableName, batch);
|
|
|
317
|
+ insertBatchInternal(dbName, newStableName, newTableName, batch);
|
|
317
|
318
|
}
|
|
318
|
319
|
log.info("分组插入完成: stable={}, table={}, 列数={}, 数据条数={}",
|
|
319
|
|
- stableName, tableName, group.getValue().size(), filteredData.size());
|
|
|
320
|
+ newStableName, newTableName, group.getValue().size(), filteredData.size());
|
|
320
|
321
|
}
|
|
321
|
322
|
}
|
|
322
|
323
|
|
|
|
@@ -329,7 +330,7 @@ public class TdEngineService {
|
|
329
|
330
|
}
|
|
330
|
331
|
String firstChar = columnName.substring(0, 1);
|
|
331
|
332
|
byte[] bytes = firstChar.getBytes(java.nio.charset.StandardCharsets.UTF_8);
|
|
332
|
|
- return (int) bytes[0] % 10;
|
|
|
333
|
+ return (bytes[0] & 0xFF) % 10;
|
|
333
|
334
|
}
|
|
334
|
335
|
|
|
335
|
336
|
/**
|