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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
//! Operations module for dsq
//!
//! This module provides core operations for manipulating `DataFrames` and other data structures
//! in dsq. It includes basic operations like selection and filtering, aggregation operations
//! like group by and statistical functions, join operations for combining datasets, and
//! transformation operations for reshaping and converting data.
//!
//! The operations are designed to work with both Polars `DataFrames` and jq-style arrays
//! and objects, providing a unified interface that bridges the gap between structured
//! and semi-structured data processing.
//!
//! # Examples
//!
//! Basic operations:
//! ```rust,ignore
//! use dsq_core::ops::basic::{select_columns, filter_values, sort_by_columns, SortOptions};
//! use dsq_core::value::Value;
//!
//! // Select specific columns
//! let columns = vec!["name".to_string(), "age".to_string()];
//! let result = select_columns(&dataframe_value, &columns).unwrap();
//!
//! // Sort by multiple columns
//! let sort_opts = vec![
//! SortOptions::desc("age"),
//! SortOptions::asc("name"),
//! ];
//! let sorted = sort_by_columns(&result, &sort_opts).unwrap();
//! ```
//!
//! Aggregation operations:
//! ```rust,ignore
//! use dsq_core::ops::aggregate::{group_by_agg, AggregationFunction};
//! use dsq_core::value::Value;
//!
//! let group_cols = vec!["department".to_string()];
//! let agg_funcs = vec![
//! AggregationFunction::Sum("salary".to_string()),
//! AggregationFunction::Mean("age".to_string()),
//! AggregationFunction::Count,
//! ];
//! let result = group_by_agg(&dataframe_value, &group_cols, &agg_funcs).unwrap();
//! ```
//!
//! Join operations:
//! ```rust,ignore
//! use dsq_core::ops::join::{inner_join, JoinKeys};
//! use dsq_core::value::Value;
//!
//! let keys = JoinKeys::on(vec!["id".to_string()]);
//! let result = inner_join(&left_df, &right_df, &keys).unwrap();
//! ```
//!
//! Transformation operations:
//! ```rust,ignore
//! use dsq_core::ops::transform::{transpose, string::to_uppercase};
//! use dsq_core::value::Value;
//!
//! let transposed = transpose(&dataframe_value).unwrap();
//! let uppercase = to_uppercase(&dataframe_value, "name").unwrap();
//! ```
//!
//! # Architecture
//!
//! The operations module is organized into four main submodules:
//!
//! - [`basic`] - Fundamental operations like selection, filtering, sorting
//! - [`aggregate`] - Grouping and aggregation operations
//! - `join` - Operations for combining multiple datasets
//! - [`transform`] - Data transformation and reshaping operations
//!
//! Each operation is designed to work with the [`Value`] enum, which can represent
//! `DataFrames`, `LazyFrames`, arrays, objects, or scalar values. This unified approach
//! allows operations to work seamlessly across different data representations.
//!
//! # Error Handling
//!
//! All operations return [`Result<Value>`] where errors are represented by the
//! `Error` type. Common error scenarios include:
//!
//! - Type mismatches (e.g., trying to sort non-comparable values)
//! - Missing columns or fields
//! - Schema incompatibilities in joins
//! - Invalid operation parameters
//!
//! Operations will attempt to handle mixed data types gracefully where possible,
//! but will return descriptive errors when operations cannot be completed.
//!
//! # Performance Considerations
//!
//! Operations are optimized for different data representations:
//!
//! - **`DataFrame` operations** leverage Polars' optimized columnar processing
//! - **`LazyFrame` operations** benefit from query optimization and lazy evaluation
//! - **Array operations** use efficient in-memory processing for jq-style data
//! - **Mixed operations** automatically convert between representations as needed
//!
//! For large datasets, prefer using `LazyFrame` operations when possible to take
//! advantage of query optimization and memory-efficient processing.
/// Data transformation operations
// Re-export commonly used types and functions for convenience
pub use ;
pub use ;
pub use ;
pub use Transform;
pub use ;
pub use ;
// Re-export operation types from filter_ops modules
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SelectConditionOperation;
use crateResult;
use crateValue;
/// Trait for operations that can be applied to values
///
/// This trait provides a common interface for all data operations,
/// allowing them to be composed and chained together.