Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
31a1187
feat: collect zone map write seeds for unindexed columns from dataset…
LuQQiu Nov 23, 2026
1e00abb
feat: validate zone write seed config when it is set
LuQQiu Nov 23, 2026
ec35041
fix: leave fixed-size binary columns out of configured zone write seeds
LuQQiu Nov 23, 2026
d2021bf
fix: validate zone write seed config on the composite commit path
LuQQiu Nov 23, 2026
6012095
test: drop the view-type case from the zone write seed type gate
LuQQiu Nov 23, 2026
23f9e97
feat: record null positions in configured zone write seeds
LuQQiu Nov 23, 2026
83102c1
Merge remote-tracking branch 'lance-format/main' into lu/zone-write-s…
LuQQiu Nov 23, 2026
9f63366
test: cover seed and index zone boundaries for configured write seeds
LuQQiu Nov 23, 2026
7198351
test: pin observed reuse counts in the seed boundary matrix
LuQQiu Nov 23, 2026
4405ba9
test: pin coarse-seed rejection and cover production zone sizes
LuQQiu Nov 23, 2026
60f25ad
test: type the expected reuse counts in the real-size boundary test
LuQQiu Nov 23, 2026
ae859f3
test: compare stored zone statistics with a generator oracle
LuQQiu Nov 23, 2026
35bd435
test: require fragment-local zone starts in the stored statistics oracle
LuQQiu Nov 23, 2026
bda2e55
test: cover seed boundaries per type with and without a null bitmap i…
LuQQiu Nov 23, 2026
cec0853
test: compare typed zone bounds through array equality
LuQQiu Nov 23, 2026
759eeba
test: extend the per-type seed boundary test to every round-trip type
LuQQiu Nov 23, 2026
0b403f4
test: cover the remaining configured-seed types in the boundary oracle
LuQQiu Nov 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 93 additions & 0 deletions rust/lance-table/src/feature_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,60 @@ pub fn validate_auto_cleanup_config(manifest: &Manifest) -> Result<()> {
Ok(())
}

/// Prefix of the dataset config keys that control zone write seeds.
pub const ZONE_WRITE_SEEDS_CONFIG_PREFIX: &str = "lance.zone_write_seeds.";
/// Dataset config key that enables zone map seeds for columns without a
/// seeded ZoneMap index (`"true"` / `"false"`).
pub const ZONE_WRITE_SEEDS_ENABLED_KEY: &str = "lance.zone_write_seeds.enabled";
/// Dataset config key for the rows per seed zone of those columns.
pub const ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY: &str = "lance.zone_write_seeds.rows_per_zone";
/// Dataset config key that makes those seeds record null positions, so they
/// can serve a ZoneMap index that stores a null bitmap (`"true"` / `"false"`,
/// absent means `"true"`).
pub const ZONE_WRITE_SEEDS_STORE_NULL_BITMAP_KEY: &str = "lance.zone_write_seeds.store_null_bitmap";

/// Validate a change to the zone write seed configuration.
///
/// `lance.zone_write_seeds.enabled` and
/// `lance.zone_write_seeds.store_null_bitmap` must be `"true"` or `"false"`,
/// and `lance.zone_write_seeds.rows_per_zone` an integer in `1..=u32::MAX`:
/// per-zone null and NaN counts are 32-bit, as are the row offsets a zone
/// spans within a fragment. No other key may use the prefix. Call before
/// publishing a change to these keys.
pub fn validate_zone_write_seeds_config(manifest: &Manifest) -> Result<()> {
for (key, value) in manifest.config.iter() {
if !key.starts_with(ZONE_WRITE_SEEDS_CONFIG_PREFIX) {
continue;
}
match key.as_str() {
ZONE_WRITE_SEEDS_ENABLED_KEY | ZONE_WRITE_SEEDS_STORE_NULL_BITMAP_KEY => {
if value != "true" && value != "false" {
return Err(Error::invalid_input(format!(
"{key} must be \"true\" or \"false\", got {value:?}"
)));
}
}
ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY => {
let valid = value
.parse::<u64>()
.is_ok_and(|rows| rows > 0 && rows <= u64::from(u32::MAX));
if !valid {
return Err(Error::invalid_input(format!(
"{key} must be an integer between 1 and {}, got {value:?}",
u32::MAX
)));
}
}
_ => {
return Err(Error::invalid_input(format!(
"Unknown zone write seeds configuration key: {key}={value:?}"
)));
}
}
}
Ok(())
}

/// Set the reader and writer feature flags in the manifest based on the contents of the manifest.
pub fn apply_feature_flags(
manifest: &mut Manifest,
Expand Down Expand Up @@ -1016,6 +1070,45 @@ mod tests {
assert_eq!(destination.writer_feature_flags, FLAG_ZONE_WRITE_SEEDS);
}

#[rstest::rstest]
#[case::absent(&[])]
#[case::enabled(&[(ZONE_WRITE_SEEDS_ENABLED_KEY, "true")])]
#[case::disabled(&[(ZONE_WRITE_SEEDS_ENABLED_KEY, "false")])]
#[case::size(&[(ZONE_WRITE_SEEDS_ENABLED_KEY, "true"), (ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, "8")])]
#[case::size_without_enabled(&[(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, "1")])]
#[case::largest_size(&[(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, "4294967295")])]
#[case::null_bitmap(&[(ZONE_WRITE_SEEDS_ENABLED_KEY, "true"), (ZONE_WRITE_SEEDS_STORE_NULL_BITMAP_KEY, "true")])]
#[case::no_null_bitmap(&[(ZONE_WRITE_SEEDS_STORE_NULL_BITMAP_KEY, "false")])]
#[case::unrelated_key(&[("lance.zone_write_seedsx", "1"), ("other.key", "x")])]
fn test_zone_write_seeds_config_accepts_valid_values(#[case] entries: &[(&str, &str)]) {
let mut manifest = empty_manifest();
for (key, value) in entries {
manifest.config.insert(key.to_string(), value.to_string());
}
validate_zone_write_seeds_config(&manifest).unwrap();
}

#[rstest::rstest]
#[case::enabled_yes(ZONE_WRITE_SEEDS_ENABLED_KEY, "yes")]
#[case::enabled_uppercase(ZONE_WRITE_SEEDS_ENABLED_KEY, "TRUE")]
#[case::enabled_empty(ZONE_WRITE_SEEDS_ENABLED_KEY, "")]
#[case::null_bitmap_yes(ZONE_WRITE_SEEDS_STORE_NULL_BITMAP_KEY, "yes")]
#[case::null_bitmap_empty(ZONE_WRITE_SEEDS_STORE_NULL_BITMAP_KEY, "")]
#[case::zero_size(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, "0")]
#[case::negative_size(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, "-4")]
#[case::garbage_size(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, "many")]
#[case::too_large_size(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, "4294967296")]
#[case::unknown_key("lance.zone_write_seeds.rows_per_zonee", "8")]
fn test_zone_write_seeds_config_rejects_invalid_values(#[case] key: &str, #[case] value: &str) {
let mut manifest = empty_manifest();
manifest.config.insert(key.to_string(), value.to_string());
let error = validate_zone_write_seeds_config(&manifest).unwrap_err();
assert!(matches!(error, Error::InvalidInput { .. }), "{error}");
let message = error.to_string();
assert!(message.contains(key), "{message}");
assert!(message.contains(&format!("{value:?}")), "{message}");
}

#[test]
fn test_zone_write_seeds_require_both_feature_bits() {
for (reader, writer) in [(true, false), (false, true)] {
Expand Down
23 changes: 17 additions & 6 deletions rust/lance-table/src/transaction/action/apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@

use super::{CompositeOperation, FieldId, FieldRef, Ref};
use crate::feature_flags::{
FLAG_MANAGED_BLOBS, apply_index_object_metadata_flag, inherit_sticky_feature_flags,
managed_blobs_enabled, validate_auto_cleanup_config,
FLAG_MANAGED_BLOBS, ZONE_WRITE_SEEDS_CONFIG_PREFIX, apply_index_object_metadata_flag,
inherit_sticky_feature_flags, managed_blobs_enabled, validate_auto_cleanup_config,
validate_zone_write_seeds_config,
};
use crate::format::overlay::staleness::field_affects_index;
use crate::format::{
Expand Down Expand Up @@ -421,11 +422,16 @@ impl<'a> ApplyState<'a> {
manifest.table_metadata = table_metadata;
// Only a change is validated: settings inherited as they were, even
// invalid ones, must not block an unrelated commit.
if auto_cleanup_settings(&current_manifest.config)
!= auto_cleanup_settings(&manifest.config)
if settings_with_prefix(&current_manifest.config, AUTO_CLEANUP_CONFIG_PREFIX)
!= settings_with_prefix(&manifest.config, AUTO_CLEANUP_CONFIG_PREFIX)
{
validate_auto_cleanup_config(&manifest)?;
}
if settings_with_prefix(&current_manifest.config, ZONE_WRITE_SEEDS_CONFIG_PREFIX)
!= settings_with_prefix(&manifest.config, ZONE_WRITE_SEEDS_CONFIG_PREFIX)
{
validate_zone_write_seeds_config(&manifest)?;
}
// Both read the final schema and config, so they come after those land.
apply_range_segments(&mut manifest, Some(current_manifest))?;
if managed_blobs_enabled(&manifest.schema)? {
Expand Down Expand Up @@ -1406,10 +1412,15 @@ fn check_schema(schema: &Schema) -> Result<()> {
schema.validate()
}

fn auto_cleanup_settings(config: &HashMap<String, String>) -> BTreeMap<&str, &str> {
const AUTO_CLEANUP_CONFIG_PREFIX: &str = "lance.auto_cleanup.";

fn settings_with_prefix<'a>(
config: &'a HashMap<String, String>,
prefix: &str,
) -> BTreeMap<&'a str, &'a str> {
config
.iter()
.filter(|(key, _)| key.starts_with("lance.auto_cleanup."))
.filter(|(key, _)| key.starts_with(prefix))
.map(|(key, value)| (key.as_str(), value.as_str()))
.collect()
}
Expand Down
52 changes: 52 additions & 0 deletions rust/lance-table/src/transaction/action/config_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ impl TryFrom<pb_actions::ConfigUpdate> for ConfigUpdate {
#[cfg(test)]
mod tests {
use super::*;
use crate::feature_flags::{ZONE_WRITE_SEEDS_ENABLED_KEY, ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY};
use crate::format::Manifest;
use crate::transaction::action::test_support::{
added_field, apply, backed_manifest, footprint,
Expand Down Expand Up @@ -608,6 +609,57 @@ mod tests {
apply(&manifest, vec![set_config(&[("unrelated", Some("1"))])]).unwrap();
}

#[test]
fn test_config_update_rejects_an_invalid_zone_write_seeds_value() {
let error = apply(
&backed_manifest(),
vec![set_config(&[(
ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY,
Some("0"),
)])],
)
.unwrap_err();

assert!(
error
.to_string()
.contains(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY),
"unexpected error: {error}"
);
}

/// Only the settings the whole operation leaves are validated, so a later
/// update may repair a value an earlier one set.
#[test]
fn test_config_update_validates_the_zone_write_seeds_settings_it_leaves() {
let next = apply(
&backed_manifest(),
vec![
set_config(&[(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, Some("0"))]),
set_config(&[(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY, Some("8"))]),
],
)
.unwrap();

assert_eq!(
next.config
.get(ZONE_WRITE_SEEDS_ROWS_PER_ZONE_KEY)
.map(String::as_str),
Some("8")
);
}

#[test]
fn test_zone_write_seeds_settings_invalid_before_the_commit_do_not_block_it() {
let mut manifest = backed_manifest();
manifest
.config
.insert(ZONE_WRITE_SEEDS_ENABLED_KEY.into(), "yes".into());
assert!(crate::feature_flags::validate_zone_write_seeds_config(&manifest).is_err());

apply(&manifest, vec![set_config(&[("unrelated", Some("1"))])]).unwrap();
}

#[test]
fn test_edits_to_different_keys_commute() {
let update = |key: &str| {
Expand Down
63 changes: 59 additions & 4 deletions rust/lance-table/src/transaction/manifest_build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The Lance Authors

Expand All @@ -12,10 +12,11 @@

use crate::feature_flags::{
FLAG_COVERED_INDEX_METADATA, FLAG_FRAGMENT_REUSE_INDEX, FLAG_INDEPENDENT_COVERING_FIELDS,
FLAG_MANAGED_BLOBS, FLAG_NON_REUSABLE_FIELD_IDS, FLAG_STABLE_ROW_IDS, apply_feature_flags,
apply_index_object_metadata_flag, apply_row_addr_index_feature_flag, ensure_can_read_manifest,
ensure_can_write_manifest, inherit_sticky_feature_flags, managed_blobs_enabled,
validate_auto_cleanup_config, validate_non_reusable_field_id_flags,
FLAG_MANAGED_BLOBS, FLAG_NON_REUSABLE_FIELD_IDS, FLAG_STABLE_ROW_IDS,
ZONE_WRITE_SEEDS_CONFIG_PREFIX, apply_feature_flags, apply_index_object_metadata_flag,
apply_row_addr_index_feature_flag, ensure_can_read_manifest, ensure_can_write_manifest,
inherit_sticky_feature_flags, managed_blobs_enabled, validate_auto_cleanup_config,
validate_non_reusable_field_id_flags, validate_zone_write_seeds_config,
};
use crate::format::clustering::{ChangedReferences, validate_clustering_of};

Expand Down Expand Up @@ -141,6 +142,27 @@
}
}

fn changes_zone_write_seeds_config(operation: &Operation) -> bool {
let is_zone_write_seeds_key = |key: &str| key.starts_with(ZONE_WRITE_SEEDS_CONFIG_PREFIX);
match operation {
Operation::Overwrite {
config_upsert_values: Some(values),
..
} => values.keys().any(|key| is_zone_write_seeds_key(key)),
Operation::UpdateConfig {
config_updates: Some(update),
..
} => {
update.replace
|| update
.update_entries
.iter()
.any(|entry| is_zone_write_seeds_key(&entry.key))
}
_ => false,
}
}

/// Re-encode inline row id sequences in their smallest wire form when the
/// table has opted in.
///
Expand Down Expand Up @@ -2058,6 +2080,9 @@
if changes_auto_cleanup_config(&self.operation) {
validate_auto_cleanup_config(&manifest)?;
}
if changes_zone_write_seeds_config(&self.operation) {
validate_zone_write_seeds_config(&manifest)?;
}

apply_range_segments(&mut manifest, current_manifest)?;

Expand Down Expand Up @@ -4244,6 +4269,36 @@
);
}

#[test]
fn zone_write_seeds_settings_invalid_before_the_commit_do_not_block_it() {
let mut manifest = sample_manifest();
manifest.config.insert(
crate::feature_flags::ZONE_WRITE_SEEDS_ENABLED_KEY.into(),
"yes".into(),
);
assert!(validate_zone_write_seeds_config(&manifest).is_err());
let transaction = Transaction::new(
manifest.version,
Operation::UpdateConfig {
config_updates: Some(crate::transaction::UpdateMap {
update_entries: vec![crate::transaction::update_map::UpdateMapEntry {
key: "unrelated".into(),
value: Some("1".into()),
}],
replace: false,
}),
table_metadata_updates: None,
schema_metadata_updates: None,
field_metadata_updates: HashMap::new(),
},
None,
);

transaction
.build_manifest(Some(&manifest), vec![], "txn", &default_build_config())
.unwrap();
}

fn covered_index(name: &str, fields: Vec<i32>, covering_fields: Vec<i32>) -> IndexMetadata {
IndexMetadata {
fields,
Expand Down
7 changes: 5 additions & 2 deletions rust/lance/src/dataset/optimize/binary_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ pub async fn rewrite_files_binary_copy(
// Seeds of the inputs feeding the current output file, in copy order.
let mut seed_acc = OutputSeedAccumulator::default();
let index_rows_per_zone = seed_carry::index_rows_per_zone(dataset).await?;
let unindexed_rows_per_zone = seed_carry::unindexed_rows_per_zone(dataset);

// Visit each fragment and all of its data files (a fragment may contain multiple files)
for frag in fragments.iter() {
Expand Down Expand Up @@ -387,7 +388,8 @@ pub async fn rewrite_files_binary_copy(
// Accumulate rows for the current output file and flush when reaching the threshold
total_rows_in_current += file_meta.num_rows;
if total_rows_in_current >= max_rows_per_file {
let output_seeds = seed_acc.finish(&schema, &index_rows_per_zone)?;
let output_seeds =
seed_acc.finish(&schema, &index_rows_per_zone, unindexed_rows_per_zone)?;
let fragment_out = finalize_current_output_file(
&schema,
version,
Expand Down Expand Up @@ -420,7 +422,8 @@ pub async fn rewrite_files_binary_copy(
// Flush remaining rows as a final output file
init_writer_if_necessary(dataset, version, &mut current_writer, &mut current_filename)
.await?;
let output_seeds = seed_acc.finish(&schema, &index_rows_per_zone)?;
let output_seeds =
seed_acc.finish(&schema, &index_rows_per_zone, unindexed_rows_per_zone)?;
let frag = finalize_current_output_file(
&schema,
version,
Expand Down
Loading
Loading