diff --git a/.config/nextest.toml b/.config/nextest.toml index 68f920ddcc1..5a1e64de727 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -1,14 +1,2 @@ [profile.default] slow-timeout = { period = "30s", terminate-after = 5 } - -# Spatial tests concurrently call INSTALL spatial which fails -[test-groups] -duckdb-extension-install = { max-threads = 1 } - -[[profile.default.overrides]] -filter = 'test(compress_large_int | fsst_compress_offsets_overflow_i32)' -priority = 100 - -[[profile.default.overrides]] -filter = 'package(vortex-duckdb) & (test(spatial_) | test(test_geometry))' -test-group = 'duckdb-extension-install' diff --git a/Cargo.lock b/Cargo.lock index 042d61b6722..f092da52836 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11852,7 +11852,6 @@ dependencies = [ "rand 0.10.3", "rstest", "simdutf8", - "test-with", "vortex-array", "vortex-buffer", "vortex-error", diff --git a/encodings/fsst/Cargo.toml b/encodings/fsst/Cargo.toml index a0ba83259bd..dc85415669c 100644 --- a/encodings/fsst/Cargo.toml +++ b/encodings/fsst/Cargo.toml @@ -36,7 +36,6 @@ divan = { workspace = true } mimalloc = { workspace = true } rand = { workspace = true } rstest = { workspace = true } -test-with = { workspace = true } vortex-array = { workspace = true, features = ["_test-harness"] } vortex-expr = { workspace = true } diff --git a/encodings/fsst/src/tests.rs b/encodings/fsst/src/tests.rs index 270450cf746..e07d59706bb 100644 --- a/encodings/fsst/src/tests.rs +++ b/encodings/fsst/src/tests.rs @@ -201,59 +201,3 @@ fn fsst_compress_offset_width_rollover() -> VortexResult<()> { Ok(()) } - -// TODO(someone): ideally CI would run this in release mode as well since debug builds make the -// allocation and compression loop substantially slower. -/// Regression for #7833: [`fsst_compress`] must accept inputs whose cumulative compressed -/// bytes exceed [`i32::MAX`]. Before the fix, the compress path hardcoded -/// [`VarBinBuilder`] for the FSST output and panicked in -/// [`VarBinBuilder::append_value`] once cumulative compressed bytes crossed the boundary. -/// -/// The compressor is built with an empty symbol table, so every input byte misses the table -/// and is escape-coded at exactly two output bytes per input byte. This makes the output -/// size deterministic and crosses the i32 boundary with roughly half the input bytes that -/// an incompressible-input construction would need. The input is built with -/// [`VarBinBuilder`] so the input itself does not panic, which confirms the overflow -/// is on the FSST output side. After the fix the test must succeed with the row count -/// preserved. -/// -/// Allocates ~1.1 GiB for the input and ~2.1 GiB for the FSST output (~3.2 GiB total), so -/// it is gated to CI runs and skipped when `VORTEX_SKIP_SLOW_TESTS` is set. To run it -/// locally: -/// -/// ```text -/// CI=1 cargo test --release -p vortex-fsst fsst_compress_offsets -/// ``` -/// -/// [`fsst_compress`]: crate::compress::fsst_compress -#[test_with::env(CI)] -#[test_with::no_env(VORTEX_SKIP_SLOW_TESTS)] -fn fsst_compress_offsets_overflow_i32() { - const STRING_LEN: usize = 64 * 1024; - // Escape coding doubles every byte, so ~1.06 GiB of input compresses to ~2.13 GiB, - // comfortably past i32::MAX. - const TOTAL_BYTES: usize = (1usize << 30) + (64 << 20); - const N: usize = TOTAL_BYTES / STRING_LEN; - - println!("building large VarBinArray"); - let string = vec![b'a'; STRING_LEN]; - let mut builder = VarBinBuilder::::with_capacity_in( - DType::Utf8(Nullability::NonNullable), - N, - BufferAllocatorRef::static_ref(), - ); - for _ in 0..N { - builder.append_value(&string); - } - let array = builder.finish_into_varbin().into_array(); - - let compressor = CompressorBuilder::default().build(); - let len = array.len(); - let mut ctx = SESSION.create_execution_ctx(); - - println!("compressing to FSST"); - let compressed = fsst_compress(&array, &compressor, &mut ctx).unwrap(); - assert_eq!(compressed.len(), len); - // Prove the regression condition was exercised: compressed bytes crossed i32::MAX. - assert!(compressed.codes_bytes().len() > i32::MAX as usize); -} diff --git a/encodings/uuid/src/arrow_properties.rs b/encodings/uuid/src/arrow_properties.rs index 8c4c35b3dd5..18ddf4d1cd6 100644 --- a/encodings/uuid/src/arrow_properties.rs +++ b/encodings/uuid/src/arrow_properties.rs @@ -8,6 +8,7 @@ mod tests { use std::sync::Arc; + use std::sync::LazyLock; use arrow_array::builder::FixedSizeBinaryBuilder; use arrow_schema::DataType; @@ -45,6 +46,12 @@ mod tests { use crate::Uuid; use crate::UuidMetadata; + static SESSION: LazyLock = LazyLock::new(|| { + let session = VortexSession::empty(); + crate::initialize(&session); + session + }); + struct UuidCase { array: ArrayRef, field: Field, @@ -71,11 +78,7 @@ mod tests { Some(Version::Custom), Some(Version::Max), ])); - let mut bytes = tc.draw( - gs::vecs(gs::integers::()) - .min_size(len * 16) - .max_size(len * 16), - ); + let mut bytes = tc.draw(gs::binary().min_size(len * 16).max_size(len * 16)); if let Some(version) = version { set_uuid_version(&mut bytes, version); @@ -133,9 +136,7 @@ mod tests { #[track_caller] fn check_uuid_round_trip(tc: &TestCase) -> VortexResult<()> { - let session = VortexSession::empty(); - crate::initialize(&session); - let mut ctx = session.create_execution_ctx(); + let mut ctx = SESSION.create_execution_ctx(); let case = draw_case(tc, &mut ctx)?; assert_eq!(case.dtype.serialize_metadata()?, case.metadata); assert_eq!( @@ -148,9 +149,7 @@ mod tests { #[track_caller] fn check_native_and_order(tc: &TestCase) -> VortexResult<()> { - let session = VortexSession::empty(); - crate::initialize(&session); - let mut ctx = session.create_execution_ctx(); + let mut ctx = SESSION.create_execution_ctx(); let case = draw_case(tc, &mut ctx)?; for (i, expected) in case.source.iter().enumerate() { let scalar = case.array.execute_scalar(i, &mut ctx)?; diff --git a/vortex-btrblocks/src/tests.rs b/vortex-btrblocks/src/tests.rs index cfc57ca09b4..b9c89c4de25 100644 --- a/vortex-btrblocks/src/tests.rs +++ b/vortex-btrblocks/src/tests.rs @@ -77,6 +77,7 @@ use vortex_fastlanes::BitPacked; use vortex_fastlanes::Delta; use vortex_onpair::DEFAULT_CONFIG; use vortex_onpair::OnPair; +#[cfg(feature = "zstd")] use vortex_session::VortexSession; use vortex_sparse::Sparse; @@ -147,30 +148,30 @@ fn test_container_validity_is_compressed( ) -> VortexResult<()> { let mut ctx = SESSION.create_execution_ctx(); let validity = Validity::Array( - BoolArray::from_iter((0..100_000).map(|i| (1000..2000).contains(&i))).into_array(), + BoolArray::from_iter((0..4_096).map(|i| (1000..1500).contains(&i))).into_array(), ); - let elements = PrimitiveArray::from_iter(0..100_000i32).into_array(); + let elements = PrimitiveArray::from_iter(0..4_096i32).into_array(); let input = match kind { "struct" => { - StructArray::try_new(["value"].into(), [elements], 100_000, validity)?.into_array() + StructArray::try_new(["value"].into(), [elements], 4_096, validity)?.into_array() } "list" => ListArray::try_new( elements, - PrimitiveArray::from_iter(0..=100_000u32).into_array(), + PrimitiveArray::from_iter(0..=4_096u32).into_array(), validity, &mut ctx, )? .into_array(), "listview" => ListViewArray::try_new( elements, - PrimitiveArray::from_iter(0..100_000u32).into_array(), - PrimitiveArray::from_iter(iter::repeat_n(1u32, 100_000)).into_array(), + PrimitiveArray::from_iter(0..4_096u32).into_array(), + PrimitiveArray::from_iter(iter::repeat_n(1u32, 4_096)).into_array(), validity, &mut ctx, )? .into_array(), "fixed_size_list" => { - FixedSizeListArray::try_new(elements, 1, validity, 100_000)?.into_array() + FixedSizeListArray::try_new(elements, 1, validity, 4_096)?.into_array() } _ => unreachable!(), }; @@ -187,29 +188,29 @@ fn test_leaf_validity_is_compressed( #[values("bool", "integer", "float", "decimal", "string")] kind: &str, ) -> VortexResult<()> { let validity = Validity::Array( - BoolArray::from_iter((0..100_000).map(|i| (1000..2000).contains(&i))).into_array(), + BoolArray::from_iter((0..4_096).map(|i| (1000..1500).contains(&i))).into_array(), ); let input = match kind { "bool" => BoolArray::new( - BitBuffer::from_iter((0..100_000).map(|i| i % 2 == 0)), + BitBuffer::from_iter((0..4_096).map(|i| i % 2 == 0)), validity, ) .into_array(), - "integer" => PrimitiveArray::new(Buffer::from_iter(0..100_000i64), validity).into_array(), + "integer" => PrimitiveArray::new(Buffer::from_iter(0..4_096i64), validity).into_array(), "float" => PrimitiveArray::new( - Buffer::from_iter((0..100_000).map(|i| f64::from(i) / 3.0)), + Buffer::from_iter((0..4_096).map(|i| f64::from(i) / 3.0)), validity, ) .into_array(), "decimal" => DecimalArray::new( - (0..100_000i64).collect(), + (0..4_096i64).collect(), DecimalDType::new(12, 2), validity, &mut SESSION.create_execution_ctx(), ) .into_array(), "string" => VarBinViewArray::from_iter( - (0..100_000).map(|i| (1000..2000).contains(&i).then(|| format!("value-{i}"))), + (0..4_096).map(|i| (1000..1500).contains(&i).then(|| format!("value-{i}"))), DType::Utf8(Nullability::Nullable), ) .into_array(), @@ -614,7 +615,7 @@ fn test_integer_scheme_compresses_its_validity( #[case] scheme: &'static dyn Scheme, ) -> VortexResult<()> { let input = PrimitiveArray::from_option_iter( - (0..100_000i32).map(|i| (!(1000..2000).contains(&i)).then_some(i % 100)), + (0..4_096i32).map(|i| (!(1000..1500).contains(&i)).then_some(i % 100)), ) .into_array(); let compressor = BtrBlocksCompressorBuilder::empty() @@ -665,7 +666,7 @@ fn test_float_scheme_compresses_its_validity( #[case] scheme: &'static dyn Scheme, ) -> VortexResult<()> { let input = PrimitiveArray::from_option_iter( - (0..100_000).map(|i| (!(1000..2000).contains(&i)).then(|| f64::from(i).sqrt())), + (0..4_096).map(|i| (!(1000..1500).contains(&i)).then(|| f64::from(i).sqrt())), ) .into_array(); let compressor = BtrBlocksCompressorBuilder::empty() @@ -742,8 +743,8 @@ fn test_bytes_scheme_compresses_its_validity( #[case] dtype: DType, ) -> VortexResult<()> { let input = VarBinViewArray::from_iter( - (0..100_000).map(|i| { - (!(1000..2000).contains(&i)).then(|| format!("value-{}", i % 100).into_bytes()) + (0..4_096).map(|i| { + (!(1000..1500).contains(&i)).then(|| format!("value-{}", i % 100).into_bytes()) }), dtype, ) @@ -772,14 +773,14 @@ fn test_zstd_compacts_and_compresses_its_validity( // Values longer than 12 bytes live in the data buffers, and the slice references a tenth of // them, so compaction rewrites the array. let input = VarBinViewArray::from_iter( - (0..200_000).map(|i| { - (!(1000..2000).contains(&i)) + (0..40_960).map(|i| { + (!(1000..1500).contains(&i)) .then(|| format!("an outlined value {}", i % 100).into_bytes()) }), dtype, ) .into_array() - .slice(0..20_000)?; + .slice(0..4_096)?; let compressor = BtrBlocksCompressorBuilder::empty() .with_new_scheme(scheme) .with_new_scheme(&BoolRunEndScheme) @@ -796,8 +797,7 @@ fn test_zstd_compacts_and_compresses_its_validity( #[test] fn test_varbin_validity_is_compressed() -> VortexResult<()> { let input = VarBinViewArray::from_iter( - (0..100_000) - .map(|i| (!(1000..2000).contains(&i)).then(|| format!("value-{i}").into_bytes())), + (0..4_096).map(|i| (!(1000..1500).contains(&i)).then(|| format!("value-{i}").into_bytes())), DType::Binary(Nullability::Nullable), ) .into_array(); @@ -912,7 +912,7 @@ impl ChildPolicy for KeepEverything { #[case::schemes_decide(false)] #[case::policy_keeps(true)] fn test_child_policy_overrides_schemes(#[case] keep: bool) -> VortexResult<()> { - let input = PrimitiveArray::from_iter((0..1_000_000).map(|i| i / 100)).into_array(); + let input = PrimitiveArray::from_iter((0..8_192).map(|i| i / 8)).into_array(); let mut builder = BtrBlocksCompressorBuilder::empty() .with_new_scheme(&RunEndScheme) .with_new_scheme(&BITPACKING_V1); diff --git a/vortex-duckdb/src/e2e_test/mod.rs b/vortex-duckdb/src/e2e_test/mod.rs index 7be5711b2e5..66a30e84850 100644 --- a/vortex-duckdb/src/e2e_test/mod.rs +++ b/vortex-duckdb/src/e2e_test/mod.rs @@ -5,6 +5,64 @@ //! //! These tests exercise the registered extension through scans, spatial pushdown, and S3 reads. +#[cfg(test)] +mod spatial_loader { + use std::env; + use std::fs; + use std::fs::OpenOptions; + use std::path::PathBuf; + + use vortex::error::VortexResult; + + use crate::duckdb::Connection; + + fn spatial_extension_dir() -> VortexResult { + let dir = env::var_os("HOME") + .or_else(|| env::var_os("USERPROFILE")) + .map(|home| { + PathBuf::from(home) + .join(".duckdb") + .join("vortex-test-extensions") + }) + .unwrap_or_else(|| env::temp_dir().join("vortex-duckdb-test-extensions")); + fs::create_dir_all(&dir)?; + Ok(dir) + } + + /// Loads DuckDB's `spatial` extension, synchronizing one-time installation across threads and + /// processes with a file lock. + pub(crate) fn load_spatial(conn: &Connection) -> VortexResult<()> { + if conn.query("LOAD spatial;").is_ok() { + return Ok(()); + } + + let ext_dir = spatial_extension_dir()?; + let escaped_dir = ext_dir.to_string_lossy().replace('\'', "''"); + conn.query(&format!("SET extension_directory = '{escaped_dir}';"))?; + + if conn.query("LOAD spatial;").is_ok() { + return Ok(()); + } + + let lock_file = OpenOptions::new() + .create(true) + .truncate(false) + .write(true) + .open(ext_dir.join(".spatial.lock"))?; + lock_file.lock()?; + + if conn.query("LOAD spatial;").is_ok() { + return Ok(()); + } + + conn.query("INSTALL spatial; LOAD spatial;")?; + Ok(()) + } +} + +#[cfg(test)] +pub(crate) use spatial_loader::load_spatial; + #[cfg(test)] mod s3_test; #[cfg(all(test, duckdb_release))] diff --git a/vortex-duckdb/src/e2e_test/spatial_pushdown_test.rs b/vortex-duckdb/src/e2e_test/spatial_pushdown_test.rs index 5e15416d9b6..b4a1bdd2dbd 100644 --- a/vortex-duckdb/src/e2e_test/spatial_pushdown_test.rs +++ b/vortex-duckdb/src/e2e_test/spatial_pushdown_test.rs @@ -18,6 +18,7 @@ use vortex_spatial::extension::Dimension; use vortex_spatial::extension::Point; use vortex_spatial::extension::SpatialMetadata; +use super::load_spatial; use crate::RUNTIME; use crate::SESSION; use crate::cpp::duckdb_string_t; @@ -86,7 +87,7 @@ fn spatial_database() -> (Database, Connection) { db.register_vortex_scan_replacement().unwrap(); crate::initialize(&db).unwrap(); let conn = db.connect().unwrap(); - conn.query("INSTALL spatial; LOAD spatial;").unwrap(); + load_spatial(&conn).unwrap(); // Must follow `LOAD spatial`: the overrides copy spatial's catalog entries. db.register_spatial_overrides().unwrap(); (db, conn) diff --git a/vortex-duckdb/src/e2e_test/vortex_scan_test.rs b/vortex-duckdb/src/e2e_test/vortex_scan_test.rs index f99f3bfac6c..ecbc38dd99c 100644 --- a/vortex-duckdb/src/e2e_test/vortex_scan_test.rs +++ b/vortex-duckdb/src/e2e_test/vortex_scan_test.rs @@ -10,6 +10,8 @@ use anyhow::Result; use geo_types::LineString; use geo_types::Polygon; use num_traits::AsPrimitive; +use parking_lot::Mutex; +use parking_lot::MutexGuard; use rstest::rstest; use tempfile::NamedTempFile; use vortex::array::IntoArray; @@ -42,6 +44,7 @@ use vortex_spatial::extension::SpatialMetadata; use vortex_spatial::extension::WellKnownBinary; use wkb::writer::WriteOptions; +use super::load_spatial; use crate::RUNTIME; use crate::SESSION; use crate::cpp; @@ -381,7 +384,7 @@ fn test_geometry() { }); let conn = database_connection(); - conn.query("INSTALL spatial; LOAD spatial;").unwrap(); + load_spatial(&conn).unwrap(); let file_path = file.path().to_string_lossy(); let result = conn .query(&format!("SELECT SUM(ST_Area(geometry)) FROM '{file_path}'")) @@ -556,6 +559,28 @@ fn query_i64_column(path: &str, query: &str) -> Result> { Ok(values) } +struct ScanV2Guard { + previous: bool, + _lock: MutexGuard<'static, ()>, +} + +impl ScanV2Guard { + fn acquire() -> Self { + static LOCK: Mutex<()> = Mutex::new(()); + let lock = LOCK.lock(); + Self { + previous: crate::scan_v2(), + _lock: lock, + } + } +} + +impl Drop for ScanV2Guard { + fn drop(&mut self) { + crate::set_scan_v2(self.previous); + } +} + #[rstest] #[case::filtered_count("SELECT count(*) FROM ? WHERE b < 100")] #[case::filtered_max("SELECT max(a) FROM ? WHERE b BETWEEN 300 AND 310")] @@ -581,12 +606,12 @@ fn test_vortex_scan_v2_matches_v1(#[case] query: &str) -> Result<()> { )); let path = file.path().to_string_lossy(); + let _scan_v2 = ScanV2Guard::acquire(); crate::set_scan_v2(false); let v1 = query_i64_column(&path, query)?; crate::set_scan_v2(true); - let v2 = query_i64_column(&path, query); - crate::set_scan_v2(false); + let v2 = query_i64_column(&path, query)?; - assert_eq!(v2?, v1); + assert_eq!(v2, v1); Ok(()) }