Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
fixed linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielLazarHTDM committed Nov 10, 2023
1 parent 59400d8 commit 4e578e0
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 138 deletions.
61 changes: 32 additions & 29 deletions kuksa_databroker/databroker/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ use std::convert::TryFrom;
use std::sync::atomic::{AtomicI32, Ordering};
use std::sync::Arc;
use std::time::SystemTime;
use crate::query::{CompiledQuery, ExecutionInput};

use tracing::{debug, info, warn};
use crate::query::{CompiledQuery, ExecutionInput};
use crate::types::ExecutionInputImplData;
use tracing::{debug, info, warn};

use crate::glob;

Expand Down Expand Up @@ -611,11 +611,11 @@ impl Subscriptions {
let mut lag_updates: HashMap<String, ()> = HashMap::new();
for sub in &self.query_subscriptions {
match sub.notify(changed, db).await {
Ok(None) => {},
Ok(None) => {}
Ok(Some(input)) => {
for x in input.get_fields() {
if x.1.lag_value != x.1.value {
if ! lag_updates.contains_key(x.0) {
if !lag_updates.contains_key(x.0) {
lag_updates.insert(x.0.clone(), ());
}
}
Expand All @@ -640,7 +640,7 @@ impl Subscriptions {
} else {
Ok(None)
}
},
}
}
}

Expand Down Expand Up @@ -785,21 +785,27 @@ impl QuerySubscription {
&self,
name: &String,
db: &DatabaseReadAccess,
input: &mut query::ExecutionInputImpl) {
input: &mut query::ExecutionInputImpl,
) {
match db.get_entry_by_path(name) {
Ok(entry) => {
input.add(name.to_owned(), ExecutionInputImplData{
value: entry.datapoint.value.to_owned(),
lag_value: entry.lag_datapoint.value.to_owned()
});

},
input.add(
name.to_owned(),
ExecutionInputImplData {
value: entry.datapoint.value.to_owned(),
lag_value: entry.lag_datapoint.value.to_owned(),
},
);
}
Err(_) => {
// TODO: This should probably generate an error
input.add(name.to_owned(), ExecutionInputImplData {
value: DataValue::NotAvailable,
lag_value: DataValue::NotAvailable
})
input.add(
name.to_owned(),
ExecutionInputImplData {
value: DataValue::NotAvailable,
lag_value: DataValue::NotAvailable,
},
)
}
}
}
Expand Down Expand Up @@ -830,7 +836,7 @@ impl QuerySubscription {
}
None => {
// Always generate input if `changed` is None
return true
return true;
}
}
false
Expand All @@ -839,7 +845,7 @@ impl QuerySubscription {
&self,
query: &CompiledQuery,
db: &DatabaseReadAccess,
input: &mut query::ExecutionInputImpl
input: &mut query::ExecutionInputImpl,
) {
for name in query.input_spec.iter() {
self.find_in_db_and_add(name, db, input);
Expand Down Expand Up @@ -1030,14 +1036,12 @@ impl<'a, 'b> DatabaseWriteAccess<'a, 'b> {

pub fn update_entry_lag_to_be_equal(&mut self, path: &str) -> Result<(), UpdateError> {
match self.db.path_to_id.get(path) {
Some(id) => {
match self.db.entries.get_mut(&id) {
Some(entry) => {
entry.apply_lag_after_execute();
Ok(())
}
None => Err(UpdateError::NotFound),
Some(id) => match self.db.entries.get_mut(&id) {
Some(entry) => {
entry.apply_lag_after_execute();
Ok(())
}
None => Err(UpdateError::NotFound),
},
None => Err(UpdateError::NotFound),
}
Expand Down Expand Up @@ -1389,7 +1393,6 @@ impl<'a, 'b> AuthorizedAccess<'a, 'b> {
// notifying subscribers (no writes in between)
let db = db.downgrade();


// Notify
match self
.broker
Expand All @@ -1403,7 +1406,7 @@ impl<'a, 'b> AuthorizedAccess<'a, 'b> {
Ok(Some(lag_updates_)) => {
lag_updates = lag_updates_.clone();
false
},
}
Err(_) => true, // Cleanup needed
}
};
Expand All @@ -1413,8 +1416,8 @@ impl<'a, 'b> AuthorizedAccess<'a, 'b> {
let mut db_write = db.authorized_write_access(self.permissions);
for x in lag_updates {
match db_write.update_entry_lag_to_be_equal(x.0.as_str()) {
Ok(_) => {},
Err(_) => {},
Ok(_) => {}
Err(_) => {}
};
}
}
Expand Down
31 changes: 16 additions & 15 deletions kuksa_databroker/databroker/src/query/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn compile_expr(
data_type,
lag: false,
})
},
}
ast::Expr::Function(f) => {
let name = &f.name.to_string();
return if name == "LAG" {
Expand All @@ -164,31 +164,33 @@ pub fn compile_expr(
ast::FunctionArgExpr::Expr(e) => {
let function_expr = compile_expr(e, input, output)?;
return match function_expr {
Expr::Datapoint { name, data_type, .. } => Ok(Expr::Datapoint {
Expr::Datapoint {
name, data_type, ..
} => Ok(Expr::Datapoint {
name,
data_type,
lag: true
lag: true,
}),
_ => Err(CompilationError::ParseError(format!(
"Unable to create lag datapoint"
)))
))),
};
}
_ => Err(CompilationError::UnsupportedOperator(format!(
"Unsupported function argument expression"
)))
))),
}
},
}
_ => Err(CompilationError::UnsupportedOperator(format!(
"Unsupported function argument"
)))
))),
}
} else {
Err(CompilationError::UnsupportedOperator(format!(
"Unsupported operator \"{name}\""
)))
};
},
}

ast::Expr::BinaryOp {
ref left,
Expand Down Expand Up @@ -352,20 +354,20 @@ pub fn compile_expr(
Ok(compiled_query) => {
output.subquery.push(compiled_query);
Ok(Expr::Subquery {
index: (output.subquery.len() - 1) as u32
index: (output.subquery.len() - 1) as u32,
})
},
}

_ => Err(CompilationError::UnsupportedOperator(format!(
"Subquery failed to compile query"
)))
))),
}
} else {
Err(CompilationError::UnsupportedOperation(
"Subquery to parse".to_string(),
))
}
},
}

ast::Expr::UnaryOp { ref op, ref expr } => match op {
ast::UnaryOperator::Not => Ok(Expr::UnaryOperation {
Expand Down Expand Up @@ -475,7 +477,7 @@ fn resolve_literal(

fn compile_select_statement(
select: &ast::Select,
input: &impl CompilationInput
input: &impl CompilationInput,
) -> Result<CompiledQuery, CompilationError> {
let mut query = CompiledQuery::new();

Expand All @@ -486,8 +488,7 @@ fn compile_select_statement(
if let Ok(data_type) = condition.get_type() {
if data_type != DataType::Bool {
return Err(CompilationError::TypeError(
"WHERE statement doesn't evaluate to a boolean expression"
.to_string(),
"WHERE statement doesn't evaluate to a boolean expression".to_string(),
));
}
}
Expand Down
Loading

0 comments on commit 4e578e0

Please sign in to comment.