1
1
use partiql_ast_passes:: error:: AstTransformationError ;
2
2
use partiql_eval as eval;
3
+ use std:: ops:: Deref ;
3
4
4
5
use partiql_eval:: error:: { EvalErr , PlanErr } ;
5
6
use partiql_eval:: eval:: { BasicContext , EvalContext , EvalPlan , EvalResult , Evaluated } ;
6
7
use partiql_logical as logical;
7
8
use partiql_parser:: { Parsed , ParserError , ParserResult } ;
8
9
use partiql_value:: DateTime ;
9
10
10
- use partiql_catalog:: catalog:: { Catalog , PartiqlCatalog } ;
11
+ use partiql_catalog:: catalog:: { PartiqlCatalog , PartiqlSharedCatalog , SharedCatalog } ;
11
12
use partiql_catalog:: context:: SystemContext ;
12
13
use thiserror:: Error ;
13
14
14
15
mod test_value;
15
16
pub ( crate ) use test_value:: TestValue ;
16
17
18
+ use once_cell:: sync:: Lazy ;
19
+ pub ( crate ) static SHARED_CATALOG : Lazy < PartiqlSharedCatalog > = Lazy :: new ( init_shared_catalog) ;
20
+
21
+ fn init_shared_catalog ( ) -> PartiqlSharedCatalog {
22
+ PartiqlCatalog :: default ( ) . to_shared_catalog ( )
23
+ }
24
+
17
25
#[ derive( Debug , Copy , Clone ) ]
18
26
#[ allow( dead_code) ]
19
27
pub ( crate ) enum EvaluationMode {
@@ -52,7 +60,7 @@ pub(crate) fn parse(statement: &str) -> ParserResult {
52
60
#[ track_caller]
53
61
#[ inline]
54
62
pub ( crate ) fn lower (
55
- catalog : & dyn Catalog ,
63
+ catalog : & dyn SharedCatalog ,
56
64
parsed : & Parsed < ' _ > ,
57
65
) -> Result < logical:: LogicalPlan < logical:: BindingsOp > , AstTransformationError > {
58
66
let planner = partiql_logical_planner:: LogicalPlanner :: new ( catalog) ;
@@ -63,7 +71,7 @@ pub(crate) fn lower(
63
71
#[ inline]
64
72
pub ( crate ) fn compile (
65
73
mode : EvaluationMode ,
66
- catalog : & dyn Catalog ,
74
+ catalog : & dyn SharedCatalog ,
67
75
logical : logical:: LogicalPlan < logical:: BindingsOp > ,
68
76
) -> Result < EvalPlan , PlanErr > {
69
77
let mut planner = eval:: plan:: EvaluatorPlanner :: new ( mode. into ( ) , catalog) ;
@@ -103,9 +111,9 @@ pub(crate) fn pass_syntax(statement: &str) -> Parsed {
103
111
#[ inline]
104
112
#[ allow( dead_code) ]
105
113
pub ( crate ) fn fail_semantics ( statement : & str ) {
106
- let catalog = PartiqlCatalog :: default ( ) ;
114
+ let catalog: & PartiqlSharedCatalog = SHARED_CATALOG . deref ( ) ;
107
115
if let Ok ( parsed) = parse ( statement) {
108
- let lowered = lower ( & catalog, & parsed) ;
116
+ let lowered = lower ( catalog, & parsed) ;
109
117
110
118
assert ! (
111
119
lowered. is_err( ) ,
@@ -118,9 +126,9 @@ pub(crate) fn fail_semantics(statement: &str) {
118
126
#[ inline]
119
127
#[ allow( dead_code) ]
120
128
pub ( crate ) fn pass_semantics ( statement : & str ) {
121
- let catalog = PartiqlCatalog :: default ( ) ;
129
+ let catalog: & PartiqlSharedCatalog = SHARED_CATALOG . deref ( ) ;
122
130
let parsed = pass_syntax ( statement) ;
123
- let lowered = lower ( & catalog, & parsed) ;
131
+ let lowered = lower ( catalog, & parsed) ;
124
132
assert ! (
125
133
lowered. is_ok( ) ,
126
134
"When semantically verifying `{statement}`, expected `Ok(_)`, but was `{lowered:#?}`"
@@ -171,17 +179,17 @@ pub(crate) fn eval<'a>(
171
179
mode : EvaluationMode ,
172
180
env : & Option < TestValue > ,
173
181
) -> Result < Evaluated , TestError < ' a > > {
174
- let catalog = PartiqlCatalog :: default ( ) ;
182
+ let catalog: & PartiqlSharedCatalog = SHARED_CATALOG . deref ( ) ;
175
183
176
184
let parsed = parse ( statement) ?;
177
- let lowered = lower ( & catalog, & parsed) ?;
185
+ let lowered = lower ( catalog, & parsed) ?;
178
186
179
187
let bindings = env. as_ref ( ) . map ( |e| ( & e. value ) . into ( ) ) . unwrap_or_default ( ) ;
180
188
let sys = SystemContext {
181
189
now : DateTime :: from_system_now_utc ( ) ,
182
190
} ;
183
191
let ctx = BasicContext :: new ( bindings, sys) ;
184
- let plan = compile ( mode, & catalog, lowered) ?;
192
+ let plan = compile ( mode, catalog, lowered) ?;
185
193
186
194
Ok ( evaluate ( plan, & ctx) ?)
187
195
}
0 commit comments