feat(cbo): expose ColumnStatistics with conservative NDV from zonemap#511
Draft
LuciferYang wants to merge 1 commit into
Draft
feat(cbo): expose ColumnStatistics with conservative NDV from zonemap#511LuciferYang wants to merge 1 commit into
LuciferYang wants to merge 1 commit into
Conversation
Contributor
|
ACTION NEEDED The PR title and description are used as the merge commit message. Please update your PR title and description to match the specification. For details on the error please inspect the "PR Title Check" action. |
Contributor
Author
|
Still a draft. |
fbcfd0a to
d8eeb13
Compare
ColumnStatsAggregator reduces per-zone ZoneStats to DSv2 ColumnStatistics with min/max/nullCount + a conservative NDV when every non-null zone has min == max. LanceStatistics.columnStats() exposes the aggregated map. LanceScanBuilder loads zonemap stats for projected zonemap-indexed columns up to a configurable cap (default 8). The conservative NDV path produces an exact NDV when applicable (every zone single-valued); returns null otherwise so Spark CBO falls back to row-count heuristics rather than guess. Most useful for sorted/clustered low-cardinality columns (e.g. d_year, ca_state) — no extra I/O on top of the zonemap load. Configuration (per-scan option / SparkConf key): - lance.cbo.column.stats.enabled / spark.lance.cbo.column.stats.enabled (default true) - lance.cbo.column.stats.max.columns / spark.lance.cbo.column.stats.max.columns (default 8) The cap default (8) is a conservative starting point that bounds plan-time zonemap I/O on wide-projection queries. Users can raise it for deeper CBO coverage or set the master switch to false for a no-op rollback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #510.
Summary
ColumnStatsAggregatorreduces per-zoneZoneStatsinto DSv2ColumnStatisticswith min / max / nullCount + a conservative NDV when every non-null zone hasmin == max.LanceStatistics.columnStats()exposes the aggregated map to Spark's CBO via the standardStatistics.columnStats()API.LanceScanBuilderloads zonemap stats for projected zonemap-indexed columns up tolance.cbo.column.stats.max.columns(default 8). Filter and partition columns are always loaded — they already drive fragment pruning.spark.lance.cbo.column.stats.enabled, defaulttrue) + per-scan option for safe rollback. Both flow throughparseTypedFlagsso catalog-level configs propagate the same way as fix(spark): gss initiate failed on hms executors; spark.sql.catalog read options not applied #476.Configuration
spark.lance.cbo.column.stats.enabledlance.cbo.column.stats.enabledtruecolumnStats()reporting entirely.spark.lance.cbo.column.stats.max.columnslance.cbo.column.stats.max.columns8Per-scan options win over SparkConf. Master switch off restores prior behavior (no
columnStats()reported).Related
USING zonemapas a recognizedCREATE INDEXmethod. Not a strict prerequisite (this PR's tests don't depend on it), but pairing them lets users opt into a zonemap-only index for CBO column stats without paying btree's index-build cost.What's NOT in this PR (follow-ups)
avgLen/maxLenfor variable-length types — separate issue.ANALYZE TABLEand persistent column statistics — separate follow-up PR; depends on this one.Test plan
make test SPARK_VERSION=3.5 SCALA_VERSION=2.12—ColumnStatsAggregatorTest(17),LanceStatisticsTest(19),LanceSparkReadOptionsSerializationTest(8) all pass.make test SPARK_VERSION=3.4 SCALA_VERSION=2.12— same suite passes.make test SPARK_VERSION=4.0 SCALA_VERSION=2.13— same suite passes.make test SPARK_VERSION=4.1 SCALA_VERSION=2.13— same suite passes.make lint— Checkstyle + Spotless clean.EXPLAIN COSTand confirmcolumnStatslines appear under theStatisticsblock when zonemap indexes exist on filter columns.spark.lance.cbo.column.stats.enabled=falseand confirmcolumnStatsdisappears (kill-switch verification).Risks
max.columnscap (default 8). On wide tables with no filter columns, this is the only added I/O.nullon failure — never poisons CBO with a guessed value.