Skip to content

Commit 00924f2

Browse files
authored
Minor cleanup and formatting fixes (#445)
1 parent 05d3fc8 commit 00924f2

File tree

5 files changed

+26
-47
lines changed

5 files changed

+26
-47
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ homepage = "https://github.com/partiql/partiql-lang-rust"
44
repository = "https://github.com/partiql/partiql-lang-rust"
55
version = "0.6.0"
66
edition = "2021"
7+
resolver = 2
78

89
[workspace]
910

extension/partiql-extension-visualize/src/ast_to_dot.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'d, 'w> ScopeExt<'d, 'w> for Scope<'d, 'w> {
2929

3030
fn cluster_auto_labelled(&mut self, lbl: &str) -> Scope<'_, 'w> {
3131
let mut cluster = self.cluster();
32-
cluster.set("label", lbl, lbl.contains(" "));
32+
cluster.set("label", lbl, lbl.contains(' '));
3333
cluster
3434
}
3535

@@ -49,22 +49,17 @@ trait ChildEdgeExt {
4949
impl ChildEdgeExt for Targets {
5050
fn edges(self, out: &mut Scope, from: &NodeId, lbl: &str) -> Targets {
5151
for target in &self {
52-
out.edge(&from, &target).attributes().set_label(lbl);
52+
out.edge(from, target).attributes().set_label(lbl);
5353
}
5454
self
5555
}
5656
}
5757

5858
type Targets = Vec<NodeId>;
5959

60+
#[derive(Default)]
6061
pub struct AstToDot {}
6162

62-
impl Default for AstToDot {
63-
fn default() -> Self {
64-
AstToDot {}
65-
}
66-
}
67-
6863
impl<T> ToDotGraph<T> for AstToDot
6964
where
7065
AstToDot: ToDot<T>,
@@ -96,7 +91,7 @@ where
9691
self.to_dot(&mut digraph, ast);
9792
}
9893

99-
return String::from_utf8(output_bytes).expect("invalid utf8");
94+
String::from_utf8(output_bytes).expect("invalid utf8")
10095
}
10196
}
10297

@@ -120,7 +115,7 @@ where
120115
fn to_dot(&mut self, out: &mut Scope, asts: &Vec<T>) -> Targets {
121116
let mut res = Vec::with_capacity(asts.len());
122117
for ast in asts {
123-
res.extend(self.to_dot(out, &ast));
118+
res.extend(self.to_dot(out, ast));
124119
}
125120
res
126121
}
@@ -133,7 +128,7 @@ where
133128
fn to_dot(&mut self, out: &mut Scope, ast: &Option<T>) -> Targets {
134129
match ast {
135130
None => vec![],
136-
Some(ast) => self.to_dot(out, &ast),
131+
Some(ast) => self.to_dot(out, ast),
137132
}
138133
}
139134
}
@@ -455,7 +450,7 @@ fn symbol_primitive_to_label(sym: &ast::SymbolPrimitive) -> String {
455450
use ast::CaseSensitivity;
456451
match &sym.case {
457452
CaseSensitivity::CaseSensitive => format!("'{}'", sym.value),
458-
CaseSensitivity::CaseInsensitive => format!("{}", sym.value),
453+
CaseSensitivity::CaseInsensitive => sym.value.to_string(),
459454
}
460455
}
461456

extension/partiql-extension-visualize/src/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ pub trait ToDotGraph<T> {
33
}
44

55
#[cfg(feature = "visualize-dot")]
6-
pub(crate) const FG_COLOR: &'static str = "\"#839496\"";
6+
pub(crate) const FG_COLOR: &str = "\"#839496\"";

extension/partiql-extension-visualize/src/plan_to_dot.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,9 @@ use std::collections::HashMap;
88

99
use crate::common::{ToDotGraph, FG_COLOR};
1010

11+
#[derive(Default)]
1112
pub struct PlanToDot {}
1213

13-
impl Default for PlanToDot {
14-
fn default() -> Self {
15-
PlanToDot {}
16-
}
17-
}
18-
1914
impl PlanToDot {
2015
pub(crate) fn to_dot(&self, scope: &mut Scope, plan: &LogicalPlan<BindingsOp>) {
2116
let mut graph_nodes = HashMap::new();
@@ -71,10 +66,10 @@ impl PlanToDot {
7166
let clauses = [
7267
lo.limit
7368
.as_ref()
74-
.map(|e| format!("limit {}", expr_to_str(&e))),
69+
.map(|e| format!("limit {}", expr_to_str(e))),
7570
lo.offset
7671
.as_ref()
77-
.map(|e| format!("offset {}", expr_to_str(&e))),
72+
.map(|e| format!("offset {}", expr_to_str(e))),
7873
]
7974
.iter()
8075
.filter_map(|o| o.as_ref())
@@ -92,10 +87,7 @@ impl PlanToDot {
9287
format!(
9388
"{{ {} join | {} }}",
9489
kind,
95-
join.on
96-
.as_ref()
97-
.map(|e| expr_to_str(e))
98-
.unwrap_or("".to_string())
90+
join.on.as_ref().map(expr_to_str).unwrap_or("".to_string())
9991
)
10092
}
10193
BindingsOp::BagOp(_) => "bag op (TODO)".to_string(),
@@ -108,9 +100,7 @@ impl PlanToDot {
108100
.join(" | "),
109101
)
110102
}
111-
BindingsOp::ProjectAll => {
112-
format!("{{project * }}")
113-
}
103+
BindingsOp::ProjectAll => "{project * }".to_string(),
114104
BindingsOp::ProjectValue(pv) => {
115105
format!("{{project value | {} }}", expr_to_str(&pv.expr))
116106
}
@@ -135,8 +125,7 @@ impl PlanToDot {
135125
}
136126
BindingsOp::Sink => "sink".to_string(),
137127
};
138-
node.set_shape(Shape::Mrecord)
139-
.set_label(&format!("{label}"));
128+
node.set_shape(Shape::Mrecord).set_label(&label.to_string());
140129

141130
node.id()
142131
}
@@ -163,8 +152,8 @@ fn expr_to_str(expr: &ValueExpr) -> String {
163152
let expr = expr.replace('{', "\\{");
164153
let expr = expr.replace('}', "\\}");
165154
let expr = expr.replace('<', "\\<");
166-
let expr = expr.replace('>', "\\>");
167-
expr
155+
156+
expr.replace('>', "\\>")
168157
}
169158
}
170159
}
@@ -206,6 +195,6 @@ impl ToDotGraph<LogicalPlan<BindingsOp>> for PlanToDot {
206195
self.to_dot(&mut digraph, plan);
207196
}
208197

209-
return String::from_utf8(output_bytes).expect("invalid utf8");
198+
String::from_utf8(output_bytes).expect("invalid utf8")
210199
}
211200
}

partiql-eval/src/eval/expr/path.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,16 @@ impl EvalPathComponent {
118118
impl EvalExpr for EvalPath {
119119
fn evaluate<'a>(&'a self, bindings: &'a Tuple, ctx: &'a dyn EvalContext) -> Cow<'a, Value> {
120120
let value = self.expr.evaluate(bindings, ctx);
121+
let mut path_componenents = self.components.iter();
121122
match value {
122-
Cow::Borrowed(borrowed) => self
123-
.components
124-
.iter()
125-
.fold(Some(borrowed), |v, path| {
126-
v.and_then(|v| path.get_val(v, bindings, ctx))
127-
})
128-
.map_or_else(|| Cow::Owned(Value::Missing), Cow::Borrowed),
129-
Cow::Owned(owned) => self
130-
.components
131-
.iter()
132-
.fold(Some(owned), |v, path| {
133-
v.and_then(|v| path.take_val(v, bindings, ctx))
134-
})
135-
.map_or_else(|| Cow::Owned(Value::Missing), Cow::Owned),
123+
Cow::Borrowed(borrowed) => path_componenents
124+
.try_fold(borrowed, |v, path| path.get_val(v, bindings, ctx))
125+
.map(Cow::Borrowed),
126+
Cow::Owned(owned) => path_componenents
127+
.try_fold(owned, |v, path| path.take_val(v, bindings, ctx))
128+
.map(Cow::Owned),
136129
}
130+
.unwrap_or_else(|| Cow::Owned(Value::Missing))
137131
}
138132
}
139133

0 commit comments

Comments
 (0)