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
use crate::eval::expr::EvalExpr;
use crate::eval::EvalContext;
use itertools::Itertools;
use partiql_catalog::table_fn::BaseTableExpr;
use partiql_value::Value::Missing;
use partiql_value::{Bag, Value};
use partiql_catalog::extension::ExtensionResultError;
use partiql_value::datum::RefTupleView;
use std::borrow::Cow;
use std::fmt::Debug;
/// Represents a Base Table Expr
#[derive(Debug)]
pub(crate) struct EvalFnBaseTableExpr {
pub(crate) args: Vec<Box<dyn EvalExpr>>,
pub(crate) expr: Box<dyn BaseTableExpr>,
}
impl EvalExpr for EvalFnBaseTableExpr {
#[inline]
fn evaluate<'a, 'c, 'o>(
&'a self,
bindings: &'a dyn RefTupleView<'a, Value>,
ctx: &'c dyn EvalContext,
) -> Cow<'o, Value>
where
'c: 'a,
'a: 'o,
{
let args = self
.args
.iter()
.map(|arg| arg.evaluate(bindings, ctx))
.collect_vec();
let results = self.expr.evaluate(&args, ctx);
let result = match results {
Ok(it) => {
let bag: Result<Bag, _> = it
.map(|r| {
match r {
Ok(v) => Ok(v),
Err(err) => match err {
err @ ExtensionResultError::DataError(_) => {
ctx.add_error(err.into());
// This is an error for this data item; coerce it to `Missing` and continue
Ok(Missing)
}
err => Err(err),
},
}
})
.collect();
match bag {
Ok(bag) => Value::from(bag),
Err(err) => {
// Error on read and/or stream; Treat whole stream as `Missing`
ctx.add_error(err.into());
Missing
}
}
}
Err(err) => {
// Error on read and/or stream; Treat whole stream as `Missing`
ctx.add_error(err.into());
Missing
}
};
Cow::Owned(result)
}
}