Applies new Clippy suggestions

pull/244/head
Tpt 2 years ago committed by Thomas Tanon
parent f3e138f0b4
commit e9bbe8e036
  1. 2
      lib/oxrdf/src/parser.rs
  2. 8
      lib/spargebra/src/algebra.rs
  3. 5
      lib/src/sparql/eval.rs
  4. 6
      lib/src/sparql/model.rs
  5. 68
      lib/src/sparql/plan.rs
  6. 22
      lib/src/sparql/plan_builder.rs
  7. 8
      lib/src/storage/backend/rocksdb.rs
  8. 2
      lib/src/xsd/decimal.rs

@ -241,7 +241,7 @@ fn read_literal(s: &str) -> Result<(Literal, &str), TermParseError> {
return Err(TermParseError::msg("Empty term serialization")); return Err(TermParseError::msg("Empty term serialization"));
} }
let mut cursor = match input.get(0) { let mut cursor = match input.first() {
Some(b'+' | b'-') => 1, Some(b'+' | b'-') => 1,
_ => 0, _ => 0,
}; };

@ -1027,19 +1027,19 @@ impl<'a> fmt::Display for SparqlGraphRootPattern<'a> {
match child { match child {
GraphPattern::OrderBy { inner, expression } => { GraphPattern::OrderBy { inner, expression } => {
order = Some(expression); order = Some(expression);
child = &*inner; child = inner;
} }
GraphPattern::Project { inner, variables } if project.is_empty() => { GraphPattern::Project { inner, variables } if project.is_empty() => {
project = variables; project = variables;
child = &*inner; child = inner;
} }
GraphPattern::Distinct { inner } => { GraphPattern::Distinct { inner } => {
distinct = true; distinct = true;
child = &*inner; child = inner;
} }
GraphPattern::Reduced { inner } => { GraphPattern::Reduced { inner } => {
reduced = true; reduced = true;
child = &*inner; child = inner;
} }
GraphPattern::Slice { GraphPattern::Slice {
inner, inner,

@ -32,6 +32,7 @@ use std::str;
const REGEX_SIZE_LIMIT: usize = 1_000_000; const REGEX_SIZE_LIMIT: usize = 1_000_000;
type EncodedTuplesIterator = Box<dyn Iterator<Item = Result<EncodedTuple, EvaluationError>>>; type EncodedTuplesIterator = Box<dyn Iterator<Item = Result<EncodedTuple, EvaluationError>>>;
type CustomFunctionRegistry = HashMap<NamedNode, Rc<dyn Fn(&[Term]) -> Option<Term>>>;
#[derive(Clone)] #[derive(Clone)]
pub struct SimpleEvaluator { pub struct SimpleEvaluator {
@ -39,7 +40,7 @@ pub struct SimpleEvaluator {
base_iri: Option<Rc<Iri<String>>>, base_iri: Option<Rc<Iri<String>>>,
now: DateTime, now: DateTime,
service_handler: Rc<dyn ServiceHandler<Error = EvaluationError>>, service_handler: Rc<dyn ServiceHandler<Error = EvaluationError>>,
custom_functions: Rc<HashMap<NamedNode, Rc<dyn Fn(&[Term]) -> Option<Term>>>>, custom_functions: Rc<CustomFunctionRegistry>,
} }
impl SimpleEvaluator { impl SimpleEvaluator {
@ -47,7 +48,7 @@ impl SimpleEvaluator {
dataset: Rc<DatasetView>, dataset: Rc<DatasetView>,
base_iri: Option<Rc<Iri<String>>>, base_iri: Option<Rc<Iri<String>>>,
service_handler: Rc<dyn ServiceHandler<Error = EvaluationError>>, service_handler: Rc<dyn ServiceHandler<Error = EvaluationError>>,
custom_functions: Rc<HashMap<NamedNode, Rc<dyn Fn(&[Term]) -> Option<Term>>>>, custom_functions: Rc<CustomFunctionRegistry>,
) -> Self { ) -> Self {
Self { Self {
dataset, dataset,

@ -60,7 +60,7 @@ impl QueryResults {
Self::Boolean(value) => { Self::Boolean(value) => {
serializer.write_boolean_result(writer, value)?; serializer.write_boolean_result(writer, value)?;
} }
QueryResults::Solutions(solutions) => { Self::Solutions(solutions) => {
let mut writer = let mut writer =
serializer.solutions_writer(writer, solutions.variables().to_vec())?; serializer.solutions_writer(writer, solutions.variables().to_vec())?;
for solution in solutions { for solution in solutions {
@ -68,7 +68,7 @@ impl QueryResults {
} }
writer.finish()?; writer.finish()?;
} }
QueryResults::Graph(triples) => { Self::Graph(triples) => {
let s = VariableRef::new_unchecked("subject"); let s = VariableRef::new_unchecked("subject");
let p = VariableRef::new_unchecked("predicate"); let p = VariableRef::new_unchecked("predicate");
let o = VariableRef::new_unchecked("object"); let o = VariableRef::new_unchecked("object");
@ -115,7 +115,7 @@ impl QueryResults {
write: impl Write, write: impl Write,
format: GraphFormat, format: GraphFormat,
) -> Result<(), EvaluationError> { ) -> Result<(), EvaluationError> {
if let QueryResults::Graph(triples) = self { if let Self::Graph(triples) = self {
let mut writer = GraphSerializer::from_format(format).triple_writer(write)?; let mut writer = GraphSerializer::from_format(format).triple_writer(write)?;
for triple in triples { for triple in triples {
writer.write(&triple?)?; writer.write(&triple?)?;

@ -107,7 +107,7 @@ impl PlanNode {
pub fn lookup_used_variables(&self, callback: &mut impl FnMut(usize)) { pub fn lookup_used_variables(&self, callback: &mut impl FnMut(usize)) {
match self { match self {
PlanNode::StaticBindings { tuples } => { Self::StaticBindings { tuples } => {
for tuple in tuples { for tuple in tuples {
for (key, value) in tuple.iter().enumerate() { for (key, value) in tuple.iter().enumerate() {
if value.is_some() { if value.is_some() {
@ -116,7 +116,7 @@ impl PlanNode {
} }
} }
} }
PlanNode::QuadPattern { Self::QuadPattern {
subject, subject,
predicate, predicate,
object, object,
@ -135,7 +135,7 @@ impl PlanNode {
callback(*var); callback(*var);
} }
} }
PlanNode::PathPattern { Self::PathPattern {
subject, subject,
object, object,
graph_name, graph_name,
@ -151,23 +151,23 @@ impl PlanNode {
callback(*var); callback(*var);
} }
} }
PlanNode::Filter { child, expression } => { Self::Filter { child, expression } => {
expression.lookup_used_variables(callback); expression.lookup_used_variables(callback);
child.lookup_used_variables(callback); child.lookup_used_variables(callback);
} }
PlanNode::Union { children } => { Self::Union { children } => {
for child in children.iter() { for child in children.iter() {
child.lookup_used_variables(callback); child.lookup_used_variables(callback);
} }
} }
PlanNode::HashJoin { left, right } Self::HashJoin { left, right }
| PlanNode::ForLoopJoin { left, right, .. } | Self::ForLoopJoin { left, right, .. }
| PlanNode::AntiJoin { left, right } | Self::AntiJoin { left, right }
| PlanNode::LeftJoin { left, right, .. } => { | Self::LeftJoin { left, right, .. } => {
left.lookup_used_variables(callback); left.lookup_used_variables(callback);
right.lookup_used_variables(callback); right.lookup_used_variables(callback);
} }
PlanNode::Extend { Self::Extend {
child, child,
position, position,
expression, expression,
@ -176,12 +176,12 @@ impl PlanNode {
expression.lookup_used_variables(callback); expression.lookup_used_variables(callback);
child.lookup_used_variables(callback); child.lookup_used_variables(callback);
} }
PlanNode::Sort { child, .. } Self::Sort { child, .. }
| PlanNode::HashDeduplicate { child } | Self::HashDeduplicate { child }
| PlanNode::Reduced { child } | Self::Reduced { child }
| PlanNode::Skip { child, .. } | Self::Skip { child, .. }
| PlanNode::Limit { child, .. } => child.lookup_used_variables(callback), | Self::Limit { child, .. } => child.lookup_used_variables(callback),
PlanNode::Service { Self::Service {
child, child,
service_name, service_name,
.. ..
@ -191,7 +191,7 @@ impl PlanNode {
} }
child.lookup_used_variables(callback); child.lookup_used_variables(callback);
} }
PlanNode::Project { mapping, child } => { Self::Project { mapping, child } => {
let child_bound = child.used_variables(); let child_bound = child.used_variables();
for (child_i, output_i) in mapping.iter() { for (child_i, output_i) in mapping.iter() {
if child_bound.contains(child_i) { if child_bound.contains(child_i) {
@ -199,7 +199,7 @@ impl PlanNode {
} }
} }
} }
PlanNode::Aggregate { Self::Aggregate {
key_mapping, key_mapping,
aggregates, aggregates,
.. ..
@ -227,7 +227,7 @@ impl PlanNode {
pub fn lookup_always_bound_variables(&self, callback: &mut impl FnMut(usize)) { pub fn lookup_always_bound_variables(&self, callback: &mut impl FnMut(usize)) {
match self { match self {
PlanNode::StaticBindings { tuples } => { Self::StaticBindings { tuples } => {
let mut variables = BTreeMap::default(); // value true iff always bound let mut variables = BTreeMap::default(); // value true iff always bound
let max_tuple_length = tuples.iter().map(|t| t.capacity()).fold(0, max); let max_tuple_length = tuples.iter().map(|t| t.capacity()).fold(0, max);
for tuple in tuples { for tuple in tuples {
@ -250,7 +250,7 @@ impl PlanNode {
} }
} }
} }
PlanNode::QuadPattern { Self::QuadPattern {
subject, subject,
predicate, predicate,
object, object,
@ -269,7 +269,7 @@ impl PlanNode {
callback(*var); callback(*var);
} }
} }
PlanNode::PathPattern { Self::PathPattern {
subject, subject,
object, object,
graph_name, graph_name,
@ -285,11 +285,11 @@ impl PlanNode {
callback(*var); callback(*var);
} }
} }
PlanNode::Filter { child, .. } => { Self::Filter { child, .. } => {
//TODO: have a look at the expression to know if it filters out unbound variables //TODO: have a look at the expression to know if it filters out unbound variables
child.lookup_always_bound_variables(callback); child.lookup_always_bound_variables(callback);
} }
PlanNode::Union { children } => { Self::Union { children } => {
if let Some(vars) = children if let Some(vars) = children
.iter() .iter()
.map(|c| c.always_bound_variables()) .map(|c| c.always_bound_variables())
@ -300,14 +300,14 @@ impl PlanNode {
} }
} }
} }
PlanNode::HashJoin { left, right } | PlanNode::ForLoopJoin { left, right, .. } => { Self::HashJoin { left, right } | Self::ForLoopJoin { left, right, .. } => {
left.lookup_always_bound_variables(callback); left.lookup_always_bound_variables(callback);
right.lookup_always_bound_variables(callback); right.lookup_always_bound_variables(callback);
} }
PlanNode::AntiJoin { left, .. } | PlanNode::LeftJoin { left, .. } => { Self::AntiJoin { left, .. } | Self::LeftJoin { left, .. } => {
left.lookup_always_bound_variables(callback); left.lookup_always_bound_variables(callback);
} }
PlanNode::Extend { Self::Extend {
child, child,
position, position,
expression, expression,
@ -318,19 +318,19 @@ impl PlanNode {
} }
child.lookup_always_bound_variables(callback); child.lookup_always_bound_variables(callback);
} }
PlanNode::Sort { child, .. } Self::Sort { child, .. }
| PlanNode::HashDeduplicate { child } | Self::HashDeduplicate { child }
| PlanNode::Reduced { child } | Self::Reduced { child }
| PlanNode::Skip { child, .. } | Self::Skip { child, .. }
| PlanNode::Limit { child, .. } => child.lookup_always_bound_variables(callback), | Self::Limit { child, .. } => child.lookup_always_bound_variables(callback),
PlanNode::Service { child, silent, .. } => { Self::Service { child, silent, .. } => {
if *silent { if *silent {
// none, might return a null tuple // none, might return a null tuple
} else { } else {
child.lookup_always_bound_variables(callback) child.lookup_always_bound_variables(callback)
} }
} }
PlanNode::Project { mapping, child } => { Self::Project { mapping, child } => {
let child_bound = child.always_bound_variables(); let child_bound = child.always_bound_variables();
for (child_i, output_i) in mapping.iter() { for (child_i, output_i) in mapping.iter() {
if child_bound.contains(child_i) { if child_bound.contains(child_i) {
@ -338,7 +338,7 @@ impl PlanNode {
} }
} }
} }
PlanNode::Aggregate { .. } => { Self::Aggregate { .. } => {
//TODO //TODO
} }
} }

@ -1079,7 +1079,7 @@ impl<'a> PlanBuilder<'a> {
set.insert(v); set.insert(v);
} }
}); });
self.add_left_join_problematic_variables(&*child, set); self.add_left_join_problematic_variables(child, set);
} }
PlanNode::Union { children } => { PlanNode::Union { children } => {
for child in children.iter() { for child in children.iter() {
@ -1087,14 +1087,14 @@ impl<'a> PlanBuilder<'a> {
} }
} }
PlanNode::HashJoin { left, right } | PlanNode::ForLoopJoin { left, right } => { PlanNode::HashJoin { left, right } | PlanNode::ForLoopJoin { left, right } => {
self.add_left_join_problematic_variables(&*left, set); self.add_left_join_problematic_variables(left, set);
self.add_left_join_problematic_variables(&*right, set); self.add_left_join_problematic_variables(right, set);
} }
PlanNode::AntiJoin { left, .. } => { PlanNode::AntiJoin { left, .. } => {
self.add_left_join_problematic_variables(&*left, set); self.add_left_join_problematic_variables(left, set);
} }
PlanNode::LeftJoin { left, right, .. } => { PlanNode::LeftJoin { left, right, .. } => {
self.add_left_join_problematic_variables(&*left, set); self.add_left_join_problematic_variables(left, set);
right.lookup_used_variables(&mut |v| { right.lookup_used_variables(&mut |v| {
set.insert(v); set.insert(v);
}); });
@ -1108,28 +1108,26 @@ impl<'a> PlanBuilder<'a> {
set.insert(v); set.insert(v);
} }
}); });
self.add_left_join_problematic_variables(&*child, set); self.add_left_join_problematic_variables(child, set);
self.add_left_join_problematic_variables(&*child, set); self.add_left_join_problematic_variables(child, set);
} }
PlanNode::Sort { child, .. } PlanNode::Sort { child, .. }
| PlanNode::HashDeduplicate { child } | PlanNode::HashDeduplicate { child }
| PlanNode::Reduced { child } | PlanNode::Reduced { child }
| PlanNode::Skip { child, .. } | PlanNode::Skip { child, .. }
| PlanNode::Limit { child, .. } => { | PlanNode::Limit { child, .. } => self.add_left_join_problematic_variables(child, set),
self.add_left_join_problematic_variables(&*child, set)
}
PlanNode::Service { child, silent, .. } => { PlanNode::Service { child, silent, .. } => {
if *silent { if *silent {
child.lookup_used_variables(&mut |v| { child.lookup_used_variables(&mut |v| {
set.insert(v); set.insert(v);
}); });
} else { } else {
self.add_left_join_problematic_variables(&*child, set) self.add_left_join_problematic_variables(child, set)
} }
} }
PlanNode::Project { mapping, child } => { PlanNode::Project { mapping, child } => {
let mut child_bound = BTreeSet::new(); let mut child_bound = BTreeSet::new();
self.add_left_join_problematic_variables(&*child, &mut child_bound); self.add_left_join_problematic_variables(child, &mut child_bound);
for (child_i, output_i) in mapping.iter() { for (child_i, output_i) in mapping.iter() {
if child_bound.contains(child_i) { if child_bound.contains(child_i) {
set.insert(*output_i); set.insert(*output_i);

@ -892,13 +892,13 @@ impl Deref for PinnableSlice {
impl AsRef<[u8]> for PinnableSlice { impl AsRef<[u8]> for PinnableSlice {
fn as_ref(&self) -> &[u8] { fn as_ref(&self) -> &[u8] {
&*self self
} }
} }
impl Borrow<[u8]> for PinnableSlice { impl Borrow<[u8]> for PinnableSlice {
fn borrow(&self) -> &[u8] { fn borrow(&self) -> &[u8] {
&*self self
} }
} }
@ -931,13 +931,13 @@ impl Deref for Buffer {
impl AsRef<[u8]> for Buffer { impl AsRef<[u8]> for Buffer {
fn as_ref(&self) -> &[u8] { fn as_ref(&self) -> &[u8] {
&*self self
} }
} }
impl Borrow<[u8]> for Buffer { impl Borrow<[u8]> for Buffer {
fn borrow(&self) -> &[u8] { fn borrow(&self) -> &[u8] {
&*self self
} }
} }

@ -320,7 +320,7 @@ impl FromStr for Decimal {
return Err(PARSE_UNEXPECTED_END); return Err(PARSE_UNEXPECTED_END);
} }
let (sign, mut cursor) = match input.get(0) { let (sign, mut cursor) = match input.first() {
Some(b'+') => (1, 1), Some(b'+') => (1, 1),
Some(b'-') => (-1, 1), Some(b'-') => (-1, 1),
_ => (1, 0), _ => (1, 0),

Loading…
Cancel
Save