Skip to content

Commit

Permalink
formatting & cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jpschorr committed Feb 7, 2024
1 parent 06e0ccd commit 3f04665
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
2 changes: 1 addition & 1 deletion partiql-eval/src/eval/expr/path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::env::Bindings;

pub use core::borrow::{Borrow, BorrowMut};
pub use core::borrow::Borrow;

use crate::eval::expr::{BindError, BindEvalExpr, EvalExpr};
use crate::eval::EvalContext;
Expand Down
58 changes: 23 additions & 35 deletions partiql-logical-planner/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use partiql_catalog::call_defs::{CallArgument, CallDef};

use partiql_ast_passes::error::{AstTransformError, AstTransformationError};

use partiql_ast_passes::name_resolver::{NameLookup, NameRef};
use partiql_ast_passes::name_resolver::NameRef;
use partiql_catalog::Catalog;
use partiql_extension_ion::decode::{IonDecoderBuilder, IonDecoderConfig};
use partiql_extension_ion::Encoding;
Expand Down Expand Up @@ -289,19 +289,6 @@ impl<'a> AstToLogical<'a> {
}

fn resolve_varref(&self, varref: &ast::VarRef) -> logical::ValueExpr {
fn binding_to_symprim<'a>(binding: &'a BindingsName<'a>) -> SymbolPrimitive {
match binding {
BindingsName::CaseSensitive(n) => SymbolPrimitive {
value: n.as_ref().to_owned(),
case: CaseSensitivity::CaseSensitive,
},
BindingsName::CaseInsensitive(n) => SymbolPrimitive {
value: n.as_ref().to_owned(),
case: CaseSensitivity::CaseInsensitive,
},
}
}

fn binding_to_static<'a>(binding: &'a BindingsName<'a>) -> BindingsName<'static> {
match binding {
BindingsName::CaseSensitive(n) => {
Expand Down Expand Up @@ -336,7 +323,7 @@ impl<'a> AstToLogical<'a> {
if let Some(key_schema) = self.key_registry.schema.get(id) {
let key_schema: &name_resolver::KeySchema = key_schema;

let name_ref: &NameRef = &key_schema
let name_ref: &NameRef = key_schema
.consume
.iter()
.find(|name_ref| name_ref.sym == varref.name)
Expand All @@ -346,23 +333,24 @@ impl<'a> AstToLogical<'a> {
let mut lookups = vec![];

if matches!(self.current_ctx(), Some(QueryContext::Order)) {
let renames = self.projection_renames.last().unwrap();
let binding = renames
.iter()
.find(|(k, _)| {
let SymbolPrimitive { value, case } = &name_ref.sym;
match case {
CaseSensitivity::CaseSensitive => value == *k,
CaseSensitivity::CaseInsensitive => unicase::eq(value, *k),
}
})
.map(|(k, v)| binding_to_static(v))
.unwrap_or_else(|| symprim_to_binding(&name_ref.sym));

lookups.push(DynamicLookup(Box::new(vec![ValueExpr::VarRef(
binding,
VarRefType::Local,
)])));
if let Some(renames) = self.projection_renames.last() {
let binding = renames
.iter()
.find(|(k, _)| {
let SymbolPrimitive { value, case } = &name_ref.sym;
match case {
CaseSensitivity::CaseSensitive => value == *k,
CaseSensitivity::CaseInsensitive => unicase::eq(value, *k),
}
})
.map(|(_k, v)| binding_to_static(v))
.unwrap_or_else(|| symprim_to_binding(&name_ref.sym));

lookups.push(DynamicLookup(Box::new(vec![ValueExpr::VarRef(
binding,
VarRefType::Local,
)])));
}
}

for lookup in &name_ref.lookup {
Expand Down Expand Up @@ -911,7 +899,7 @@ impl<'a, 'ast> Visitor<'ast> for AstToLogical<'a> {
};

if !alias.is_empty() {
if let ValueExpr::VarRef(name, vrtype) = &value {
if let ValueExpr::VarRef(name, _vrtype) = &value {
self.projection_renames
.last_mut()
.expect("renames")
Expand Down Expand Up @@ -2025,7 +2013,7 @@ mod tests {
let lowering_errs = logical.expect_err("Expect errs").errors;
assert_eq!(lowering_errs.len(), 2);
assert_eq!(
lowering_errs.get(0),
lowering_errs.first(),
Some(&AstTransformError::UnsupportedFunction("foo".to_string()))
);
assert_eq!(
Expand All @@ -2047,7 +2035,7 @@ mod tests {
let lowering_errs = logical.expect_err("Expect errs").errors;
assert_eq!(lowering_errs.len(), 2);
assert_eq!(
lowering_errs.get(0),
lowering_errs.first(),
Some(&AstTransformError::InvalidNumberOfArguments(
"abs".to_string()
))
Expand Down

0 comments on commit 3f04665

Please sign in to comment.