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
//! # pvstream
//!
//! Stream download, parse, and filter Wikimedia pageviews files.
//!
//! This library provides efficient streaming access to Wikimedia's hourly pageview
//! dumps. It can download and parse multi-gigabyte compressed files on-the-fly
//! without storing the entire file in memory.
//!
//! ## Features
//!
//! - **Streaming parsing**: Process files as they download, minimizing memory usage
//! - **Flexible filtering**: Filter by language, domain, page title (regex), view counts, and more
//! - **Performance optimization**: Apply regex filters before parsing for maximum efficiency
//! - **Parquet export**: Convert filtered data to Parquet format for analysis
//! - **Rust and Python**: Native Rust library with Python bindings via PyO3
//!
//! ## Quick Start
//!
//! ```no_run
//! use pvstream::{stream_from_file, filter::FilterBuilder};
//! use std::path::PathBuf;
//!
//! let filter = FilterBuilder::new()
//! .domain_codes(["en.m"])
//! .page_title("Rust")
//! .build();
//!
//! let rows = stream_from_file(PathBuf::from("pageviews.gz"), &filter).unwrap();
//! for result in rows {
//! match result {
//! Ok(pageview) => println!("{:?}", pageview),
//! Err(e) => eprintln!("Error: {:?}", e),
//! }
//! }
//! ```
use crate;
use ;
use PathBuf;
use ;
use ;
use Url;
/// Iterator type returned by streaming functions.
///
/// Yields `Result<Pageviews, ParseError>` for each line in the pageviews file.
pub type RowIterator = ;
/// Decompress, stream, and parse lines from a local pageviews file
///
/// The function will return a `StreamError` if it fails to read the file.
/// Otherwise, it returns a `Pageviews` iterator, yielding a `ParseError`
/// for each line it fails to parse, either due to IO issues or a parsing
/// error.
///
/// # Example
///
/// ```no_run
/// use pvstream::{stream_from_file, filter::FilterBuilder};
/// use std::path::PathBuf;
///
/// let filter = FilterBuilder::new().domain_codes(["en"]).build();
/// let rows = stream_from_file(PathBuf::from("pageviews-20240818-080000.gz"), &filter)?;
///
/// for result in rows {
/// println!("{:?}", result?);
/// }
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Decompress, stream, and parse lines from a remote pageviews file
///
/// The function will return a `StreamError` if it fails to read the file.
/// Otherwise, it returns a `Pageviews` iterator, yielding a `ParseError`
/// for each line it fails to parse, either due to IO issues or a parsing
/// error.
///
/// # Example
///
/// ```no_run
/// use pvstream::{stream_from_url, filter::FilterBuilder};
/// use url::Url;
///
/// let url = Url::parse("https://dumps.wikimedia.org/other/pageviews/2024/2024-08/pageviews-20240818-080000.gz")?;
/// let filter = FilterBuilder::new().languages(["ja"]).build();
/// let rows = stream_from_url(url, &filter)?;
///
/// for result in rows.take(10) {
/// println!("{:?}", result?);
/// }
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Parse a local pageviews file and write filtered results to a Parquet file.
///
/// This function processes the entire input file and writes the filtered
/// results to a Parquet file on disk. Use this when you want to convert
/// pageviews data to Parquet format for later analysis.
///
/// By default, the batches will equal the default parquet row group size,
/// which causes memory requirements of about 100MB. Lower this to sacrifice
/// performance for lower memory requirements, or vice versa.
///
/// # Example
///
/// ```no_run
/// use pvstream::{parquet_from_file, filter::FilterBuilder};
/// use std::path::PathBuf;
///
/// let filter = FilterBuilder::new()
/// .min_views(100)
/// .languages(["en", "de", "fr"])
/// .build();
///
/// parquet_from_file(
/// PathBuf::from("pageviews-20240818-080000.gz"),
/// PathBuf::from("output.parquet"),
/// &filter,
/// None, // Use default batch size
/// )?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```
/// Download a remote pageviews file and write filtered results to a Parquet file.
///
/// This function streams the file from a remote URL and writes the filtered
/// results to a Parquet file on disk. Use this when you want to download and
/// convert pageviews data to Parquet format in one step.
///
/// By default, the batches will equal the default parquet row group size,
/// which causes memory requirements of about 100MB. Lower this to sacrifice
/// performance for lower memory requirements, or vice versa.
///
/// # Example
///
/// ```no_run
/// use pvstream::{parquet_from_url, filter::FilterBuilder};
/// use std::path::PathBuf;
/// use url::Url;
///
/// let url = Url::parse("https://dumps.wikimedia.org/other/pageviews/2024/2024-08/pageviews-20240818-080000.gz")?;
/// let filter = FilterBuilder::new()
/// .domain_codes(["en.m"])
/// .min_views(50)
/// .build();
///
/// parquet_from_url(
/// url,
/// PathBuf::from("output.parquet"),
/// &filter,
/// None,
/// )?;
/// # Ok::<(), Box<dyn std::error::Error>>(())
/// ```