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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
//! # SSTable Binary Format Parser Module
//!
//! This module provides parsing functionality for Apache Cassandra SSTable binary formats.
//! It handles deserialization of binary data structures from SSTable files (Data.db,
//! Index.db, Statistics.db, etc.) produced by Cassandra 5.0+.
//!
//! ## Architecture Overview
//!
//! This is one of four parsing subsystems in cqlite-core:
//!
//! | Module | Purpose |
//! |--------|---------|
//! | `cql/` | Full CQL text → AST parsing |
//! | **`parser/`** | SSTable binary format parsing (this module) |
//! | `schema/cql_parser.rs` | CREATE TABLE → TableSchema |
//! | `query/parser.rs` | Lightweight DML → ParsedQuery |
//!
//! See `docs/architecture/parser-overview.md` for the complete architecture overview.
//!
//! ## Module Architecture
//!
//! ```text
//! parser/ (SSTable Binary Format Parsing)
//! │
//! ├── Core Binary Parsing
//! │ ├── vint.rs - Variable-length integer (VInt) encoding
//! │ ├── vint_fixed.rs - Fixed-size integer alternatives
//! │ └── header.rs - SSTable header parsing (magic numbers, version detection)
//! │
//! ├── Statistics Parsing
//! │ ├── statistics.rs - Statistics.db basic format
//! │ └── enhanced_statistics_parser.rs - Statistics.db enhanced format (nb/oa)
//! │
//! ├── CQL Type Deserialization
//! │ ├── types.rs - All CQL primitive types (int, text, uuid, etc.)
//! │ ├── complex_types.rs - Collections, UDTs, tuples, frozen types
//! │ └── optimized_complex_types.rs - M3 performance-optimized parsing
//! │
//! ├── Performance Utilities
//! │ └── zero_copy_parser.rs - String interning, zero-copy buffers
//! │
//! └── High-Level Interface
//! └── binary.rs - SSTableParser facade
//! ```
//!
//! Note: Test modules (`*_test.rs`, `*_tests.rs`) and benchmarks (`*_benchmarks.rs`)
//! are omitted from the diagram. See feature flag `benchmarks` for performance testing.
//!
//! ## Key Distinction: parser/ vs cql/
//!
//! | Module | Purpose | Input | Output |
//! |--------|---------|-------|--------|
//! | **parser/** | SSTable binary parsing | Raw bytes from .db files | Structured Rust values |
//! | **cql/** | CQL text parsing | Query strings ("SELECT...") | Abstract Syntax Trees |
//!
//! This module (`parser/`) handles **binary deserialization**:
//! - Reading bytes from SSTable files (Data.db, Statistics.db, etc.)
//! - Decoding VInt-encoded integers per Cassandra's wire format
//! - Deserializing CQL values (int → i32, text → String, uuid → Uuid)
//!
//! For **CQL text parsing** (CREATE TABLE, SELECT, etc.), see the [`crate::cql`] module.
//!
//! ## Sub-module Reference
//!
//! ### Variable-Length Integer Encoding
//! - [`vint`] - VInt encoding/decoding per Cassandra specification, with corruption detection
//! - [`vint_fixed`] - Fixed-size integer parsing for when VInt isn't used
//!
//! ### SSTable Headers
//! - [`header`] - SSTable header parsing with version detection (oa/nb/legacy formats)
//!
//! ### Statistics Files
//! - [`statistics`] - Statistics.db parsing for row counts, timestamps, min/max metadata
//! - [`enhanced_statistics_parser`] - Enhanced Statistics.db format for Cassandra 5.0's
//! nb (nested btree) and oa (open addressing) formats
//!
//! ### CQL Type Deserialization
//! - [`types`] - All 20+ CQL primitive types: int, bigint, text, blob, uuid, timestamp,
//! date, time, inet, varint, decimal, duration, boolean, float, double, ascii, timeuuid
//! - [`complex_types`] - Collections (list, set, map), UDTs, tuples, with depth tracking
//! for nested types
//! - [`optimized_complex_types`] - M3 milestone performance optimizations for complex types
//!
//! ### Performance
//! - [`zero_copy_parser`] - Memory optimization utilities: string interning, zero-copy
//! buffer management to stay under 128MB memory target
//!
//! ### High-Level Interface
//! - [`binary`] - `SSTableParser` facade providing unified access to parsing functionality
//!
//! ## Usage Examples
//!
//! ```rust,ignore
//! use cqlite_core::parser::{parse_vint, SSTableHeader, CqlType};
//!
//! // Parse variable-length integer from raw bytes
//! let bytes = [0x8A, 0x01]; // VInt-encoded value
//! let (remaining, value) = parse_vint(&bytes)?;
//!
//! // Parse SSTable header to detect format version
//! let header = SSTableHeader::parse(&file_bytes)?;
//! println!("SSTable format: {:?}", header.format_type);
//! ```
//!
//! ## Backward Compatibility
//!
//! The [`parse_cql_schema`] function is maintained for backward compatibility with
//! existing code. **New code should use [`crate::cql::parse_cql_schema_enhanced`]**
//! which provides better error handling and configuration options.
//!
//! ## Related Documentation
//!
//! - SSTable format specification: `docs/sstables-definitive-guide/`
//! - Known limitations: `docs/sstables-definitive-guide/chapters/appendix-f-known-limitations.md`
// Binary format parsing (SSTable components)
// Re-export existing modules for backward compatibility
// pub mod collection_udt_tests; // Commented out due to missing methods
// Property tests for Issue #61
// M3 Performance Optimization Modules
// Re-export binary format parser
pub use ;
// Re-export binary format parsers for backward compatibility
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
pub use *;
// Re-export M3 performance modules
pub use OptimizedComplexTypeParser;
/// Re-export common result types
pub use crateResult as CqlResult;
/// Parse CQL CREATE TABLE statement (backward compatibility function)
///
/// **DEPRECATED**: This function maintains backward compatibility with existing code.
/// For new code, use `cqlite_core::schema::parse_cql_schema()` which is synchronous
/// and returns `Result<TableSchema>` instead of `nom::IResult`.
///
/// # Arguments
/// * `input` - The CQL CREATE TABLE statement to parse
///
/// # Returns
/// * `nom::IResult<&str, crate::schema::TableSchema>` - Parsed schema or error