-
Notifications
You must be signed in to change notification settings - Fork 145
Expand file tree
/
Copy pathsession.rs
More file actions
84 lines (73 loc) · 2.55 KB
/
session.rs
File metadata and controls
84 lines (73 loc) · 2.55 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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright the Vortex contributors
use std::sync::Arc;
use vortex_session::Ref;
use vortex_session::SessionExt;
use vortex_session::registry::Registry;
use crate::scalar_fn::ScalarFnPluginRef;
use crate::scalar_fn::ScalarFnVTable;
use crate::scalar_fn::fns::between::Between;
use crate::scalar_fn::fns::binary::Binary;
use crate::scalar_fn::fns::cast::Cast;
use crate::scalar_fn::fns::fill_null::FillNull;
use crate::scalar_fn::fns::get_item::GetItem;
use crate::scalar_fn::fns::is_not_null::IsNotNull;
use crate::scalar_fn::fns::is_null::IsNull;
use crate::scalar_fn::fns::like::Like;
use crate::scalar_fn::fns::list_contains::ListContains;
use crate::scalar_fn::fns::literal::Literal;
use crate::scalar_fn::fns::merge::Merge;
use crate::scalar_fn::fns::not::Not;
use crate::scalar_fn::fns::pack::Pack;
use crate::scalar_fn::fns::root::Root;
use crate::scalar_fn::fns::select::Select;
/// Registry of scalar function vtables.
/// Registry of scalar function vtables.
pub type ScalarFnRegistry = Registry<ScalarFnPluginRef>;
/// Session state for scalar function vtables and rewrite rules.
#[derive(Debug)]
pub struct ScalarFnSession {
registry: ScalarFnRegistry,
}
impl ScalarFnSession {
pub fn registry(&self) -> &ScalarFnRegistry {
&self.registry
}
/// Register a scalar function vtable in the session, replacing any existing vtable with the same ID.
pub fn register<V: ScalarFnVTable>(&self, vtable: V) {
self.registry
.register(vtable.id(), Arc::new(vtable) as ScalarFnPluginRef);
}
}
impl Default for ScalarFnSession {
fn default() -> Self {
let this = Self {
registry: ScalarFnRegistry::default(),
};
// Register built-in expressions.
this.register(Between);
this.register(Binary);
this.register(Cast);
this.register(FillNull);
this.register(GetItem);
this.register(IsNotNull);
this.register(IsNull);
this.register(Like);
this.register(ListContains);
this.register(Literal);
this.register(Merge);
this.register(Not);
this.register(Pack);
this.register(Root);
this.register(Select);
this
}
}
/// Extension trait for accessing scalar function session data.
pub trait ScalarFnSessionExt: SessionExt {
/// Returns the scalar function vtable registry.
fn scalar_fns(&self) -> Ref<'_, ScalarFnSession> {
self.get::<ScalarFnSession>()
}
}
impl<S: SessionExt> ScalarFnSessionExt for S {}