-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathtpch_l_comment.rs
More file actions
123 lines (105 loc) · 3.94 KB
/
Copy pathtpch_l_comment.rs
File metadata and controls
123 lines (105 loc) · 3.94 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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::path::PathBuf;
use anyhow::Result;
use async_trait::async_trait;
use futures::StreamExt;
use futures::TryStreamExt;
use glob::glob;
use vortex::array::ArrayRef;
use vortex::array::Canonical;
use vortex::array::ExecutionCtx;
use vortex::array::IntoArray;
use vortex::array::arrays::ChunkedArray;
use vortex::array::arrays::StructArray;
use vortex::dtype::Nullability::NonNullable;
use vortex::expr::col;
use vortex::expr::pack;
use vortex::file::OpenOptionsSessionExt;
use crate::Format;
use crate::IdempotentPath;
use crate::SESSION;
use crate::datasets::Dataset;
use crate::tpch::tpchgen::TpchGenOptions;
use crate::tpch::tpchgen::generate_tpch_tables;
pub struct TPCHLCommentChunked;
async fn ensure_tpch_parquet() -> Result<PathBuf> {
let base_path = "tpch".to_data_path();
let scale_factor_dir = base_path.join("1.0");
let data_dir = scale_factor_dir.join(Format::Parquet.name());
// Generate TPC-H parquet data if it doesn't exist
if !data_dir.exists() {
let options =
TpchGenOptions::new("1.0".to_string(), scale_factor_dir).with_format(Format::Parquet);
generate_tpch_tables(options).await?;
}
// Return the first lineitem parquet file
let pattern = data_dir.join("lineitem_*.parquet");
glob(pattern.to_string_lossy().as_ref())?
.next()
.ok_or_else(|| anyhow::anyhow!("No lineitem parquet files found"))?
.map_err(Into::into)
}
#[async_trait]
impl Dataset for TPCHLCommentChunked {
fn name(&self) -> &str {
"TPC-H l_comment chunked"
}
async fn to_vortex_array(&self, ctx: &mut ExecutionCtx) -> Result<ArrayRef> {
let base_path = "tpch".to_data_path();
let scale_factor_dir = base_path.join("1.0");
let data_dir = scale_factor_dir.join(Format::OnDiskVortex.name());
// Generate TPC-H CSV data if it doesn't exist
if !data_dir.exists() {
// Use blocking call like TPC-H benchmark does
let options = TpchGenOptions::new("1.0".to_string(), scale_factor_dir)
.with_format(Format::OnDiskVortex);
futures::executor::block_on(generate_tpch_tables(options))?;
}
let mut chunks: Vec<ArrayRef> = vec![];
for path in glob(
data_dir
.join("lineitem_*.vortex")
.to_string_lossy()
.as_ref(),
)? {
let file = SESSION.open_options().open_path(path?).await?;
let file_chunks: Vec<_> = file
.scan()?
.with_projection(pack(vec![("l_comment", col("l_comment"))], NonNullable))
.into_stream()?
.map({
let ctx = ctx.clone();
move |result| {
let mut ctx = ctx.clone();
result.and_then(|a| {
let canonical = a.execute::<Canonical>(&mut ctx)?;
Ok(canonical.into_array())
})
}
})
.try_collect()
.await?;
chunks.extend(file_chunks);
}
Ok(ChunkedArray::from_iter(chunks).into_array())
}
async fn to_parquet_path(&self) -> Result<PathBuf> {
ensure_tpch_parquet().await
}
}
pub struct TPCHLCommentCanonical;
#[async_trait]
impl Dataset for TPCHLCommentCanonical {
fn name(&self) -> &str {
"TPC-H l_comment canonical"
}
async fn to_vortex_array(&self, ctx: &mut ExecutionCtx) -> Result<ArrayRef> {
let comments_chunked = TPCHLCommentChunked.to_vortex_array(ctx).await?;
let comments_canonical = comments_chunked.execute::<StructArray>(ctx)?.into_array();
Ok(ChunkedArray::from_iter([comments_canonical]).into_array())
}
async fn to_parquet_path(&self) -> Result<PathBuf> {
ensure_tpch_parquet().await
}
}