Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
magbak committed Dec 26, 2023
1 parent 7312fa1 commit ced7c65
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 130 deletions.
7 changes: 2 additions & 5 deletions arrow_python_utils/src/to_rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ pub fn polars_df_to_rust_df(df: &PyAny) -> PyResult<DataFrame> {
}

pub fn array_to_rust_df(rb: &[&PyAny]) -> PyResult<DataFrame> {
let schema = rb
.get(0)
let schema = rb.first()
.ok_or_else(|| ToRustError::Other("empty table".into()))?
.getattr("schema")?;
let names = schema.getattr("names")?.extract::<Vec<String>>()?;
Expand Down Expand Up @@ -140,9 +139,7 @@ impl std::convert::From<ToRustError> for PyErr {
fn from(err: ToRustError) -> PyErr {
let default = || PyRuntimeError::new_err(format!("{:?}", &err));

match &err {
_ => default(),
}
default()
}
}

Expand Down
10 changes: 5 additions & 5 deletions maplib/src/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ impl Mapping {
base_iri: Option<String>,
transient: bool,
) -> Result<(), MappingError> {
Ok(self
self
.triplestore
.read_triples(p, base_iri, transient)
.map_err(|x| MappingError::TriplestoreError(x))?)
.map_err(MappingError::TriplestoreError)
}

pub fn write_n_triples(&mut self, buffer: &mut dyn Write) -> Result<(), MappingError> {
Expand Down Expand Up @@ -386,7 +386,7 @@ impl Mapping {
if let Some(i) = nonnull {
let first_iri = df.column(colname).unwrap().utf8().unwrap().get(i).unwrap();
{
if !first_iri.starts_with("<") {
if !first_iri.starts_with('<') {
fix_iris.push(colname);
}
}
Expand Down Expand Up @@ -557,7 +557,7 @@ fn create_series_from_blank_node_constant(
}

fn create_remapped(
mut blank_node_counter: usize,
blank_node_counter: usize,
layer: usize,
pattern_num: usize,
instance: &Instance,
Expand Down Expand Up @@ -646,7 +646,7 @@ fn create_remapped(
new_constant_columns.insert(target_colname.clone(), static_column);
}
}
StottrTerm::List(l) => {
StottrTerm::List(_l) => {
todo!()
}
}
Expand Down
12 changes: 2 additions & 10 deletions maplib/src/mapping/constant_terms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,8 @@ pub fn constant_to_expr(
panic!("Should never happen")
}
ConstantLiteral::Literal(lit) => {
let dt = if let Some(nn) = &lit.data_type_iri {
Some(nn.as_ref())
} else {
None
};
let language = if let Some(l) = &lit.language {
Some(l.as_str())
} else {
None
};
let dt = lit.data_type_iri.as_ref().map(|nn| nn.as_ref());
let language = lit.language.as_deref();
let (mut any, dt) = sparql_literal_to_any_value(&lit.value, language, &dt);
//Workaround for owned utf 8..
let value_series = if let AnyValue::Utf8Owned(s) = any {
Expand Down
12 changes: 6 additions & 6 deletions representation/src/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use polars_core::prelude::{AnyValue, DataType, Field};
use std::str::FromStr;

//This code is copied and modified from Chrontext, which has identical licensing
pub fn sparql_literal_to_any_value<'a, 'b>(
value: &'b str,
pub fn sparql_literal_to_any_value<'a>(
value: &str,
language: Option<&str>,
datatype: &Option<NamedNodeRef<'a>>,
) -> (AnyValue<'static>, NamedNodeRef<'a>) {
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn sparql_literal_to_any_value<'a, 'b>(
} else {
todo!("Not implemented! {:?}", datatype)
};
(literal_value, datatype.clone())
(literal_value, datatype)
} else {
(AnyValue::Utf8Owned(value.into()), xsd::STRING)
};
Expand All @@ -81,18 +81,18 @@ pub fn sparql_literal_to_any_value<'a, 'b>(
pub fn parse_literal_as_primitive<T: std::str::FromStr>(
l: Literal,
) -> Result<T, RepresentationError> {
let parsed = l.value().parse().map_err(|x| {
let parsed = l.value().parse().map_err(|_x| {
RepresentationError::InvalidLiteralError(format!("Could not parse as literal {}", l))
})?;
Ok(parsed)
}

pub fn parse_term_as_primitive<T: std::str::FromStr>(term: Term) -> Result<T, RepresentationError> {
Ok(match term {
match term {
Term::Literal(l) => parse_literal_as_primitive(l),
_ => Err(RepresentationError::InvalidLiteralError(format!(
"Wrong term type when trying to parse literal {}",
term
))),
}?)
}
}
2 changes: 1 addition & 1 deletion triplestore/src/ntriples_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ fn write_object_property_triple(f: &mut Vec<u8>, mut any_values: Vec<AnyValue>,
}

fn write_iri_or_blanknode(f: &mut Vec<u8>, s: &str) {
if s.chars().nth(0).unwrap() == '_' {
if s.starts_with('_') {
write!(f, "{}", s).unwrap();
} else {
write_iri(f, s);
Expand Down
4 changes: 2 additions & 2 deletions triplestore/src/sparql/lazy_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ impl Triplestore {
)?;
}

let coalesced_context = inner_contexts.get(0).unwrap();
let coalesced_context = inner_contexts.first().unwrap();
let mut coalesced = col(coalesced_context.as_str());
for c in &inner_contexts[1..inner_contexts.len()] {
coalesced = Expr::Ternary {
Expand All @@ -593,7 +593,7 @@ impl Triplestore {
//TODO: generalize
let existing_type = output_solution_mappings
.rdf_node_types
.get(inner_contexts.get(0).unwrap().as_str())
.get(inner_contexts.first().unwrap().as_str())
.unwrap();
output_solution_mappings
.rdf_node_types
Expand Down
5 changes: 2 additions & 3 deletions triplestore/src/sparql/lazy_graph_patterns/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use log::debug;
use polars::prelude::JoinArgs;
use polars::prelude::{col, Expr, JoinType};
use polars_core::datatypes::DataType;
use representation::RDFNodeType;

use spargebra::algebra::GraphPattern;

impl Triplestore {
Expand Down Expand Up @@ -54,8 +54,7 @@ impl Triplestore {

let mut join_on: Vec<_> = left_solution_mappings
.columns
.intersection(&right_columns)
.map(|x| x.clone())
.intersection(&right_columns).cloned()
.collect();
join_on.sort();

Expand Down
7 changes: 3 additions & 4 deletions triplestore/src/sparql/lazy_graph_patterns/left_join.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use super::Triplestore;
use crate::sparql::errors::SparqlError;
use crate::sparql::multitype::{
create_join_compatible_solution_mappings, join_workaround, lf_printer,
create_join_compatible_solution_mappings, join_workaround,
};
use crate::sparql::query_context::{Context, PathEntry};
use crate::sparql::solution_mapping::{is_string_col, SolutionMappings};
use log::debug;
use polars::prelude::{col, Expr, JoinArgs, JoinType};
use polars_core::datatypes::DataType;
use representation::RDFNodeType;

use spargebra::algebra::{Expression, GraphPattern};

impl Triplestore {
Expand Down Expand Up @@ -52,8 +52,7 @@ impl Triplestore {
} = left_solution_mappings;

let mut join_on: Vec<_> = left_columns
.intersection(&right_columns)
.map(|x| x.clone())
.intersection(&right_columns).cloned()
.collect();
join_on.sort();

Expand Down
14 changes: 5 additions & 9 deletions triplestore/src/sparql/lazy_graph_patterns/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl Triplestore {
subject_lookup_df.rename("value", "subject").unwrap();
out_df = out_df
.join(
&subject_lookup_df,
subject_lookup_df,
&["subject_key"],
&["key"],
JoinArgs::new(JoinType::Inner),
Expand All @@ -120,7 +120,7 @@ impl Triplestore {
object_lookup_df.rename("value", "object").unwrap();
out_df = out_df
.join(
&object_lookup_df,
object_lookup_df,
&["object_key"],
&["key"],
JoinArgs::new(JoinType::Inner),
Expand Down Expand Up @@ -241,7 +241,7 @@ impl Triplestore {
);
for m in &multicols {
mappings.mappings =
convert_lf_col_to_multitype(mappings.mappings, &m, &RDFNodeType::IRI);
convert_lf_col_to_multitype(mappings.mappings, m, &RDFNodeType::IRI);
}
} else {
let join_col_exprs: Vec<Expr> = join_cols.iter().map(|x| col(x)).collect();
Expand Down Expand Up @@ -505,7 +505,7 @@ fn find_lookup(
out_map
}

fn df_with_cats(mut df: DataFrame, subj_dt: &RDFNodeType, obj_dt: &RDFNodeType) -> DataFrame {
fn df_with_cats(df: DataFrame, subj_dt: &RDFNodeType, obj_dt: &RDFNodeType) -> DataFrame {
let mut lf = df.lazy();
if subj_dt == &RDFNodeType::MultiType {
lf = lf.with_column(col("subject").alias("subject_multi"));
Expand Down Expand Up @@ -761,11 +761,7 @@ fn sparse_path(
dt_obj: dt_obj_left,
})
}
} else if let Some(r) = res_right {
Some(r)
} else {
None
}
} else { res_right }
}
PropertyPathExpression::ZeroOrMore(inner) => {
if let Some(SparsePathReturn {
Expand Down
74 changes: 35 additions & 39 deletions triplestore/src/sparql/lazy_graph_patterns/triple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use crate::sparql::sparql_to_polars::{
use crate::sparql::lazy_graph_patterns::load_tt::multiple_tt_to_lf;
use crate::sparql::multitype::{
convert_lf_col_to_multitype, create_join_compatible_solution_mappings, join_workaround,
unicol_to_multitype_value,
};
use log::debug;
use oxrdf::vocab::xsd;
Expand Down Expand Up @@ -50,7 +49,7 @@ impl Triplestore {
let verb_rename = get_keep_rename_named_node_pattern(&triple_pattern.predicate);
let object_rename = get_keep_rename_term_pattern(&triple_pattern.object);

let (mut lf, mut dts, height_0) = match &triple_pattern.predicate {
let (lf, mut dts, height_0) = match &triple_pattern.predicate {
NamedNodePattern::NamedNode(n) => self.get_predicate_lf(
n,
&subject_rename,
Expand Down Expand Up @@ -116,7 +115,7 @@ impl Triplestore {
}
};

let colnames: Vec<_> = dts.keys().map(|x| x.clone()).collect();
let colnames: Vec<_> = dts.keys().cloned().collect();
if let Some(SolutionMappings {
mut mappings,
mut columns,
Expand All @@ -125,8 +124,7 @@ impl Triplestore {
{
let overlap: Vec<_> = colnames
.iter()
.filter(|x| columns.contains(*x))
.map(|x| x.clone())
.filter(|x| columns.contains(*x)).cloned()
.collect();
if height_0 {
// Important that overlapping cols are dropped from mappings and not from lf,
Expand All @@ -137,44 +135,42 @@ impl Triplestore {
} else {
mappings = mappings.join(lf, [], [], JoinType::Cross.into());
}
} else {
if !overlap.is_empty() {
let (new_mappings, new_rdf_node_types, mut lf, new_dts) =
create_join_compatible_solution_mappings(
mappings,
rdf_node_types,
lf,
dts,
true,
);

dts = new_dts;
rdf_node_types = new_rdf_node_types;
mappings = new_mappings;

let join_on: Vec<Expr> = overlap.iter().map(|x| col(x)).collect();
let mut strcol = vec![];
for c in &overlap {
let dt = rdf_node_types.get(c).unwrap();
if is_string_col(dt) {
strcol.push(c);
}
}
for c in strcol {
lf = lf.with_column(col(c).cast(DataType::Categorical(None)));
mappings = mappings.with_column(col(c).cast(DataType::Categorical(None)));
}

mappings = join_workaround(
} else if !overlap.is_empty() {
let (new_mappings, new_rdf_node_types, mut lf, new_dts) =
create_join_compatible_solution_mappings(
mappings,
&rdf_node_types,
rdf_node_types,
lf,
&dts,
JoinType::Inner.into(),
dts,
true,
);
} else {
mappings = mappings.join(lf, [], [], JoinType::Cross.into());

dts = new_dts;
rdf_node_types = new_rdf_node_types;
mappings = new_mappings;

let _join_on: Vec<Expr> = overlap.iter().map(|x| col(x)).collect();
let mut strcol = vec![];
for c in &overlap {
let dt = rdf_node_types.get(c).unwrap();
if is_string_col(dt) {
strcol.push(c);
}
}
for c in strcol {
lf = lf.with_column(col(c).cast(DataType::Categorical(None)));
mappings = mappings.with_column(col(c).cast(DataType::Categorical(None)));
}

mappings = join_workaround(
mappings,
&rdf_node_types,
lf,
&dts,
JoinType::Inner.into(),
);
} else {
mappings = mappings.join(lf, [], [], JoinType::Cross.into());
}
columns.extend(colnames);
rdf_node_types.extend(dts);
Expand Down
4 changes: 1 addition & 3 deletions triplestore/src/sparql/lazy_graph_patterns/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ impl Triplestore {
right_datatypes,
);
for (k, v) in right_datatypes.drain() {
if !left_datatypes.contains_key(&k) {
left_datatypes.insert(k, v);
}
left_datatypes.entry(k).or_insert(v);
}

let output_mappings =
Expand Down
Loading

0 comments on commit ced7c65

Please sign in to comment.