From 3ebffdae3e07771af27b2f2b0d129c545725fa00 Mon Sep 17 00:00:00 2001 From: Josh Pschorr Date: Wed, 7 Feb 2024 09:53:04 -0800 Subject: [PATCH] Minor cleanup and formatting fixes --- Cargo.toml | 1 + .../src/ast_to_dot.rs | 19 +++++------- .../partiql-extension-visualize/src/common.rs | 2 +- .../src/plan_to_dot.rs | 29 ++++++------------- partiql-eval/src/eval/expr/path.rs | 22 +++++--------- 5 files changed, 26 insertions(+), 47 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 60a53595..8e33e3a1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ homepage = "https://github.com/partiql/partiql-lang-rust" repository = "https://github.com/partiql/partiql-lang-rust" version = "0.6.0" edition = "2021" +resolver = 2 [workspace] diff --git a/extension/partiql-extension-visualize/src/ast_to_dot.rs b/extension/partiql-extension-visualize/src/ast_to_dot.rs index 63b30590..7ae4d67b 100644 --- a/extension/partiql-extension-visualize/src/ast_to_dot.rs +++ b/extension/partiql-extension-visualize/src/ast_to_dot.rs @@ -29,7 +29,7 @@ impl<'d, 'w> ScopeExt<'d, 'w> for Scope<'d, 'w> { fn cluster_auto_labelled(&mut self, lbl: &str) -> Scope<'_, 'w> { let mut cluster = self.cluster(); - cluster.set("label", lbl, lbl.contains(" ")); + cluster.set("label", lbl, lbl.contains(' ')); cluster } @@ -49,7 +49,7 @@ trait ChildEdgeExt { impl ChildEdgeExt for Targets { fn edges(self, out: &mut Scope, from: &NodeId, lbl: &str) -> Targets { for target in &self { - out.edge(&from, &target).attributes().set_label(lbl); + out.edge(from, target).attributes().set_label(lbl); } self } @@ -57,14 +57,9 @@ impl ChildEdgeExt for Targets { type Targets = Vec; +#[derive(Default)] pub struct AstToDot {} -impl Default for AstToDot { - fn default() -> Self { - AstToDot {} - } -} - impl ToDotGraph for AstToDot where AstToDot: ToDot, @@ -96,7 +91,7 @@ where self.to_dot(&mut digraph, ast); } - return String::from_utf8(output_bytes).expect("invalid utf8"); + String::from_utf8(output_bytes).expect("invalid utf8") } } @@ -120,7 +115,7 @@ where fn to_dot(&mut self, out: &mut Scope, asts: &Vec) -> Targets { let mut res = Vec::with_capacity(asts.len()); for ast in asts { - res.extend(self.to_dot(out, &ast)); + res.extend(self.to_dot(out, ast)); } res } @@ -133,7 +128,7 @@ where fn to_dot(&mut self, out: &mut Scope, ast: &Option) -> Targets { match ast { None => vec![], - Some(ast) => self.to_dot(out, &ast), + Some(ast) => self.to_dot(out, ast), } } } @@ -455,7 +450,7 @@ fn symbol_primitive_to_label(sym: &ast::SymbolPrimitive) -> String { use ast::CaseSensitivity; match &sym.case { CaseSensitivity::CaseSensitive => format!("'{}'", sym.value), - CaseSensitivity::CaseInsensitive => format!("{}", sym.value), + CaseSensitivity::CaseInsensitive => sym.value.to_string(), } } diff --git a/extension/partiql-extension-visualize/src/common.rs b/extension/partiql-extension-visualize/src/common.rs index 1a79bc27..637dc12e 100644 --- a/extension/partiql-extension-visualize/src/common.rs +++ b/extension/partiql-extension-visualize/src/common.rs @@ -3,4 +3,4 @@ pub trait ToDotGraph { } #[cfg(feature = "visualize-dot")] -pub(crate) const FG_COLOR: &'static str = "\"#839496\""; +pub(crate) const FG_COLOR: &str = "\"#839496\""; diff --git a/extension/partiql-extension-visualize/src/plan_to_dot.rs b/extension/partiql-extension-visualize/src/plan_to_dot.rs index 4090acb1..5bc6beac 100644 --- a/extension/partiql-extension-visualize/src/plan_to_dot.rs +++ b/extension/partiql-extension-visualize/src/plan_to_dot.rs @@ -8,14 +8,9 @@ use std::collections::HashMap; use crate::common::{ToDotGraph, FG_COLOR}; +#[derive(Default)] pub struct PlanToDot {} -impl Default for PlanToDot { - fn default() -> Self { - PlanToDot {} - } -} - impl PlanToDot { pub(crate) fn to_dot(&self, scope: &mut Scope, plan: &LogicalPlan) { let mut graph_nodes = HashMap::new(); @@ -71,10 +66,10 @@ impl PlanToDot { let clauses = [ lo.limit .as_ref() - .map(|e| format!("limit {}", expr_to_str(&e))), + .map(|e| format!("limit {}", expr_to_str(e))), lo.offset .as_ref() - .map(|e| format!("offset {}", expr_to_str(&e))), + .map(|e| format!("offset {}", expr_to_str(e))), ] .iter() .filter_map(|o| o.as_ref()) @@ -92,10 +87,7 @@ impl PlanToDot { format!( "{{ {} join | {} }}", kind, - join.on - .as_ref() - .map(|e| expr_to_str(e)) - .unwrap_or("".to_string()) + join.on.as_ref().map(expr_to_str).unwrap_or("".to_string()) ) } BindingsOp::BagOp(_) => "bag op (TODO)".to_string(), @@ -108,9 +100,7 @@ impl PlanToDot { .join(" | "), ) } - BindingsOp::ProjectAll => { - format!("{{project * }}") - } + BindingsOp::ProjectAll => "{project * }".to_string(), BindingsOp::ProjectValue(pv) => { format!("{{project value | {} }}", expr_to_str(&pv.expr)) } @@ -135,8 +125,7 @@ impl PlanToDot { } BindingsOp::Sink => "sink".to_string(), }; - node.set_shape(Shape::Mrecord) - .set_label(&format!("{label}")); + node.set_shape(Shape::Mrecord).set_label(&label.to_string()); node.id() } @@ -163,8 +152,8 @@ fn expr_to_str(expr: &ValueExpr) -> String { let expr = expr.replace('{', "\\{"); let expr = expr.replace('}', "\\}"); let expr = expr.replace('<', "\\<"); - let expr = expr.replace('>', "\\>"); - expr + + expr.replace('>', "\\>") } } } @@ -206,6 +195,6 @@ impl ToDotGraph> for PlanToDot { self.to_dot(&mut digraph, plan); } - return String::from_utf8(output_bytes).expect("invalid utf8"); + String::from_utf8(output_bytes).expect("invalid utf8") } } diff --git a/partiql-eval/src/eval/expr/path.rs b/partiql-eval/src/eval/expr/path.rs index c46d8261..da6acf1f 100644 --- a/partiql-eval/src/eval/expr/path.rs +++ b/partiql-eval/src/eval/expr/path.rs @@ -118,22 +118,16 @@ impl EvalPathComponent { impl EvalExpr for EvalPath { fn evaluate<'a>(&'a self, bindings: &'a Tuple, ctx: &'a dyn EvalContext) -> Cow<'a, Value> { let value = self.expr.evaluate(bindings, ctx); + let mut path_componenents = self.components.iter(); match value { - Cow::Borrowed(borrowed) => self - .components - .iter() - .fold(Some(borrowed), |v, path| { - v.and_then(|v| path.get_val(v, bindings, ctx)) - }) - .map_or_else(|| Cow::Owned(Value::Missing), Cow::Borrowed), - Cow::Owned(owned) => self - .components - .iter() - .fold(Some(owned), |v, path| { - v.and_then(|v| path.take_val(v, bindings, ctx)) - }) - .map_or_else(|| Cow::Owned(Value::Missing), Cow::Owned), + Cow::Borrowed(borrowed) => path_componenents + .try_fold(borrowed, |v, path| path.get_val(v, bindings, ctx)) + .map(Cow::Borrowed), + Cow::Owned(owned) => path_componenents + .try_fold(owned, |v, path| path.take_val(v, bindings, ctx)) + .map(Cow::Owned), } + .unwrap_or_else(|| Cow::Owned(Value::Missing)) } }