Skip to content

Commit a9411ec

Browse files
committed
use scanbuilder::new
Signed-off-by: Mikhail Kot <mikhail@spiraldb.com>
1 parent 70be73c commit a9411ec

3 files changed

Lines changed: 14 additions & 20 deletions

File tree

vortex-bench/src/random_access/take.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ use vortex::array::VortexSessionExecute;
2424
use vortex::array::stream::ArrayStreamExt;
2525
use vortex::buffer::Buffer;
2626
use vortex::file::OpenOptionsSessionExt;
27-
use vortex::file::VortexFile;
27+
use vortex::layout::LayoutReader;
28+
use vortex::layout::scan::scan_builder::ScanBuilder;
2829
use vortex::utils::aliases::hash_map::HashMap;
2930

3031
use crate::Format;
@@ -38,7 +39,7 @@ use crate::random_access::RandomAccessorRet;
3839
pub struct VortexRandomAccessor {
3940
name: String,
4041
format: Format,
41-
file: VortexFile,
42+
reader: Arc<dyn LayoutReader>,
4243
}
4344

4445
impl VortexRandomAccessor {
@@ -49,10 +50,11 @@ impl VortexRandomAccessor {
4950
format: Format,
5051
) -> anyhow::Result<Self> {
5152
let file = SESSION.open_options().open_path(path.as_ref()).await?;
53+
let reader = file.layout_reader()?;
5254
Ok(Self {
5355
name: name.into(),
5456
format,
55-
file,
57+
reader,
5658
})
5759
}
5860
}
@@ -69,9 +71,8 @@ impl RandomAccessor for VortexRandomAccessor {
6971

7072
async fn take(&self, indices: &[u64]) -> anyhow::Result<RandomAccessorRet> {
7173
let indices_buf: Buffer<u64> = Buffer::from(indices.to_vec());
72-
let array = self
73-
.file
74-
.scan()?
74+
let reader = ScanBuilder::new(SESSION.clone(), self.reader.clone());
75+
let array = reader
7576
.with_row_indices(indices_buf)
7677
.into_array_stream()?
7778
.read_all()

vortex-layout/src/layouts/row_idx/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use vortex_array::dtype::FieldMask;
2424
use vortex_array::dtype::FieldName;
2525
use vortex_array::dtype::Nullability;
2626
use vortex_array::dtype::PType;
27-
use vortex_array::expr::ExactExpr;
2827
use vortex_array::expr::Expression;
2928
use vortex_array::expr::is_root;
3029
use vortex_array::expr::root;
@@ -50,7 +49,7 @@ pub struct RowIdxLayoutReader {
5049
name: Arc<str>,
5150
row_offset: u64,
5251
child: Arc<dyn LayoutReader>,
53-
partition_cache: DashMap<ExactExpr, Arc<OnceLock<Partitioning>>>,
52+
partition_cache: DashMap<Expression, Arc<OnceLock<Partitioning>>>,
5453
session: VortexSession,
5554
}
5655

@@ -66,10 +65,7 @@ impl RowIdxLayoutReader {
6665
}
6766

6867
fn partition_expr(&self, expr: &Expression) -> VortexResult<Partitioning> {
69-
let key = ExactExpr(expr.clone());
70-
71-
// Check cache first with read-only lock.
72-
if let Some(entry) = self.partition_cache.get(&key)
68+
if let Some(entry) = self.partition_cache.get(&expr)
7369
&& let Some(partitioning) = entry.value().get()
7470
{
7571
return Ok(partitioning.clone());
@@ -78,7 +74,7 @@ impl RowIdxLayoutReader {
7874
let result = self.compute_partitioning(expr)?;
7975

8076
self.partition_cache
81-
.entry(key)
77+
.entry(expr.clone())
8278
.or_insert_with(|| Arc::new(OnceLock::new()))
8379
.get_or_init(|| result.clone());
8480

vortex-layout/src/layouts/struct_/reader.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use vortex_array::dtype::FieldMask;
1919
use vortex_array::dtype::FieldName;
2020
use vortex_array::dtype::Nullability;
2121
use vortex_array::dtype::StructFields;
22-
use vortex_array::expr::ExactExpr;
2322
use vortex_array::expr::Expression;
2423
use vortex_array::expr::col;
2524
use vortex_array::expr::make_free_field_annotator;
@@ -59,7 +58,7 @@ pub struct StructReader {
5958
expanded_root_expr: Expression,
6059

6160
field_lookup: Option<HashMap<FieldName, usize>>,
62-
partitioned_expr_cache: DashMap<ExactExpr, Arc<OnceLock<Partitioned>>>,
61+
partitioned_expr_cache: DashMap<Expression, Arc<OnceLock<Partitioned>>>,
6362
}
6463

6564
impl StructReader {
@@ -154,18 +153,16 @@ impl StructReader {
154153

155154
/// Utility for partitioning an expression over the fields of a struct.
156155
fn partition_expr(&self, expr: Expression) -> VortexResult<Partitioned> {
157-
let key = ExactExpr(expr.clone());
158-
159-
if let Some(entry) = self.partitioned_expr_cache.get(&key)
156+
if let Some(entry) = self.partitioned_expr_cache.get(&expr)
160157
&& let Some(partitioning) = entry.value().get()
161158
{
162159
return Ok(partitioning.clone());
163160
}
164161

165-
let result = self.compute_partitioned_expr(expr)?;
162+
let result = self.compute_partitioned_expr(expr.clone())?;
166163

167164
self.partitioned_expr_cache
168-
.entry(key)
165+
.entry(expr)
169166
.or_insert_with(|| Arc::new(OnceLock::new()))
170167
.get_or_init(|| result.clone());
171168

0 commit comments

Comments
 (0)