Adds a "prepare" step during SPARQL query execution

pull/10/head
Tpt 6 years ago
parent 909c7abd07
commit 1772f3df07
  1. 30
      lib/src/sparql/mod.rs
  2. 6
      lib/tests/sparql_test_cases.rs

@ -2,10 +2,12 @@
//! This is a work in progress!!!
use model::Dataset;
use sparql::algebra::Query;
use sparql::algebra::QueryResult;
use sparql::eval::SimpleEvaluator;
use sparql::parser::read_sparql_query;
use std::io::Read;
use std::sync::Arc;
use store::encoded::EncodedQuadsStore;
use store::encoded::StoreDataset;
use Result;
@ -17,12 +19,32 @@ mod plan;
pub mod xml_results;
pub trait SparqlDataset: Dataset {
fn query(&self, query: impl Read) -> Result<QueryResult>;
type PreparedQuery: PreparedQuery;
fn prepare_query(&self, query: impl Read) -> Result<Self::PreparedQuery>;
}
pub trait PreparedQuery {
fn exec(&self) -> Result<QueryResult>;
}
impl<S: EncodedQuadsStore> SparqlDataset for StoreDataset<S> {
fn query(&self, query: impl Read) -> Result<QueryResult> {
let query = read_sparql_query(query, None)?;
SimpleEvaluator::new(self.encoded()).evaluate(&query)
type PreparedQuery = SimplePreparedQuery<S>;
fn prepare_query(&self, query: impl Read) -> Result<SimplePreparedQuery<S>> {
Ok(SimplePreparedQuery {
query: read_sparql_query(query, None)?,
store: self.encoded(),
})
}
}
pub struct SimplePreparedQuery<S: EncodedQuadsStore> {
query: Query,
store: Arc<S>,
}
impl<S: EncodedQuadsStore> PreparedQuery for SimplePreparedQuery<S> {
fn exec(&self) -> Result<QueryResult> {
SimpleEvaluator::new(self.store.clone()).evaluate(&self.query)
}
}

@ -16,6 +16,7 @@ use rudf::sparql::algebra::Query;
use rudf::sparql::algebra::QueryResult;
use rudf::sparql::parser::read_sparql_query;
use rudf::sparql::xml_results::read_xml_results;
use rudf::sparql::PreparedQuery;
use rudf::sparql::SparqlDataset;
use rudf::store::isomorphism::GraphIsomorphism;
use rudf::store::MemoryDataset;
@ -210,7 +211,10 @@ fn sparql_w3c_query_evaluation_testsuite() {
.unwrap()
.for_each(|triple| named_graph.insert(&triple.unwrap()).unwrap());
}
match data.query(client.get(&test.query).unwrap()) {
match data
.prepare_query(client.get(&test.query).unwrap())
.and_then(|p| p.exec())
{
Err(error) => assert!(
false,
"Failure to parse query of {} with error: {}",

Loading…
Cancel
Save