sqlload 0.25.0

SQL data loading tooling. Pre-release, under development.
//! Decide whether a partition lies in a cursor window.

use crate::adapters::files::_helpers::layout::partitions::{bound_key, partition_key};
use crate::adapters::files::models::PartitionBy;
use crate::column_types::models::ColumnType;

/// Whether partition `value` lies in `from <= value < to` (each open when `None`).
pub(in crate::adapters) fn partition_in_window(
    value: &str,
    by: PartitionBy,
    cursor_type: &ColumnType,
    bounds: (Option<&str>, Option<&str>),
) -> Result<bool, String> {
    let key = partition_key(value, by, cursor_type)?;
    let after_start = match bounds.0 {
        Some(from) => key >= bound_key(from, by, cursor_type)?,
        None => true,
    };
    let before_end = match bounds.1 {
        Some(to) => key < bound_key(to, by, cursor_type)?,
        None => true,
    };
    Ok(after_start && before_end)
}