1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//! 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()
}
}