From 4918820818c5d1f28ac22eb0865d9f4b088d0026 Mon Sep 17 00:00:00 2001 From: Josh Pschorr Date: Wed, 6 Mar 2024 15:09:27 -0800 Subject: [PATCH] Clean-up and add changelog entries --- CHANGELOG.md | 2 ++ partiql-eval/src/eval/mod.rs | 8 ++++---- partiql/tests/user_context.rs | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8787f29a..4e214c08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Changed - Adds quotes to the attributes of PartiQL tuple's debug output so it can be read and transformed using Kotlin `partiql-cli` +- Changes the interface to `EvalPlan` to accept an `EvalContext` ### Added - Add `partiql-extension-visualize` for visualizing AST and logical plan +- Add a `SessionContext` containing both a system-level and a user-level context object usable by expression evaluation ### Fixed - Fixed `ORDER BY`'s ability to see into projection aliases diff --git a/partiql-eval/src/eval/mod.rs b/partiql-eval/src/eval/mod.rs index 6463fa1a..c12794c8 100644 --- a/partiql-eval/src/eval/mod.rs +++ b/partiql-eval/src/eval/mod.rs @@ -20,6 +20,7 @@ use petgraph::graph::NodeIndex; use crate::error::{EvalErr, EvaluationError}; use partiql_catalog::context::{Bindings, SessionContext, SystemContext}; use petgraph::visit::EdgeRef; +use unicase::UniCase; use crate::eval::evaluable::{EvalType, Evaluable}; @@ -66,8 +67,6 @@ impl EvalPlan { /// Executes the plan while mutating its state by changing the inputs and outputs of plan /// operators. pub fn execute_mut<'c>(&mut self, ctx: &'c dyn EvalContext<'c>) -> Result { - //let ctx: Box = Box::new(BasicContext::new(bindings)); - // We are only interested in DAGs that can be used as execution plans, which leads to the // following definition. // A DAG is a directed, cycle-free graph G = (V, E) with a denoted root node v0 ∈ V such @@ -157,7 +156,7 @@ pub struct BasicContext<'a> { pub bindings: MapBindings, pub sys: SystemContext, - pub user: HashMap, // TODO: Unicase the keys? + pub user: HashMap, &'a (dyn Any)>, pub errors: RefCell>, } @@ -182,7 +181,8 @@ impl<'a> SessionContext<'a> for BasicContext<'a> { } fn user_context(&self, name: &str) -> Option<&(dyn Any)> { - self.user.get(name).copied() + let key = name.into(); + self.user.get(&key).copied() } } impl<'a> EvalContext<'a> for BasicContext<'a> { diff --git a/partiql/tests/user_context.rs b/partiql/tests/user_context.rs index e9ee53ce..bd35c776 100644 --- a/partiql/tests/user_context.rs +++ b/partiql/tests/user_context.rs @@ -174,7 +174,7 @@ pub(crate) fn evaluate( }; let mut ctx = BasicContext::new(bindings, sys); for (k, v) in ctx_vals { - ctx.user.insert(k.to_string(), *v); + ctx.user.insert(k.as_str().into(), *v); } if let Ok(out) = plan.execute_mut(&ctx) { out.result