sql-cli 1.69.3

SQL query tool for CSV/JSON with both interactive TUI and non-interactive CLI modes - perfect for exploration and automation
Documentation
//! Batch evaluation system for window functions
//!
//! This module provides optimized batch evaluation of window functions
//! to eliminate per-row overhead and improve performance significantly.

use std::collections::HashMap;
use std::sync::Arc;

use crate::sql::parser::ast::{SqlExpression, WindowSpec};
use crate::sql::window_context::WindowContext;

/// Specification for a single window function in a query
///
/// This structure captures all metadata needed to evaluate
/// a window function and place its results in the output table
#[derive(Debug, Clone)]
pub struct WindowFunctionSpec {
    /// The window specification (PARTITION BY, ORDER BY, frame)
    pub spec: WindowSpec,

    /// Function name (e.g., "LAG", "LEAD", "ROW_NUMBER")
    pub function_name: String,

    /// Arguments to the window function
    pub args: Vec<SqlExpression>,

    /// Column index in the output table where results should be placed
    pub output_column_index: usize,
}

/// Batch evaluator for window functions
///
/// This structure manages batch evaluation of window functions
/// to avoid repeated context lookups and per-row overhead
pub struct BatchWindowEvaluator {
    /// All window function specifications in the query
    specs: Vec<WindowFunctionSpec>,

    /// Pre-created window contexts, keyed by spec hash
    contexts: HashMap<u64, Arc<WindowContext>>,
}

impl BatchWindowEvaluator {
    /// Create a new batch window evaluator
    pub fn new() -> Self {
        Self {
            specs: Vec::new(),
            contexts: HashMap::new(),
        }
    }

    // Additional methods will be added in subsequent steps:
    // - add_spec() - Add a window function specification
    // - create_contexts() - Pre-create all window contexts
    // - evaluate_batch() - Batch evaluate all window functions
    // - get_results() - Retrieve results for a specific row
}

impl Default for BatchWindowEvaluator {
    fn default() -> Self {
        Self::new()
    }
}