σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
σμimplied vol · KKmax(S−K,0)udβρᵢⱼfat tailsPnL · drawdownyield · TdSₜ = μSₜ dt + σSₜ dWₜC = S·N(d₁) − K·e⁻ʳᵀ·N(d₂)σₚ² = wᵀΣwd₁ = [ln(S/K) + (r + σ²⁄2)T] ⁄ σ√T∂V/∂t + ½σ²S²·∂²V/∂S² + rS·∂V/∂S − rV = 0Sharpe = (Rₚ − R_f) ⁄ σₚVaR₉₉ = μ − 2.33σρ = Cov(X,Y) ⁄ σₓσᵧE[Rₚ] = Σ wᵢ·E[Rᵢ]φ(x) = e^(−x²/2) ⁄ √2πE[Rᵢ] = R_f + βᵢ(E[Rₘ] − R_f)dXₜ = θ(μ − Xₜ)dt + σ dWₜσ²ₜ = ω + α·ε²ₜ₋₁ + β·σ²ₜ₋₁C − P = S − K·e⁻ʳᵀΔ = ∂V/∂S Γ = ∂²V/∂S²p = (e^(rΔt) − d) ⁄ (u − d)rₜ = ln(Pₜ ⁄ Pₜ₋₁)E[Xₜ₊₁ | ℱₜ] = Xₜf* = (bp − q) ⁄ bz = (x − μ) ⁄ σP(N=k) = λᵏe^(−λ) ⁄ k!Θ = −∂V/∂Tν = S·φ(d₁)·√Tmin wᵀΣw s.t. wᵀμ = μ*∫Σ∂∞λ
uantCraft AcademyRoadmapsSkills
Ctrl K
AO
+1.2k Learners
LoginJoin ↗
RoadmapsSkills
AO
+1.2k Learners
Login
  • English
  • Français
  • Español
  • العربية
  • Português
  • Deutsch
  • 日本語
  • 中文
Parquet skill›Module 3 · Keeping a lake healthy›Topic 3.2·~45 minAdvanced

Statistics and bloom filters

Skill positionModule 3 of 3 · Topic 2 of 4
3.2 Statistics and bloom filters
—Lab score— / 100Total XP—Streak—
Lecture0% read

3 min readCode examples: 3

  1. 01The idea in plain words
  2. 02Min and max, straight from the footer
  3. 03A bloom filter for what statistics cannot rule out
  4. 04What the tasks ask

To avoid reading data you need a cheap way to say "it is not in there". The footer holds two. Minimum and maximum statistics rule out a whole row group when a value falls outside its range. A bloom filter rules out a value that is inside the range but was never stored. Neither can prove a value is present, only that it is absent.

01

The idea in plain words

Where we are. Topic 4 used min and max to skip row groups for a range filter. This topic reads those statistics directly, shows where they stop being useful (a single value that happens to fall inside a range), and builds the bloom filter that covers that gap. The next topic deals with the cost of having too many files, which all of this assumes you have avoided.

DefinitionBloom filter

A bit array that answers "is this value in the set?" with either "definitely not" or "probably". Each added value sets a few bits chosen by hashing; a value is reported present only if all of its bits are set. It never forgets a member, and occasionally reports a stranger.

02

Min and max, straight from the footer

row_group_stats reads minimum, maximum, null count and row count for a column in every row group, all from the footer. For a date column in a file sorted by date, the ranges are narrow and almost do not overlap, so looking up a date lands in one or two groups. But note the word "might": a date inside a group's range is not necessarily in the group.

main.pyPython
# The first three row groups of a file sorted by date: (min, max, nulls, rows)for stats in row_group_stats("by_date.parquet", "date")[:3]:    print(stats)
(datetime.date(2000, 1, 3), datetime.date(2003, 3, 13), 0, 4000)
(datetime.date(2003, 3, 13), datetime.date(2006, 5, 16), 0, 4000)
(datetime.date(2006, 5, 16), datetime.date(2009, 7, 21), 0, 4000)
main.pyPython
# A Saturday sits inside a group's range but is not in the file: statistics can only say "maybe"saturday = date(2020, 1, 4)print("row groups that might hold it:", groups_with_value("by_date.parquet", "date", saturday))print("rows really dated that day:", sum(1 for d in table["date"].to_pylist() if d == saturday))
row groups that might hold it: [6]
rows really dated that day: 0
03

A bloom filter for what statistics cannot rule out

An order ID or a trade ID is spread over its whole range in every row group, so min and max exclude nothing. A bloom filter per row group stores a fingerprint of the IDs it holds. bloom_build sets k bits per value; bloom_contains checks them. The size of the bit array decides how often a stranger is let in: the more bits per value, the fewer false positives, at the cost of a bigger footer.

main.pyPython
# 1,000 order IDs in a filter; then 1,000 IDs that were never added, at three filter sizesmembers = [f"order-{i}" for i in range(1000)]strangers = [f"other-{i}" for i in range(1000)]for nbits in (2_000, 10_000, 40_000):    bits = bloom_build(members, nbits, 4)    missed = sum(not bloom_contains(bits, nbits, 4, m) for m in members)    false_positives = sum(bloom_contains(bits, nbits, 4, s) for s in strangers)    print(f"{nbits:>6} bits: members missed {missed}, strangers let in {false_positives} of 1000")
  2000 bits: members missed 0, strangers let in 546 of 1000
 10000 bits: members missed 0, strangers let in 19 of 1000
 40000 bits: members missed 0, strangers let in 0 of 1000
Use it where min and max fail

Sorted columns like date already skip well from statistics, and a bloom filter adds only weight. Unsorted high-cardinality columns that you look up by equality, such as order IDs, trade IDs or account numbers, are where filters pay off. They help = and IN lookups, never range conditions.

04

What the tasks ask

  1. 1
    `row_group_stats` and `groups_with_value`Find the column chunk by path_in_schema; read statistics.min, .max, .null_count. Keep a group when min <= value <= max, or when it has no statistics.
  2. 2
    `bloom_build` and `bloom_contains`For each value, bits |= 1 << position for every bit_positions(value, nbits, k); to query, return False as soon as one of those bits is 0.

Key takeaways

  • Statistics say no, never yes A value outside a group's range is certainly absent; inside it is only possible.
  • A bloom filter has no false negatives It may let a stranger in, but never loses a member.
  • Match the tool to the column Sorted: statistics. Unsorted IDs: bloom filter. Next: too many small files.
Quick check
A bloom filter is asked about an ID and answers "no". What can you conclude?
Pick an answer.

Lab · what's graded

4 tasks · 100 pts
  • Read the statistics: row_group_stats25 pts
  • A firm no or a maybe: groups_with_value25 pts
  • Build a bloom filter: bloom_build25 pts
  • Ask the filter: bloom_contains25 pts
Explorer · lab-7-1
▾ lab-7-1
▾ data
…
bash · in-browser
learner@quantcraft:~/lab-7-1$
Python not loaded yetPythonLn 1, Col 1Spaces: 4UTF-8

Reset this topic?

Everything in lab-7-1 goes back to the starter files and the terminal is cleared. Your current solution will be lost — this can't be undone.

Will be reset
  • main.py → starter code
  • Terminal history and test output
  • Unsubmitted changes
Will be kept
  • Best lab score
  • Your XP and streak
  • Lecture progress and notes