-
Notifications
You must be signed in to change notification settings - Fork 203
Expand file tree
/
Copy pathsession.rs
More file actions
80 lines (65 loc) · 1.99 KB
/
Copy pathsession.rs
File metadata and controls
80 lines (65 loc) · 1.99 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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
//! Module for managing extension dtypes in a Vortex session.
use std::any::Any;
use std::sync::Arc;
use vortex_session::ArcSwapMap;
use vortex_session::SessionExt;
use vortex_session::SessionGuard;
use vortex_session::SessionVar;
use vortex_session::registry::Id;
use crate::dtype::extension::ExtDTypePluginRef;
use crate::dtype::extension::ExtVTable;
use crate::extension::datetime::Date;
use crate::extension::datetime::Time;
use crate::extension::datetime::Timestamp;
use crate::extension::uuid::Uuid;
/// Registry for extension dtypes.
pub type ExtDTypeRegistry = ArcSwapMap<Id, ExtDTypePluginRef>;
/// Session for managing extension dtypes.
#[derive(Clone, Debug)]
pub struct DTypeSession {
registry: ExtDTypeRegistry,
}
impl Default for DTypeSession {
fn default() -> Self {
let this = Self {
registry: ExtDTypeRegistry::default(),
};
// Register built-in temporal extension dtypes
this.register(Date);
this.register(Time);
this.register(Timestamp);
this.register(Uuid);
this
}
}
impl SessionVar for DTypeSession {
fn as_any(&self) -> &dyn Any {
self
}
fn as_any_mut(&mut self) -> &mut dyn Any {
self
}
}
impl DTypeSession {
/// Register an extension DType with the Vortex session.
pub fn register<V: ExtVTable>(&self, vtable: V) {
self.registry
.insert(vtable.id(), Arc::new(vtable) as ExtDTypePluginRef);
}
/// Return the registry of extension dtypes.
pub fn registry(&self) -> &ExtDTypeRegistry {
&self.registry
}
}
/// Extension trait for accessing the DType session.
pub trait DTypeSessionExt: SessionExt {
/// Get the DType session.
fn dtypes(&self) -> SessionGuard<'_, DTypeSession>;
}
impl<S: SessionExt> DTypeSessionExt for S {
fn dtypes(&self) -> SessionGuard<'_, DTypeSession> {
self.get::<DTypeSession>()
}
}