parse_records_from_file

Function parse_records_from_file 

Source
pub fn parse_records_from_file<P>(
    path: P,
) -> Result<(Vec<Sqllog>, Vec<ParseError>), ParseError>
where P: AsRef<Path>,
Expand description

从文件读取并并行解析为 Sqllog(高性能版本)

此函数使用并行处理,将日志文件解析为 Sqllog 列表。 适合处理大文件(GB 级别),先识别所有记录,然后并行解析。

§性能

  • 1GB 文件(300万条记录):约 2.5-2.7 秒
  • 与流式处理性能相当(流式也使用批量并行优化)
  • 内存使用:批量加载所有记录到内存

§参数

  • path - 日志文件路径

§返回

  • Ok((Vec<Sqllog>, Vec<ParseError>)) - 成功解析的 Sqllog 和遇到的错误
  • Err(ParseError) - 文件打开错误

§示例

use dm_database_parser_sqllog::parse_records_from_file;

let (sqllogs, errors) = parse_records_from_file("large_log.txt")?;

println!("成功解析 {} 条 SQL 日志", sqllogs.len());
println!("遇到 {} 个错误", errors.len());

for sqllog in sqllogs.iter().take(10) {
    println!("用户: {}, SQL: {}", sqllog.meta.username, sqllog.body);
}