|
|
@ -18,6 +18,8 @@ use crate::sparql::plan::{DatasetView, PlanNode}; |
|
|
|
use crate::sparql::plan_builder::PlanBuilder; |
|
|
|
use crate::sparql::plan_builder::PlanBuilder; |
|
|
|
use crate::store::StoreConnection; |
|
|
|
use crate::store::StoreConnection; |
|
|
|
use crate::Result; |
|
|
|
use crate::Result; |
|
|
|
|
|
|
|
use failure::format_err; |
|
|
|
|
|
|
|
use rio_api::iri::Iri; |
|
|
|
use std::fmt; |
|
|
|
use std::fmt; |
|
|
|
|
|
|
|
|
|
|
|
pub use crate::sparql::algebra::GraphPattern; |
|
|
|
pub use crate::sparql::algebra::GraphPattern; |
|
|
@ -64,31 +66,31 @@ impl<'a, S: StoreConnection + 'a> SimplePreparedQuery<S> { |
|
|
|
QueryVariants::Select { |
|
|
|
QueryVariants::Select { |
|
|
|
algebra, |
|
|
|
algebra, |
|
|
|
dataset: _, |
|
|
|
dataset: _, |
|
|
|
.. |
|
|
|
base_iri, |
|
|
|
} => { |
|
|
|
} => { |
|
|
|
let (plan, variables) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
let (plan, variables) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
SimplePreparedQueryAction::Select { |
|
|
|
SimplePreparedQueryAction::Select { |
|
|
|
plan, |
|
|
|
plan, |
|
|
|
variables, |
|
|
|
variables, |
|
|
|
evaluator: SimpleEvaluator::new(dataset), |
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
QueryVariants::Ask { |
|
|
|
QueryVariants::Ask { |
|
|
|
algebra, |
|
|
|
algebra, |
|
|
|
dataset: _, |
|
|
|
dataset: _, |
|
|
|
.. |
|
|
|
base_iri, |
|
|
|
} => { |
|
|
|
} => { |
|
|
|
let (plan, _) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
let (plan, _) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
SimplePreparedQueryAction::Ask { |
|
|
|
SimplePreparedQueryAction::Ask { |
|
|
|
plan, |
|
|
|
plan, |
|
|
|
evaluator: SimpleEvaluator::new(dataset), |
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
QueryVariants::Construct { |
|
|
|
QueryVariants::Construct { |
|
|
|
construct, |
|
|
|
construct, |
|
|
|
algebra, |
|
|
|
algebra, |
|
|
|
dataset: _, |
|
|
|
dataset: _, |
|
|
|
.. |
|
|
|
base_iri, |
|
|
|
} => { |
|
|
|
} => { |
|
|
|
let (plan, variables) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
let (plan, variables) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
SimplePreparedQueryAction::Construct { |
|
|
|
SimplePreparedQueryAction::Construct { |
|
|
@ -98,18 +100,18 @@ impl<'a, S: StoreConnection + 'a> SimplePreparedQuery<S> { |
|
|
|
&construct, |
|
|
|
&construct, |
|
|
|
variables, |
|
|
|
variables, |
|
|
|
)?, |
|
|
|
)?, |
|
|
|
evaluator: SimpleEvaluator::new(dataset), |
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
QueryVariants::Describe { |
|
|
|
QueryVariants::Describe { |
|
|
|
algebra, |
|
|
|
algebra, |
|
|
|
dataset: _, |
|
|
|
dataset: _, |
|
|
|
.. |
|
|
|
base_iri, |
|
|
|
} => { |
|
|
|
} => { |
|
|
|
let (plan, _) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
let (plan, _) = PlanBuilder::build(dataset.encoder(), &algebra)?; |
|
|
|
SimplePreparedQueryAction::Describe { |
|
|
|
SimplePreparedQueryAction::Describe { |
|
|
|
plan, |
|
|
|
plan, |
|
|
|
evaluator: SimpleEvaluator::new(dataset), |
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
})) |
|
|
|
})) |
|
|
@ -118,14 +120,27 @@ impl<'a, S: StoreConnection + 'a> SimplePreparedQuery<S> { |
|
|
|
pub(crate) fn new_from_pattern( |
|
|
|
pub(crate) fn new_from_pattern( |
|
|
|
connection: S, |
|
|
|
connection: S, |
|
|
|
pattern: &GraphPattern, |
|
|
|
pattern: &GraphPattern, |
|
|
|
|
|
|
|
base_iri: Option<&'a str> |
|
|
|
) -> Result<Self> { |
|
|
|
) -> Result<Self> { |
|
|
|
let dataset = DatasetView::new(connection); |
|
|
|
let dataset = DatasetView::new(connection); |
|
|
|
let (plan, variables) = PlanBuilder::build(dataset.encoder(), pattern)?; |
|
|
|
let (plan, variables) = PlanBuilder::build(dataset.encoder(), pattern)?; |
|
|
|
Ok(Self(SimplePreparedQueryAction::Select { |
|
|
|
let base_iri = base_iri.map(|str_iri| Iri::parse(str_iri.to_string())); |
|
|
|
plan, |
|
|
|
match base_iri { |
|
|
|
variables, |
|
|
|
Some(Err(_)) => Err(format_err!("Failed to parse base_iri")), |
|
|
|
evaluator: SimpleEvaluator::new(dataset), |
|
|
|
Some(Ok(base_iri)) =>
|
|
|
|
})) |
|
|
|
Ok(Self(SimplePreparedQueryAction::Select { |
|
|
|
|
|
|
|
plan, |
|
|
|
|
|
|
|
variables, |
|
|
|
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, Some(base_iri)), |
|
|
|
|
|
|
|
})), |
|
|
|
|
|
|
|
None =>
|
|
|
|
|
|
|
|
Ok(Self(SimplePreparedQueryAction::Select { |
|
|
|
|
|
|
|
plan, |
|
|
|
|
|
|
|
variables, |
|
|
|
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, None), |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|