-
Notifications
You must be signed in to change notification settings - Fork 150
Expand file tree
/
Copy pathdata.rs
More file actions
212 lines (200 loc) · 8.56 KB
/
data.rs
File metadata and controls
212 lines (200 loc) · 8.56 KB
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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::fmt;
use std::fmt::Display;
use std::path::Path;
use std::str::FromStr;
use std::sync::LazyLock;
use arrow_schema::DataType;
use arrow_schema::Field;
use arrow_schema::Schema;
use arrow_schema::TimeUnit;
use clap::ValueEnum;
use serde::Deserialize;
use serde::Serialize;
use tokio::task::JoinSet;
use tracing::info;
use vortex::error::VortexExpect;
use crate::Format;
// Re-export for use by clickbench_benchmark
pub use crate::conversions::convert_parquet_directory_to_vortex;
use crate::datasets::data_downloads::download_data;
pub static HITS_SCHEMA: LazyLock<Schema> = LazyLock::new(|| {
use DataType::*;
Schema::new(vec![
Field::new("WatchID", Int64, false),
Field::new("JavaEnable", Int16, false),
Field::new("Title", Utf8View, false),
Field::new("GoodEvent", Int16, false),
Field::new("EventTime", Timestamp(TimeUnit::Microsecond, None), false),
Field::new("EventDate", Timestamp(TimeUnit::Microsecond, None), false),
Field::new("CounterID", Int32, false),
Field::new("ClientIP", Int32, false),
Field::new("RegionID", Int32, false),
Field::new("UserID", Int64, false),
Field::new("CounterClass", Int16, false),
Field::new("OS", Int16, false),
Field::new("UserAgent", Int16, false),
Field::new("URL", Utf8View, false),
Field::new("Referer", Utf8View, false),
Field::new("IsRefresh", Int16, false),
Field::new("RefererCategoryID", Int16, false),
Field::new("RefererRegionID", Int32, false),
Field::new("URLCategoryID", Int16, false),
Field::new("URLRegionID", Int32, false),
Field::new("ResolutionWidth", Int16, false),
Field::new("ResolutionHeight", Int16, false),
Field::new("ResolutionDepth", Int16, false),
Field::new("FlashMajor", Int16, false),
Field::new("FlashMinor", Int16, false),
Field::new("FlashMinor2", Utf8View, false),
Field::new("NetMajor", Int16, false),
Field::new("NetMinor", Int16, false),
Field::new("UserAgentMajor", Int16, false),
Field::new("UserAgentMinor", Utf8View, false),
Field::new("CookieEnable", Int16, false),
Field::new("JavascriptEnable", Int16, false),
Field::new("IsMobile", Int16, false),
Field::new("MobilePhone", Int16, false),
Field::new("MobilePhoneModel", Utf8View, false),
Field::new("Params", Utf8View, false),
Field::new("IPNetworkID", Int32, false),
Field::new("TraficSourceID", Int16, false),
Field::new("SearchEngineID", Int16, false),
Field::new("SearchPhrase", Utf8View, false),
Field::new("AdvEngineID", Int16, false),
Field::new("IsArtifical", Int16, false),
Field::new("WindowClientWidth", Int16, false),
Field::new("WindowClientHeight", Int16, false),
Field::new("ClientTimeZone", Int16, false),
Field::new(
"ClientEventTime",
Timestamp(TimeUnit::Microsecond, None),
false,
),
Field::new("SilverlightVersion1", Int16, false),
Field::new("SilverlightVersion2", Int16, false),
Field::new("SilverlightVersion3", Int32, false),
Field::new("SilverlightVersion4", Int16, false),
Field::new("PageCharset", Utf8View, false),
Field::new("CodeVersion", Int32, false),
Field::new("IsLink", Int16, false),
Field::new("IsDownload", Int16, false),
Field::new("IsNotBounce", Int16, false),
Field::new("FUniqID", Int64, false),
Field::new("OriginalURL", Utf8View, false),
Field::new("HID", Int32, false),
Field::new("IsOldCounter", Int16, false),
Field::new("IsEvent", Int16, false),
Field::new("IsParameter", Int16, false),
Field::new("DontCountHits", Int16, false),
Field::new("WithHash", Int16, false),
Field::new("HitColor", Utf8View, false),
Field::new(
"LocalEventTime",
Timestamp(TimeUnit::Microsecond, None),
false,
),
Field::new("Age", Int16, false),
Field::new("Sex", Int16, false),
Field::new("Income", Int16, false),
Field::new("Interests", Int16, false),
Field::new("Robotness", Int16, false),
Field::new("RemoteIP", Int32, false),
Field::new("WindowName", Int32, false),
Field::new("OpenerName", Int32, false),
Field::new("HistoryLength", Int16, false),
Field::new("BrowserLanguage", Utf8View, false),
Field::new("BrowserCountry", Utf8View, false),
Field::new("SocialNetwork", Utf8View, false),
Field::new("SocialAction", Utf8View, false),
Field::new("HTTPError", Int16, false),
Field::new("SendTiming", Int32, false),
Field::new("DNSTiming", Int32, false),
Field::new("ConnectTiming", Int32, false),
Field::new("ResponseStartTiming", Int32, false),
Field::new("ResponseEndTiming", Int32, false),
Field::new("FetchTiming", Int32, false),
Field::new("SocialSourceNetworkID", Int16, false),
Field::new("SocialSourcePage", Utf8View, false),
Field::new("ParamPrice", Int64, false),
Field::new("ParamOrderID", Utf8View, false),
Field::new("ParamCurrency", Utf8View, false),
Field::new("ParamCurrencyID", Int16, false),
Field::new("OpenstatServiceName", Utf8View, false),
Field::new("OpenstatCampaignID", Utf8View, false),
Field::new("OpenstatAdID", Utf8View, false),
Field::new("OpenstatSourceID", Utf8View, false),
Field::new("UTMSource", Utf8View, false),
Field::new("UTMMedium", Utf8View, false),
Field::new("UTMCampaign", Utf8View, false),
Field::new("UTMContent", Utf8View, false),
Field::new("UTMTerm", Utf8View, false),
Field::new("FromTag", Utf8View, false),
Field::new("HasGCLID", Int16, false),
Field::new("RefererHash", Int64, false),
Field::new("URLHash", Int64, false),
Field::new("CLID", Int32, false),
])
});
/// Clickbench has two different flavors:
/// - Singe - 1 file containing the whole dataset, just under 100 million rows.
/// - Partitioned (which we run by default) - 100 files, each containing ~1 million rows, all sharing the same schema.
#[derive(ValueEnum, Default, Clone, Copy, Debug, Hash, PartialEq, Eq, Serialize, Deserialize)]
pub enum Flavor {
#[default]
Partitioned,
Single,
}
impl FromStr for Flavor {
type Err = anyhow::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"partitioned" => Ok(Flavor::Partitioned),
"single" => Ok(Flavor::Single),
_ => anyhow::bail!(
"Failed to parse {s}, only valid flavor values are `partitioned` or `single`"
),
}
}
}
impl Display for Flavor {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
self.to_possible_value()
.vortex_expect("Invalid flavour value")
.get_name()
.to_lowercase()
)
}
}
impl Flavor {
// TODO(joe): move these elsewhere.
pub async fn download(&self, basepath: impl AsRef<Path>) -> anyhow::Result<()> {
let basepath = basepath.as_ref();
match self {
Flavor::Single => {
let output_path = basepath.join(Format::Parquet.name()).join("hits.parquet");
info!("Downloading single clickbench file");
let url = "https://pub-3ba949c0f0354ac18db1f0f14f0a2c52.r2.dev/clickbench/parquet_single/hits.parquet";
download_data(output_path, url).await?;
}
Flavor::Partitioned => {
// The clickbench-provided file is missing some higher-level type info, so we reprocess it
// to add that info, see https://github.com/ClickHouse/ClickBench/issues/7.
let mut tasks = (0_u32..100).map(|idx| {
let output_path = basepath.join(Format::Parquet.name()).join(format!("hits_{idx}.parquet"));
info!("Downloading file {idx}");
let url = format!("https://pub-3ba949c0f0354ac18db1f0f14f0a2c52.r2.dev/clickbench/parquet_many/hits_{idx}.parquet");
download_data(output_path, url)
}).collect::<JoinSet<_>>();
while let Some(task) = tasks.join_next().await {
task??;
}
}
}
Ok(())
}
}