Skip to content

Commit

Permalink
Refactor matching of BindingsName (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpschorr authored Jan 14, 2025
1 parent e21bd72 commit a409335
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
3 changes: 1 addition & 2 deletions partiql-logical/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ use partiql_common::catalog::ObjectId;
/// assert_eq!(3, p.operators().len());
/// assert_eq!(2, p.flows().len());
/// ```
use partiql_value::BindingsName;
use rust_decimal::Decimal as RustDecimal;
use std::collections::HashMap;
use std::fmt::{Debug, Display, Formatter};

use partiql_value::BindingsName;
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -464,7 +464,6 @@ pub enum Lit {
Bag(Vec<Lit>),
List(Vec<Lit>),
}

// TODO we should replace this enum with some identifier that can be looked up in a symtab/funcregistry?
/// Represents logical plan's unary operators.
#[derive(Debug, Clone, Eq, PartialEq)]
Expand Down
33 changes: 33 additions & 0 deletions partiql-value/src/bindings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{PairsIntoIter, PairsIter, Value};
use serde::{Deserialize, Serialize};
use std::borrow::Cow;
use std::iter::Once;
use unicase::UniCase;

#[derive(Clone, Hash, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
Expand All @@ -11,6 +12,38 @@ pub enum BindingsName<'s> {
CaseInsensitive(Cow<'s, str>),
}

impl<'s> BindingsName<'s> {
pub fn matcher(&'s self) -> BindingsMatcher<'s> {
BindingsMatcher::from(self)
}
}

#[derive(Clone, Hash, Debug, Eq, PartialEq)]
pub enum BindingsMatcher<'s> {
CaseSensitive(&'s str),
CaseInsensitive(UniCase<&'s str>),
}

impl<'s> BindingsMatcher<'s> {
pub fn matches(&'s self, candidate: &str) -> bool {
match self {
BindingsMatcher::CaseSensitive(target) => *target == candidate,
BindingsMatcher::CaseInsensitive(target) => *target == UniCase::new(candidate),
}
}
}

impl<'s> From<&'s BindingsName<'s>> for BindingsMatcher<'s> {
fn from(name: &'s BindingsName<'_>) -> Self {
match name {
BindingsName::CaseSensitive(s) => BindingsMatcher::CaseSensitive(s.as_ref()),
BindingsName::CaseInsensitive(s) => {
BindingsMatcher::CaseInsensitive(UniCase::new(s.as_ref()))
}
}
}
}

#[derive(Debug, Clone)]
pub enum BindingIter<'a> {
Tuple(PairsIter<'a>),
Expand Down
13 changes: 2 additions & 11 deletions partiql-value/src/tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ use std::hash::{Hash, Hasher};
use std::iter::{zip, Zip};
use std::vec;

use unicase::UniCase;

use crate::sort::NullSortedValue;
use crate::{BindingsName, EqualityValue, NullableEq, Value};
#[cfg(feature = "serde")]
Expand Down Expand Up @@ -79,15 +77,8 @@ impl Tuple {

#[inline(always)]
fn find_value(&self, attr: &BindingsName<'_>) -> Option<usize> {
match attr {
BindingsName::CaseSensitive(s) => {
self.attrs.iter().position(|a| a.as_str() == s.as_ref())
}
BindingsName::CaseInsensitive(s) => {
let target = UniCase::new(&s);
self.attrs.iter().position(|a| target == UniCase::new(a))
}
}
let matcher = attr.matcher();
self.attrs.iter().position(|a| matcher.matches(a))
}

#[inline]
Expand Down

1 comment on commit a409335

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartiQL (rust) Benchmark

Benchmark suite Current: a409335 Previous: e21bd72 Ratio
arith_agg-avg 772276 ns/iter (± 3437) 775516 ns/iter (± 2472) 1.00
arith_agg-avg_distinct 858566 ns/iter (± 4128) 860718 ns/iter (± 3610) 1.00
arith_agg-count 827877 ns/iter (± 13071) 825762 ns/iter (± 13338) 1.00
arith_agg-count_distinct 852895 ns/iter (± 6794) 856013 ns/iter (± 2178) 1.00
arith_agg-min 828341 ns/iter (± 5418) 827807 ns/iter (± 3572) 1.00
arith_agg-min_distinct 857045 ns/iter (± 2362) 863961 ns/iter (± 2032) 0.99
arith_agg-max 827910 ns/iter (± 3246) 833242 ns/iter (± 13387) 0.99
arith_agg-max_distinct 865956 ns/iter (± 16577) 872569 ns/iter (± 2150) 0.99
arith_agg-sum 824878 ns/iter (± 5881) 828631 ns/iter (± 2553) 1.00
arith_agg-sum_distinct 859240 ns/iter (± 4802) 859246 ns/iter (± 3067) 1.00
arith_agg-avg-count-min-max-sum 990177 ns/iter (± 17058) 988641 ns/iter (± 11710) 1.00
arith_agg-avg-count-min-max-sum-group_by 1291903 ns/iter (± 6879) 1257536 ns/iter (± 16268) 1.03
arith_agg-avg-count-min-max-sum-group_by-group_as 1906669 ns/iter (± 8973) 1872303 ns/iter (± 7934) 1.02
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct 1200477 ns/iter (± 18692) 1194270 ns/iter (± 12517) 1.01
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by 1495367 ns/iter (± 31044) 1479657 ns/iter (± 6104) 1.01
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by-group_as 2110307 ns/iter (± 9760) 2077505 ns/iter (± 13519) 1.02
parse-1 5373 ns/iter (± 24) 5522 ns/iter (± 62) 0.97
parse-15 46819 ns/iter (± 97) 46801 ns/iter (± 209) 1.00
parse-30 89844 ns/iter (± 308) 91843 ns/iter (± 355) 0.98
compile-1 4182 ns/iter (± 23) 4343 ns/iter (± 8) 0.96
compile-15 30764 ns/iter (± 282) 31329 ns/iter (± 75) 0.98
compile-30 63231 ns/iter (± 291) 63609 ns/iter (± 1169) 0.99
plan-1 70099 ns/iter (± 1332) 71217 ns/iter (± 434) 0.98
plan-15 1088274 ns/iter (± 8357) 1102206 ns/iter (± 11946) 0.99
plan-30 2255612 ns/iter (± 46211) 2194003 ns/iter (± 12838) 1.03
eval-1 12213604 ns/iter (± 145987) 11976854 ns/iter (± 103202) 1.02
eval-15 78102224 ns/iter (± 491542) 78254362 ns/iter (± 1207080) 1.00
eval-30 148626494 ns/iter (± 839657) 148466525 ns/iter (± 476208) 1.00
join 9902 ns/iter (± 275) 9902 ns/iter (± 23) 1
simple 2466 ns/iter (± 9) 2540 ns/iter (± 15) 0.97
simple-no 467 ns/iter (± 4) 488 ns/iter (± 4) 0.96
numbers 48 ns/iter (± 0) 48 ns/iter (± 0) 1
parse-simple 755 ns/iter (± 5) 746 ns/iter (± 14) 1.01
parse-ion 2242 ns/iter (± 42) 2294 ns/iter (± 47) 0.98
parse-group 7039 ns/iter (± 88) 7003 ns/iter (± 18) 1.01
parse-complex 18804 ns/iter (± 43) 18215 ns/iter (± 56) 1.03
parse-complex-fexpr 26127 ns/iter (± 76) 25649 ns/iter (± 253) 1.02

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.