vortex-spatial 0.87.0

Spatial data types and compute for Vortex
Documentation
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors

//! The `spatial` edition family.
//!
//! Spatial support is opt-in. [`crate::initialize`] registers and enables the edition so the
//! writer can serialize spatial dtypes and the AABB zone stat registered by the crate.

use vortex_edition::Edition;
use vortex_edition::EditionDeclaration;
use vortex_edition::EditionFamily;
use vortex_edition::EditionId;
use vortex_edition::EditionMember;

/// The `spatial` family: the geometry dtypes and the AABB zone aggregate.
pub static FAMILY: EditionFamily = EditionFamily {
    name: "spatial",
    origin: "vortex-spatial",
    doc: "The geometry extension dtypes and the axis-aligned bounding-box zone aggregate. \
Spatial support is opt-in: a reader built without `vortex-spatial` cannot resolve \
`vortex.st.*`, so these members are versioned independently of `core` and a session enables \
this family only by initializing the crate.",
};

/// The August 2026 draft edition of the `spatial` family.
pub const SPATIAL_2026_08: EditionId = EditionId::new("spatial", 2026, 8, 0);

/// The declaration of [`SPATIAL_2026_08`] and the components that join the family at it.
///
/// A draft: no Vortex release yet guarantees these members forever. The dtype members appear in
/// file schemas, and the AABB aggregate is recorded in the zone maps of geometry columns.
pub static DECLARATION: EditionDeclaration = EditionDeclaration {
    edition: Edition {
        id: SPATIAL_2026_08,
        min_library_version: None,
    },
    added: &[
        EditionMember::dtype(&"vortex.st.box"),
        EditionMember::dtype(&"vortex.st.linestring"),
        EditionMember::dtype(&"vortex.st.multilinestring"),
        EditionMember::dtype(&"vortex.st.multipoint"),
        EditionMember::dtype(&"vortex.st.multipolygon"),
        EditionMember::dtype(&"vortex.st.point"),
        EditionMember::dtype(&"vortex.st.polygon"),
        EditionMember::dtype(&"vortex.st.wkb"),
        EditionMember::aggregate(&"vortex.st.aabb"),
    ],
};

#[cfg(test)]
mod tests {
    use vortex_edition::ComponentKind;
    use vortex_edition::EditionSessionExt;
    use vortex_edition::test_harness::validate_edition;
    use vortex_error::VortexResult;

    use super::*;

    #[test]
    fn spatial_edition_is_valid() -> VortexResult<()> {
        let session = crate::test_harness::spatial_session();
        validate_edition(&session.editions(), &SPATIAL_2026_08)
    }

    /// A spatial session must permit the AABB zone stat it registers, or writing a geometry
    /// column fails on the aggregate the session itself asked for.
    #[test]
    fn initialize_permits_the_aabb_zone_stat() {
        let session = crate::test_harness::spatial_session();
        let enabled = session.enabled_component_ids(ComponentKind::Aggregate);
        assert!(
            enabled.iter().any(|id| id.as_str() == "vortex.st.aabb"),
            "spatial session permits {enabled:?}"
        );
    }

    #[test]
    fn initialize_permits_spatial_dtypes() {
        let session = crate::test_harness::spatial_session();
        let enabled = session.enabled_component_ids(ComponentKind::DType);
        assert_eq!(enabled.len(), 8);
        assert!(enabled.iter().any(|id| id.as_str() == "vortex.st.point"));
    }
}