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

@ -343,7 +343,7 @@ impl Expr {
return val.eval(bindings);
}
}
return Ok(DataValue::Null);
Ok(DataValue::Null)
}
Expr::Try { clauses, .. } => {
if clauses.is_empty() {
@ -564,8 +564,7 @@ impl<'de> Visitor<'de> for OpVisitor {
E: Error,
{
let name = v.strip_prefix("OP_").unwrap().to_ascii_lowercase();
Ok(get_op(&name)
.ok_or_else(|| E::custom(format!("op not found in serialized data: {}", v)))?)
get_op(&name).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 {
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_") {
args[1] = Expr::Apply {
op: &OP_REGEX,

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

@ -154,7 +154,7 @@ impl NullableColType {
let make_err = || DataCoercionFailed(self.clone(), data.clone());
return Ok(match &self.coltype {
Ok(match &self.coltype {
ColType::Any => data,
ColType::Int => DataValue::from(data.get_int().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())
}
}
});
})
}
}

@ -25,7 +25,7 @@ impl Ord for UuidWrapper {
s_h.cmp(&o_h)
.then_with(|| s_m.cmp(&o_m))
.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 itertools::Itertools;
use miette::{bail, Diagnostic, ensure, Result};
use miette::{bail, ensure, Diagnostic, Result};
use smartstring::SmartString;
use thiserror::Error;
use crate::data::relation::{ColType, ColumnDef, NullableColType, StoredRelationMetadata};
use crate::data::symb::Symbol;
use crate::data::value::DataValue;
use crate::parse::{ExtractSpan, Pair, Rule, SourceSpan};
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);
let span = pair.extract_span();
@ -55,10 +57,14 @@ pub(crate) fn parse_schema(pair: Pair<'_>) -> Result<(StoredRelationMetadata, Ve
bail!(EmptySchema(span))
}
Ok((StoredRelationMetadata {
keys,
non_keys: dependents,
}, key_bindings, dep_bindings))
Ok((
StoredRelationMetadata {
keys,
non_keys: dependents,
},
key_bindings,
dep_bindings,
))
}
fn parse_col(pair: Pair<'_>) -> Result<(ColumnDef, Symbol)> {
@ -75,26 +81,28 @@ fn parse_col(pair: Pair<'_>) -> Result<(ColumnDef, Symbol)> {
match nxt.as_rule() {
Rule::col_type => typing = parse_nullable_type(nxt)?,
Rule::expr => default_gen = Some(build_expr(nxt, &Default::default())?),
Rule::out_arg => binding_candidate = Some(Symbol::new(nxt.as_str(), nxt.extract_span())),
r => unreachable!("{:?}", r)
Rule::out_arg => {
binding_candidate = Some(Symbol::new(nxt.as_str(), nxt.extract_span()))
}
r => unreachable!("{:?}", r),
}
}
let binding = binding_candidate.unwrap_or_else(||
Symbol::new(&name as &str, name_p.extract_span()));
Ok((ColumnDef {
name,
typing,
default_gen,
}, binding))
let binding =
binding_candidate.unwrap_or_else(|| Symbol::new(&name as &str, name_p.extract_span()));
Ok((
ColumnDef {
name,
typing,
default_gen,
},
binding,
))
}
pub(crate) fn parse_nullable_type(pair: Pair<'_>) -> Result<NullableColType> {
let nullable = pair.as_str().ends_with('?');
let coltype = parse_type_inner(pair.into_inner().next().unwrap())?;
Ok(NullableColType {
coltype,
nullable,
})
Ok(NullableColType { coltype, nullable })
}
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))]
struct BadListLenSpec(DataValue, #[label] SourceSpan);
let n = dv.get_int()
.ok_or_else(|| BadListLenSpec(dv, span))?;
let n = dv.get_int().ok_or(BadListLenSpec(dv, span))?;
ensure!(n >= 0, BadListLenSpec(DataValue::from(n), span));
Some(n as usize)
}
};
ColType::List { eltype: eltype.into(), len }
ColType::List {
eltype: eltype.into(),
len,
}
}
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,
ListRunning,
KillRunning(u64),
Explain(InputProgram),
Explain(Box<InputProgram>),
RemoveRelation(Vec<Symbol>),
RenameRelation(Vec<(Symbol, Symbol)>),
ShowTrigger(Symbol),
@ -44,7 +44,7 @@ pub(crate) fn parse_sys(
}
Rule::explain_op => {
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::remove_relations_op => {

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

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

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

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

Loading…
Cancel
Save