Skip to content

Commit d8b806b

Browse files
peaseegatesn
authored andcommitted
feat: Support retrieving WriterStrategyBuilder from VortexSession (#6)
* Fix session get-or-default (vortex-data#5662) The comments described this get-or-default, but instead it was a panic --------- Signed-off-by: Nicholas Gates <nick@nickgates.com> * feat: Support retrieving writer strategy builder from vortex session --------- Signed-off-by: Nicholas Gates <nick@nickgates.com> Co-authored-by: Nicholas Gates <gatesn@users.noreply.github.com>
1 parent 8044a84 commit d8b806b

1 file changed

Lines changed: 5 additions & 23 deletions

File tree

vortex-session/src/lib.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,14 @@
33

44
pub mod registry;
55

6-
use std::any::Any;
7-
use std::any::TypeId;
8-
use std::any::type_name;
6+
use std::any::{Any, TypeId, type_name};
97
use std::fmt::Debug;
10-
use std::hash::BuildHasherDefault;
11-
use std::hash::Hasher;
12-
use std::ops::Deref;
13-
use std::ops::DerefMut;
8+
use std::hash::{BuildHasherDefault, Hasher};
9+
use std::ops::{Deref, DerefMut};
1410
use std::sync::Arc;
1511

16-
use dashmap::DashMap;
17-
use dashmap::Entry;
18-
use vortex_error::VortexExpect;
19-
use vortex_error::vortex_panic;
12+
use dashmap::{DashMap, Entry};
13+
use vortex_error::{VortexExpect, vortex_panic};
2014

2115
/// A Vortex session encapsulates the set of extensible arrays, layouts, compute functions, dtypes,
2216
/// etc. that are available for use in a given context.
@@ -108,18 +102,6 @@ impl SessionExt for VortexSession {
108102

109103
/// Returns the scope variable of type `V`, or inserts a default one if it does not exist.
110104
fn get<V: SessionVar + Default>(&self) -> Ref<'_, V> {
111-
// NOTE(ngates): we don't use `entry().or_insert_with_key()` here because the DashMap
112-
// would immediately acquire an exclusive write lock.
113-
if let Some(v) = self.0.get(&TypeId::of::<V>()) {
114-
return Ref(v.map(|v| {
115-
(**v)
116-
.as_any()
117-
.downcast_ref::<V>()
118-
.vortex_expect("Type mismatch - this is a bug")
119-
}));
120-
}
121-
122-
// If we get here, the value was not present, so we insert the default with a write lock.
123105
Ref(self
124106
.0
125107
.entry(TypeId::of::<V>())

0 commit comments

Comments
 (0)