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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
//! Hyprstream server binary.
//!
//! This binary provides the main entry point for the Hyprstream service, a next-generation application
//! for real-time data ingestion, windowed aggregation, caching, and serving.
//!
//! # Features
//!
//! - **Data Ingestion**: Ingest data efficiently using Arrow Flight
//! - **Intelligent Caching**: High-performance caching with DuckDB
//! - **Real-time Aggregation**: Dynamic metrics and time-windowed aggregates
//! - **ADBC Integration**: Seamless connection to external databases
//!
//! # Configuration
//!
//! Configuration can be provided through multiple sources, in order of precedence:
//!
//! 1. Command-line arguments (highest precedence)
//! 2. Environment variables (prefixed with `HYPRSTREAM_`)
//! 3. User-specified configuration file (via `--config`)
//! 4. System-wide configuration (`/etc/hyprstream/config.toml`)
//! 5. Default configuration (embedded in binary)
//!
//! ## Command-line Options
//!
//! ```text
//! Options:
//! -c, --config <FILE> Path to configuration file
//! --host <HOST> Server host address [env: HYPRSTREAM_SERVER_HOST]
//! --port <PORT> Server port [env: HYPRSTREAM_SERVER_PORT]
//! --engine <TYPE> Primary storage engine type [env: HYPRSTREAM_ENGINE]
//! --engine-connection <STR> Engine connection string [env: HYPRSTREAM_ENGINE_CONNECTION]
//! --engine-options <KEY=VAL> Engine options (can be specified multiple times) [env: HYPRSTREAM_ENGINE_OPTIONS]
//! --enable-cache Enable caching [env: HYPRSTREAM_ENABLE_CACHE]
//! --cache-engine <TYPE> Cache engine type [env: HYPRSTREAM_CACHE_ENGINE]
//! --cache-connection <STR> Cache connection string [env: HYPRSTREAM_CACHE_CONNECTION]
//! --cache-options <KEY=VAL> Cache options (can be specified multiple times) [env: HYPRSTREAM_CACHE_OPTIONS]
//! --cache-max-duration <SECS> Cache max duration in seconds [env: HYPRSTREAM_CACHE_MAX_DURATION]
//! ```
//!
//! ## Configuration File Format (TOML)
//!
//! ```toml
//! # Server Configuration
//! [server]
//! host = "127.0.0.1" # Server host address
//! port = 50051 # Server port number
//!
//! # Engine Configuration
//! [engine]
//! engine = "duckdb" # Options: "duckdb", "adbc"
//! connection = ":memory:"
//! options = { } # Engine-specific options
//!
//! # Cache Configuration
//! [cache]
//! enabled = true # Enable caching
//! engine = "duckdb" # Options: "duckdb", "adbc"
//! connection = ":memory:"
//! max_duration_secs = 3600
//! options = { } # Cache-specific options
//! ```
//!
//! ## Storage Backends
//!
//! ### DuckDB Backend
//!
//! The DuckDB backend provides high-performance embedded storage:
//!
//! ```toml
//! [engine]
//! engine = "duckdb"
//! connection = ":memory:" # Use ":memory:" for in-memory or file path
//! options = {
//! threads = "4", # Number of threads (optional)
//! read_only = "false" # Read-only mode (optional)
//! }
//! ```
//!
//! ### ADBC Backend
//!
//! The ADBC backend enables connection to external databases:
//!
//! ```toml
//! [engine]
//! engine = "adbc"
//! connection = "postgresql://localhost:5432"
//! options = {
//! driver_path = "/usr/local/lib/libadbc_driver_postgresql.so", # Required
//! username = "postgres", # Optional
//! password = "secret", # Optional
//! database = "metrics", # Optional
//! pool_max = "10", # Optional
//! pool_min = "1", # Optional
//! connect_timeout = "30" # Optional
//! }
//! ```
//!
//! ### Cached Backend
//!
//! The cached backend implements a two-tier storage system:
//!
//! ```toml
//! [engine]
//! engine = "duckdb"
//! connection = "data.db"
//! options = { }
//!
//! [cache]
//! enabled = true
//! engine = "duckdb"
//! connection = ":memory:"
//! max_duration_secs = 3600
//! options = {
//! threads = "2"
//! }
//! ```
//!
//! # Examples
//!
//! ## Basic Usage
//!
//! ```bash
//! # Run with default configuration
//! hyprstream
//!
//! # Run with custom configuration file
//! hyprstream --config /path/to/config.toml
//!
//! # Run with environment variables
//! HYPRSTREAM_SERVER_HOST=0.0.0.0 HYPRSTREAM_SERVER_PORT=50051 hyprstream
//! ```
//!
//! ## Advanced Configuration
//!
//! ```bash
//! # Run with DuckDB storage and caching
//! hyprstream \
//! --engine duckdb \
//! --engine-connection ":memory:" \
//! --engine-options threads=4 \
//! --enable-cache \
//! --cache-engine duckdb \
//! --cache-connection ":memory:" \
//! --cache-max-duration 3600
//!
//! # Run with ADBC PostgreSQL backend
//! hyprstream \
//! --engine adbc \
//! --engine-connection "postgresql://localhost:5432" \
//! --engine-options driver_path=/usr/local/lib/libadbc_driver_postgresql.so \
//! --engine-options username=postgres \
//! --engine-options database=metrics \
//! --engine-options pool_max=10
//!
//! # Run with ADBC backend and DuckDB cache
//! hyprstream \
//! --engine adbc \
//! --engine-connection "postgresql://localhost:5432" \
//! --engine-options driver_path=/usr/local/lib/libadbc_driver_postgresql.so \
//! --engine-options username=postgres \
//! --enable-cache \
//! --cache-engine duckdb \
//! --cache-connection ":memory:" \
//! --cache-options threads=2 \
//! --cache-max-duration 3600
//! ```
//!
//! For more examples and detailed API documentation, visit the
//! [Hyprstream documentation](https://docs.rs/hyprstream).
use Parser;
use ;
use Arc;
use Server;
use ;
use ;
async