-- 两个方向:文件小,还是取得少。
--
-- 用法:pqt script examples/compact-vs-scannable.luau <某个 parquet 文件>
local file = ... or arg[1]
if not file then
print("用法:pqt script examples/compact-vs-scannable.luau <file>")
return
end
local cost = pqt.lookup_cost(file)
print("这个文件 " .. cost.size_bytes .. " 字节," .. cost.rows .. " 行," .. cost.row_groups .. " 个行组")
print(" 页脚(每个读者先付的) " .. cost.footer_bytes)
print(" 一次查找读 " .. cost.lookup_reads_typical .. "(典型) / " .. cost.lookup_reads_worst .. "(最坏)")
-- 行怎么分布在行组上:平不平均(不平 ⇒ 剪枝用不上)
local rows = cost.rows_per_group
local smallest, largest = rows[1], rows[1]
for _, count in rows do
if count < smallest then smallest = count end
if count > largest then largest = count end
end
print(" 每行组的行数 " .. smallest .. " 到 " .. largest)
if smallest ~= largest then
print(" ⇒ 行组大小不均匀:写的时候按查询键排一下,剪枝才用得上")
end
-- 换一份写法,看它多重
local plan = {
compression = "zstd",
compression_level = 19,
row_group_size = 100000,
}
local bench = pqt.bench(file, plan)
print("用 zstd:19 与十万行一个行组重写:" .. bench.runs[1].bytes .. " 字节")