feat(HBaseEmpManager): 统计培训课程的参与人数
- 新增 countTrainingParticipants 方法,用于统计培训课程的参与人数 - 通过 Scan 操作扫描表中的 training_courses 列 - 使用 HashMap 统计每个课程的参与人数 - 打印每个课程的参与人数统计结果
This commit is contained in:
parent
76294b7ecf
commit
fd9875baee
@ -178,4 +178,28 @@ public class HBaseEmpManager {
|
|||||||
System.out.println("Most Recently Promoted Employee: " + latestEmp + ", Promotion Date: " + latestDate);
|
System.out.println("Most Recently Promoted Employee: " + latestEmp + ", Promotion Date: " + latestDate);
|
||||||
table.close();
|
table.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 统计培训课程的参与人数
|
||||||
|
private static void countTrainingParticipants() throws IOException {
|
||||||
|
Table table = connection.getTable(TableName.valueOf(TABLE_NAME));
|
||||||
|
Scan scan = new Scan();
|
||||||
|
scan.addColumn(Bytes.toBytes(CF_TRAINING), Bytes.toBytes("training_courses"));
|
||||||
|
|
||||||
|
ResultScanner scanner = table.getScanner(scan);
|
||||||
|
Map<String, Integer> countMap = new HashMap<>();
|
||||||
|
|
||||||
|
for (Result result : scanner) {
|
||||||
|
String courses = Bytes.toString(result.getValue(Bytes.toBytes(CF_TRAINING), Bytes.toBytes("training_courses")));
|
||||||
|
for (String course : courses.split(", ")) {
|
||||||
|
countMap.put(course, countMap.getOrDefault(course, 0) + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("培训课程统计:");
|
||||||
|
for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
|
||||||
|
System.out.println(entry.getKey() + ": " + entry.getValue() + " 人");
|
||||||
|
}
|
||||||
|
|
||||||
|
table.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user