forked from vortex-data/vortex
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdatafusion.rs
More file actions
63 lines (56 loc) · 1.88 KB
/
datafusion.rs
File metadata and controls
63 lines (56 loc) · 1.88 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
#![cfg(feature = "datafusion")]
use datafusion_common::Column;
use datafusion_expr::{BinaryExpr, Expr};
use vortex_dtype::field::{Field, FieldPath};
use vortex_scalar::Scalar;
use crate::expressions::{Predicate, Value};
use crate::operators::Operator;
impl From<Predicate> for Expr {
fn from(value: Predicate) -> Self {
Expr::BinaryExpr(BinaryExpr::new(
Box::new(FieldPathWrapper(value.lhs).into()),
value.op.into(),
Box::new(value.rhs.into()),
))
}
}
impl From<Operator> for datafusion_expr::Operator {
fn from(value: Operator) -> Self {
match value {
Operator::Eq => datafusion_expr::Operator::Eq,
Operator::NotEq => datafusion_expr::Operator::NotEq,
Operator::Gt => datafusion_expr::Operator::Gt,
Operator::Gte => datafusion_expr::Operator::GtEq,
Operator::Lt => datafusion_expr::Operator::Lt,
Operator::Lte => datafusion_expr::Operator::LtEq,
}
}
}
impl From<Value> for Expr {
fn from(value: Value) -> Self {
match value {
Value::Field(field_path) => FieldPathWrapper(field_path).into(),
Value::Literal(literal) => ScalarWrapper(literal).into(),
}
}
}
struct FieldPathWrapper(FieldPath);
impl From<FieldPathWrapper> for Expr {
fn from(value: FieldPathWrapper) -> Self {
let mut field = String::new();
for part in value.0.path() {
match part {
// TODO(ngates): escape quotes?
Field::Name(name) => field.push_str(&format!("\"{}\"", name)),
Field::Index(idx) => field.push_str(&format!("[{}]", idx)),
}
}
Expr::Column(Column::from(field))
}
}
struct ScalarWrapper(Scalar);
impl From<ScalarWrapper> for Expr {
fn from(value: ScalarWrapper) -> Self {
Expr::Literal(value.0.into())
}
}