fix clippy warnings

main
Ziyang Hu 2 years ago
parent 3f3b4ea569
commit 352ac01351

@ -82,7 +82,7 @@ impl AlgoImpl for JsonReader {
let line = line.into_diagnostic()?; let line = line.into_diagnostic()?;
let line = line.trim(); let line = line.trim();
if !line.is_empty() { if !line.is_empty() {
let row = serde_json::from_str(&line).into_diagnostic()?; let row = serde_json::from_str(line).into_diagnostic()?;
process_row(&row)?; process_row(&row)?;
} }
} }
@ -104,12 +104,12 @@ impl AlgoImpl for JsonReader {
for line in content.lines() { for line in content.lines() {
let line = line.trim(); let line = line.trim();
if !line.is_empty() { if !line.is_empty() {
let row = serde_json::from_str(&line).into_diagnostic()?; let row = serde_json::from_str(line).into_diagnostic()?;
process_row(&row)?; process_row(&row)?;
} }
} }
} else { } else {
let data: JsonValue = serde_json::from_str(&content).into_diagnostic()?; let data: JsonValue = serde_json::from_str(content).into_diagnostic()?;
let rows = data let rows = data
.as_array() .as_array()
.ok_or_else(|| miette!("JSON file is not an array"))?; .ok_or_else(|| miette!("JSON file is not an array"))?;

@ -343,7 +343,7 @@ impl Expr {
return val.eval(bindings); return val.eval(bindings);
} }
} }
return Ok(DataValue::Null); Ok(DataValue::Null)
} }
Expr::Try { clauses, .. } => { Expr::Try { clauses, .. } => {
if clauses.is_empty() { if clauses.is_empty() {
@ -564,8 +564,7 @@ impl<'de> Visitor<'de> for OpVisitor {
E: Error, E: Error,
{ {
let name = v.strip_prefix("OP_").unwrap().to_ascii_lowercase(); let name = v.strip_prefix("OP_").unwrap().to_ascii_lowercase();
Ok(get_op(&name) get_op(&name).ok_or_else(|| E::custom(format!("op not found in serialized data: {}", v)))
.ok_or_else(|| E::custom(format!("op not found in serialized data: {}", v)))?)
} }
} }
@ -703,7 +702,7 @@ pub(crate) fn get_op(name: &str) -> Option<&'static Op> {
} }
impl Op { impl Op {
pub(crate) fn post_process_args(&self, args: &mut Vec<Expr>) { pub(crate) fn post_process_args(&self, args: &mut [Expr]) {
if self.name.starts_with("OP_REGEX_") { if self.name.starts_with("OP_REGEX_") {
args[1] = Expr::Apply { args[1] = Expr::Apply {
op: &OP_REGEX, op: &OP_REGEX,

@ -35,7 +35,7 @@ pub(crate) enum QueryAssertion {
AssertSome(SourceSpan), AssertSome(SourceSpan),
} }
#[derive(Clone, Eq, PartialEq)] #[derive(Clone, Eq, PartialEq, Default)]
pub(crate) struct QueryOutOptions { pub(crate) struct QueryOutOptions {
pub(crate) limit: Option<usize>, pub(crate) limit: Option<usize>,
pub(crate) offset: Option<usize>, pub(crate) offset: Option<usize>,
@ -54,20 +54,20 @@ impl Debug for QueryOutOptions {
impl Display for QueryOutOptions { impl Display for QueryOutOptions {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
if let Some(l) = self.limit { if let Some(l) = self.limit {
write!(f, ":limit {};\n", l)?; writeln!(f, ":limit {};", l)?;
} }
if let Some(l) = self.offset { if let Some(l) = self.offset {
write!(f, ":offset {};\n", l)?; writeln!(f, ":offset {};", l)?;
} }
if let Some(l) = self.timeout { if let Some(l) = self.timeout {
write!(f, ":timeout {};\n", l)?; writeln!(f, ":timeout {};", l)?;
} }
for (symb, dir) in &self.sorters { for (symb, dir) in &self.sorters {
write!(f, ":order ")?; write!(f, ":order ")?;
if *dir == SortDir::Dsc { if *dir == SortDir::Dsc {
write!(f, "-")?; write!(f, "-")?;
} }
write!(f, "{};\n", symb)?; writeln!(f, "{};", symb)?;
} }
if let Some(( if let Some((
InputRelationHandle { InputRelationHandle {
@ -124,16 +124,16 @@ impl Display for QueryOutOptions {
write!(f, " = {}", bind)?; write!(f, " = {}", bind)?;
} }
} }
write!(f, "}};\n")?; writeln!(f, "}};")?;
} }
if let Some(a) = &self.assertion { if let Some(a) = &self.assertion {
match a { match a {
QueryAssertion::AssertNone(_) => { QueryAssertion::AssertNone(_) => {
write!(f, ":assert none;\n")?; writeln!(f, ":assert none;")?;
} }
QueryAssertion::AssertSome(_) => { QueryAssertion::AssertSome(_) => {
write!(f, ":assert some;\n")?; writeln!(f, ":assert some;")?;
} }
} }
} }
@ -142,19 +142,6 @@ impl Display for QueryOutOptions {
} }
} }
impl Default for QueryOutOptions {
fn default() -> Self {
Self {
limit: None,
offset: None,
timeout: None,
sorters: vec![],
store_relation: None,
assertion: None,
}
}
}
impl QueryOutOptions { impl QueryOutOptions {
pub(crate) fn num_to_take(&self) -> Option<usize> { pub(crate) fn num_to_take(&self) -> Option<usize> {
match (self.limit, self.offset) { match (self.limit, self.offset) {
@ -607,7 +594,7 @@ impl Display for InputProgram {
f.debug_list().entries(&rule.bindings).finish()?; f.debug_list().entries(&rule.bindings).finish()?;
write!(f, " <- ")?; write!(f, " <- ")?;
f.debug_list().entries(&rule.data).finish()?; f.debug_list().entries(&rule.data).finish()?;
write!(f, ";\n")?; writeln!(f, ";")?;
} }
for (name, rules) in &self.prog { for (name, rules) in &self.prog {
match rules { match rules {
@ -639,7 +626,7 @@ impl Display for InputProgram {
} }
write!(f, "{}", atom)?; write!(f, "{}", atom)?;
} }
write!(f, ";\n")?; writeln!(f, ";")?;
} }
} }
InputRulesOrAlgo::Algo { InputRulesOrAlgo::Algo {
@ -673,7 +660,7 @@ impl Display for InputProgram {
} }
write!(f, "{}: {}", k, v)?; write!(f, "{}: {}", k, v)?;
} }
write!(f, ");\n")?; writeln!(f, ");")?;
} }
} }
} }

@ -154,7 +154,7 @@ impl NullableColType {
let make_err = || DataCoercionFailed(self.clone(), data.clone()); let make_err = || DataCoercionFailed(self.clone(), data.clone());
return Ok(match &self.coltype { Ok(match &self.coltype {
ColType::Any => data, ColType::Any => data,
ColType::Int => DataValue::from(data.get_int().ok_or_else(make_err)?), ColType::Int => DataValue::from(data.get_int().ok_or_else(make_err)?),
ColType::Float => DataValue::from(data.get_float().ok_or_else(make_err)?), ColType::Float => DataValue::from(data.get_float().ok_or_else(make_err)?),
@ -201,6 +201,6 @@ impl NullableColType {
bail!(make_err()) bail!(make_err())
} }
} }
}); })
} }
} }

@ -25,7 +25,7 @@ impl Ord for UuidWrapper {
s_h.cmp(&o_h) s_h.cmp(&o_h)
.then_with(|| s_m.cmp(&o_m)) .then_with(|| s_m.cmp(&o_m))
.then_with(|| s_l.cmp(&o_l)) .then_with(|| s_l.cmp(&o_l))
.then_with(|| s_rest.cmp(&o_rest)) .then_with(|| s_rest.cmp(o_rest))
} }
} }

@ -1,17 +1,19 @@
use std::collections::BTreeSet; use std::collections::BTreeSet;
use itertools::Itertools; use itertools::Itertools;
use miette::{bail, Diagnostic, ensure, Result}; use miette::{bail, ensure, Diagnostic, Result};
use smartstring::SmartString; use smartstring::SmartString;
use thiserror::Error; use thiserror::Error;
use crate::data::relation::{ColType, ColumnDef, NullableColType, StoredRelationMetadata}; use crate::data::relation::{ColType, ColumnDef, NullableColType, StoredRelationMetadata};
use crate::data::symb::Symbol; use crate::data::symb::Symbol;
use crate::data::value::DataValue; use crate::data::value::DataValue;
use crate::parse::{ExtractSpan, Pair, Rule, SourceSpan};
use crate::parse::expr::build_expr; use crate::parse::expr::build_expr;
use crate::parse::{ExtractSpan, Pair, Rule, SourceSpan};
pub(crate) fn parse_schema(pair: Pair<'_>) -> Result<(StoredRelationMetadata, Vec<Symbol>, Vec<Symbol>)> { pub(crate) fn parse_schema(
pair: Pair<'_>,
) -> Result<(StoredRelationMetadata, Vec<Symbol>, Vec<Symbol>)> {
// assert_eq!(pair.as_rule(), Rule::table_schema); // assert_eq!(pair.as_rule(), Rule::table_schema);
let span = pair.extract_span(); let span = pair.extract_span();
@ -55,10 +57,14 @@ pub(crate) fn parse_schema(pair: Pair<'_>) -> Result<(StoredRelationMetadata, Ve
bail!(EmptySchema(span)) bail!(EmptySchema(span))
} }
Ok((StoredRelationMetadata { Ok((
keys, StoredRelationMetadata {
non_keys: dependents, keys,
}, key_bindings, dep_bindings)) non_keys: dependents,
},
key_bindings,
dep_bindings,
))
} }
fn parse_col(pair: Pair<'_>) -> Result<(ColumnDef, Symbol)> { fn parse_col(pair: Pair<'_>) -> Result<(ColumnDef, Symbol)> {
@ -75,26 +81,28 @@ fn parse_col(pair: Pair<'_>) -> Result<(ColumnDef, Symbol)> {
match nxt.as_rule() { match nxt.as_rule() {
Rule::col_type => typing = parse_nullable_type(nxt)?, Rule::col_type => typing = parse_nullable_type(nxt)?,
Rule::expr => default_gen = Some(build_expr(nxt, &Default::default())?), Rule::expr => default_gen = Some(build_expr(nxt, &Default::default())?),
Rule::out_arg => binding_candidate = Some(Symbol::new(nxt.as_str(), nxt.extract_span())), Rule::out_arg => {
r => unreachable!("{:?}", r) binding_candidate = Some(Symbol::new(nxt.as_str(), nxt.extract_span()))
}
r => unreachable!("{:?}", r),
} }
} }
let binding = binding_candidate.unwrap_or_else(|| let binding =
Symbol::new(&name as &str, name_p.extract_span())); binding_candidate.unwrap_or_else(|| Symbol::new(&name as &str, name_p.extract_span()));
Ok((ColumnDef { Ok((
name, ColumnDef {
typing, name,
default_gen, typing,
}, binding)) default_gen,
},
binding,
))
} }
pub(crate) fn parse_nullable_type(pair: Pair<'_>) -> Result<NullableColType> { pub(crate) fn parse_nullable_type(pair: Pair<'_>) -> Result<NullableColType> {
let nullable = pair.as_str().ends_with('?'); let nullable = pair.as_str().ends_with('?');
let coltype = parse_type_inner(pair.into_inner().next().unwrap())?; let coltype = parse_type_inner(pair.into_inner().next().unwrap())?;
Ok(NullableColType { Ok(NullableColType { coltype, nullable })
coltype,
nullable,
})
} }
fn parse_type_inner(pair: Pair<'_>) -> Result<ColType> { fn parse_type_inner(pair: Pair<'_>) -> Result<ColType> {
@ -120,17 +128,19 @@ fn parse_type_inner(pair: Pair<'_>) -> Result<ColType> {
#[diagnostic(code(parser::bad_list_len_in_type))] #[diagnostic(code(parser::bad_list_len_in_type))]
struct BadListLenSpec(DataValue, #[label] SourceSpan); struct BadListLenSpec(DataValue, #[label] SourceSpan);
let n = dv.get_int() let n = dv.get_int().ok_or(BadListLenSpec(dv, span))?;
.ok_or_else(|| BadListLenSpec(dv, span))?;
ensure!(n >= 0, BadListLenSpec(DataValue::from(n), span)); ensure!(n >= 0, BadListLenSpec(DataValue::from(n), span));
Some(n as usize) Some(n as usize)
} }
}; };
ColType::List { eltype: eltype.into(), len } ColType::List {
eltype: eltype.into(),
len,
}
} }
Rule::tuple_type => { Rule::tuple_type => {
ColType::Tuple(pair.into_inner().map(|p| parse_nullable_type(p)).try_collect()?) ColType::Tuple(pair.into_inner().map(parse_nullable_type).try_collect()?)
} }
_ => unreachable!() _ => unreachable!(),
}) })
} }

@ -16,7 +16,7 @@ pub(crate) enum SysOp {
ListRelations, ListRelations,
ListRunning, ListRunning,
KillRunning(u64), KillRunning(u64),
Explain(InputProgram), Explain(Box<InputProgram>),
RemoveRelation(Vec<Symbol>), RemoveRelation(Vec<Symbol>),
RenameRelation(Vec<(Symbol, Symbol)>), RenameRelation(Vec<(Symbol, Symbol)>),
ShowTrigger(Symbol), ShowTrigger(Symbol),
@ -44,7 +44,7 @@ pub(crate) fn parse_sys(
} }
Rule::explain_op => { Rule::explain_op => {
let prog = parse_query(inner.into_inner().next().unwrap().into_inner(), param_pool)?; let prog = parse_query(inner.into_inner().next().unwrap().into_inner(), param_pool)?;
SysOp::Explain(prog) SysOp::Explain(Box::new(prog))
} }
Rule::list_relations_op => SysOp::ListRelations, Rule::list_relations_op => SysOp::ListRelations,
Rule::remove_relations_op => { Rule::remove_relations_op => {

@ -332,7 +332,7 @@ impl NormalFormProgram {
bindings, bindings,
span, span,
} => { } => {
let relation = tx.get_relation(&name, false)?; let relation = tx.get_relation(name, false)?;
let fields: BTreeSet<_> = relation let fields: BTreeSet<_> = relation
.metadata .metadata
.keys .keys

@ -790,8 +790,7 @@ impl RelationRA {
ret.extend(found.0); ret.extend(found.0);
Ok(Some(Tuple(ret))) Ok(Some(Tuple(ret)))
}) })
.map(swap_option_result) .filter_map(swap_option_result),
.flatten(),
); );
} }
} }
@ -810,8 +809,7 @@ impl RelationRA {
ret.extend(found.0); ret.extend(found.0);
Ok(Some(Tuple(ret))) Ok(Some(Tuple(ret)))
}) })
.map(swap_option_result) .filter_map(swap_option_result),
.flatten(),
) )
}) })
.flatten_ok() .flatten_ok()
@ -1169,8 +1167,7 @@ impl InMemRelationRA {
ret.extend(found.0); ret.extend(found.0);
Ok(Some(Tuple(ret))) Ok(Some(Tuple(ret)))
}) })
.map(swap_option_result) .filter_map(swap_option_result),
.flatten(),
); );
} }
} }
@ -1189,8 +1186,7 @@ impl InMemRelationRA {
ret.extend(found.0); ret.extend(found.0);
Ok(Some(Tuple(ret))) Ok(Some(Tuple(ret)))
}) })
.map(swap_option_result) .filter_map(swap_option_result),
.flatten(),
) )
}) })
.flatten_ok() .flatten_ok()

@ -603,7 +603,7 @@ impl Db {
self, self,
sorted_iter, sorted_iter,
*relation_op, *relation_op,
&meta, meta,
&input_program.get_entry_out_head_or_default()?, &input_program.get_entry_out_head_or_default()?,
) )
.wrap_err_with(|| format!("when executing against relation '{}'", meta.name))?; .wrap_err_with(|| format!("when executing against relation '{}'", meta.name))?;
@ -635,7 +635,7 @@ impl Db {
self, self,
scan, scan,
*relation_op, *relation_op,
&meta, meta,
&input_program.get_entry_out_head_or_default()?, &input_program.get_entry_out_head_or_default()?,
) )
.wrap_err_with(|| format!("when executing against relation '{}'", meta.name))?; .wrap_err_with(|| format!("when executing against relation '{}'", meta.name))?;

@ -320,7 +320,7 @@ impl SessionTx {
let metadata = input_meta.metadata.clone(); let metadata = input_meta.metadata.clone();
let last_id = self.relation_store_id.fetch_add(1, Ordering::SeqCst); let last_id = self.relation_store_id.fetch_add(1, Ordering::SeqCst);
let meta = RelationHandle { let meta = RelationHandle {
name: input_meta.name.name.clone(), name: input_meta.name.name,
id: RelationId::new(last_id + 1), id: RelationId::new(last_id + 1),
metadata, metadata,
put_triggers: vec![], put_triggers: vec![],

Loading…
Cancel
Save