|
|
@ -29,126 +29,63 @@ pub use crate::sparql::model::QuerySolutionIter; |
|
|
|
pub use crate::sparql::model::QueryTripleIter; |
|
|
|
pub use crate::sparql::model::QueryTripleIter; |
|
|
|
pub use crate::sparql::model::{Variable, VariableNameParseError}; |
|
|
|
pub use crate::sparql::model::{Variable, VariableNameParseError}; |
|
|
|
pub use crate::sparql::parser::ParseError; |
|
|
|
pub use crate::sparql::parser::ParseError; |
|
|
|
use crate::sparql::plan::{PlanNode, TripleTemplate}; |
|
|
|
|
|
|
|
use crate::sparql::plan_builder::PlanBuilder; |
|
|
|
use crate::sparql::plan_builder::PlanBuilder; |
|
|
|
pub use crate::sparql::service::ServiceHandler; |
|
|
|
pub use crate::sparql::service::ServiceHandler; |
|
|
|
use crate::sparql::service::{EmptyServiceHandler, ErrorConversionServiceHandler}; |
|
|
|
use crate::sparql::service::{EmptyServiceHandler, ErrorConversionServiceHandler}; |
|
|
|
use crate::sparql::update::SimpleUpdateEvaluator; |
|
|
|
use crate::sparql::update::SimpleUpdateEvaluator; |
|
|
|
use crate::store::numeric_encoder::{StrContainer, StrEncodingAware}; |
|
|
|
use crate::store::numeric_encoder::StrContainer; |
|
|
|
use crate::store::{ReadableEncodedStore, StoreOrParseError, WritableEncodedStore}; |
|
|
|
use crate::store::{ReadableEncodedStore, StoreOrParseError, WritableEncodedStore}; |
|
|
|
use std::convert::TryInto; |
|
|
|
use std::convert::TryInto; |
|
|
|
use std::io; |
|
|
|
use std::io; |
|
|
|
use std::rc::Rc; |
|
|
|
use std::rc::Rc; |
|
|
|
|
|
|
|
|
|
|
|
/// A prepared [SPARQL query](https://www.w3.org/TR/sparql11-query/)
|
|
|
|
pub(crate) fn evaluate_query<R: ReadableEncodedStore + 'static>( |
|
|
|
pub(crate) struct SimplePreparedQuery<S: ReadableEncodedStore + 'static>( |
|
|
|
store: R, |
|
|
|
SimplePreparedQueryAction<S>, |
|
|
|
query: impl TryInto<Query, Error = impl Into<EvaluationError>>, |
|
|
|
); |
|
|
|
options: QueryOptions, |
|
|
|
|
|
|
|
) -> Result<QueryResults, EvaluationError> { |
|
|
|
#[derive(Clone)] |
|
|
|
match query.try_into().map_err(|e| e.into())?.0 { |
|
|
|
enum SimplePreparedQueryAction<S: ReadableEncodedStore + 'static> { |
|
|
|
QueryVariants::Select { |
|
|
|
Select { |
|
|
|
algebra, |
|
|
|
plan: Rc<PlanNode<<DatasetView<S> as StrEncodingAware>::StrId>>, |
|
|
|
base_iri, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
dataset, |
|
|
|
evaluator: SimpleEvaluator<DatasetView<S>>, |
|
|
|
} => { |
|
|
|
}, |
|
|
|
let dataset = DatasetView::new(store, &dataset)?; |
|
|
|
Ask { |
|
|
|
let (plan, variables) = PlanBuilder::build(&dataset, &algebra)?; |
|
|
|
plan: Rc<PlanNode<<DatasetView<S> as StrEncodingAware>::StrId>>, |
|
|
|
SimpleEvaluator::new(Rc::new(dataset), base_iri, options.service_handler) |
|
|
|
evaluator: SimpleEvaluator<DatasetView<S>>, |
|
|
|
.evaluate_select_plan(&plan, Rc::new(variables)) |
|
|
|
}, |
|
|
|
} |
|
|
|
Construct { |
|
|
|
QueryVariants::Ask { |
|
|
|
plan: Rc<PlanNode<<DatasetView<S> as StrEncodingAware>::StrId>>, |
|
|
|
algebra, |
|
|
|
construct: Rc<Vec<TripleTemplate<<DatasetView<S> as StrEncodingAware>::StrId>>>, |
|
|
|
base_iri, |
|
|
|
evaluator: SimpleEvaluator<DatasetView<S>>, |
|
|
|
dataset, |
|
|
|
}, |
|
|
|
} => { |
|
|
|
Describe { |
|
|
|
let dataset = DatasetView::new(store, &dataset)?; |
|
|
|
plan: Rc<PlanNode<<DatasetView<S> as StrEncodingAware>::StrId>>, |
|
|
|
let (plan, _) = PlanBuilder::build(&dataset, &algebra)?; |
|
|
|
evaluator: SimpleEvaluator<DatasetView<S>>, |
|
|
|
SimpleEvaluator::new(Rc::new(dataset), base_iri, options.service_handler) |
|
|
|
}, |
|
|
|
.evaluate_ask_plan(&plan) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
QueryVariants::Construct { |
|
|
|
impl<S: ReadableEncodedStore + 'static> SimplePreparedQuery<S> { |
|
|
|
construct, |
|
|
|
pub(crate) fn new( |
|
|
|
algebra, |
|
|
|
store: S, |
|
|
|
base_iri, |
|
|
|
query: impl TryInto<Query, Error = impl Into<EvaluationError>>, |
|
|
|
dataset, |
|
|
|
options: QueryOptions, |
|
|
|
} => { |
|
|
|
) -> Result<Self, EvaluationError> { |
|
|
|
let dataset = DatasetView::new(store, &dataset)?; |
|
|
|
Ok(Self(match query.try_into().map_err(|e| e.into())?.0 { |
|
|
|
let (plan, variables) = PlanBuilder::build(&dataset, &algebra)?; |
|
|
|
QueryVariants::Select { |
|
|
|
let construct = PlanBuilder::build_graph_template(&dataset, &construct, variables)?; |
|
|
|
algebra, |
|
|
|
SimpleEvaluator::new(Rc::new(dataset), base_iri, options.service_handler) |
|
|
|
base_iri, |
|
|
|
.evaluate_construct_plan(&plan, construct) |
|
|
|
dataset, |
|
|
|
} |
|
|
|
} => { |
|
|
|
QueryVariants::Describe { |
|
|
|
let dataset = Rc::new(DatasetView::new(store, &dataset)?); |
|
|
|
algebra, |
|
|
|
let (plan, variables) = PlanBuilder::build(dataset.as_ref(), &algebra)?; |
|
|
|
base_iri, |
|
|
|
SimplePreparedQueryAction::Select { |
|
|
|
dataset, |
|
|
|
plan: Rc::new(plan), |
|
|
|
} => { |
|
|
|
variables: Rc::new(variables), |
|
|
|
let dataset = DatasetView::new(store, &dataset)?; |
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler), |
|
|
|
let (plan, _) = PlanBuilder::build(&dataset, &algebra)?; |
|
|
|
} |
|
|
|
SimpleEvaluator::new(Rc::new(dataset), base_iri, options.service_handler) |
|
|
|
} |
|
|
|
.evaluate_describe_plan(&plan) |
|
|
|
QueryVariants::Ask { |
|
|
|
|
|
|
|
algebra, |
|
|
|
|
|
|
|
base_iri, |
|
|
|
|
|
|
|
dataset, |
|
|
|
|
|
|
|
} => { |
|
|
|
|
|
|
|
let dataset = Rc::new(DatasetView::new(store, &dataset)?); |
|
|
|
|
|
|
|
let (plan, _) = PlanBuilder::build(dataset.as_ref(), &algebra)?; |
|
|
|
|
|
|
|
SimplePreparedQueryAction::Ask { |
|
|
|
|
|
|
|
plan: Rc::new(plan), |
|
|
|
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QueryVariants::Construct { |
|
|
|
|
|
|
|
construct, |
|
|
|
|
|
|
|
algebra, |
|
|
|
|
|
|
|
base_iri, |
|
|
|
|
|
|
|
dataset, |
|
|
|
|
|
|
|
} => { |
|
|
|
|
|
|
|
let dataset = Rc::new(DatasetView::new(store, &dataset)?); |
|
|
|
|
|
|
|
let (plan, variables) = PlanBuilder::build(dataset.as_ref(), &algebra)?; |
|
|
|
|
|
|
|
SimplePreparedQueryAction::Construct { |
|
|
|
|
|
|
|
plan: Rc::new(plan), |
|
|
|
|
|
|
|
construct: Rc::new(PlanBuilder::build_graph_template( |
|
|
|
|
|
|
|
dataset.as_ref(), |
|
|
|
|
|
|
|
&construct, |
|
|
|
|
|
|
|
variables, |
|
|
|
|
|
|
|
)?), |
|
|
|
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
QueryVariants::Describe { |
|
|
|
|
|
|
|
algebra, |
|
|
|
|
|
|
|
base_iri, |
|
|
|
|
|
|
|
dataset, |
|
|
|
|
|
|
|
} => { |
|
|
|
|
|
|
|
let dataset = Rc::new(DatasetView::new(store, &dataset)?); |
|
|
|
|
|
|
|
let (plan, _) = PlanBuilder::build(dataset.as_ref(), &algebra)?; |
|
|
|
|
|
|
|
SimplePreparedQueryAction::Describe { |
|
|
|
|
|
|
|
plan: Rc::new(plan), |
|
|
|
|
|
|
|
evaluator: SimpleEvaluator::new(dataset, base_iri, options.service_handler), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Evaluates the query and returns its results
|
|
|
|
|
|
|
|
pub fn exec(&self) -> Result<QueryResults, EvaluationError> { |
|
|
|
|
|
|
|
match &self.0 { |
|
|
|
|
|
|
|
SimplePreparedQueryAction::Select { |
|
|
|
|
|
|
|
plan, |
|
|
|
|
|
|
|
variables, |
|
|
|
|
|
|
|
evaluator, |
|
|
|
|
|
|
|
} => evaluator.evaluate_select_plan(plan, variables.clone()), |
|
|
|
|
|
|
|
SimplePreparedQueryAction::Ask { plan, evaluator } => evaluator.evaluate_ask_plan(plan), |
|
|
|
|
|
|
|
SimplePreparedQueryAction::Construct { |
|
|
|
|
|
|
|
plan, |
|
|
|
|
|
|
|
construct, |
|
|
|
|
|
|
|
evaluator, |
|
|
|
|
|
|
|
} => evaluator.evaluate_construct_plan(plan, construct.clone()), |
|
|
|
|
|
|
|
SimplePreparedQueryAction::Describe { plan, evaluator } => { |
|
|
|
|
|
|
|
evaluator.evaluate_describe_plan(plan) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|