Makes TermReader use IoError

pull/46/head
Tpt 4 years ago
parent 44d448c819
commit ce2b05b62b
  1. 37
      lib/src/store/numeric_encoder.rs
  2. 2
      lib/src/store/rocksdb.rs
  3. 4
      lib/src/store/sled.rs

@ -12,7 +12,7 @@ use siphasher::sip128::{Hasher128, SipHasher24};
use std::collections::HashMap;
use std::hash::Hash;
use std::hash::Hasher;
use std::io::{Cursor, Read};
use std::io::{Cursor, Error as IoError, ErrorKind, Read, Result as IoResult};
use std::mem::size_of;
use std::str;
@ -607,17 +607,17 @@ impl From<&Quad> for EncodedQuad {
}
pub trait TermReader {
fn read_term(&mut self) -> Result<EncodedTerm>;
fn read_spog_quad(&mut self) -> Result<EncodedQuad>;
fn read_posg_quad(&mut self) -> Result<EncodedQuad>;
fn read_ospg_quad(&mut self) -> Result<EncodedQuad>;
fn read_gspo_quad(&mut self) -> Result<EncodedQuad>;
fn read_gpos_quad(&mut self) -> Result<EncodedQuad>;
fn read_gosp_quad(&mut self) -> Result<EncodedQuad>;
fn read_term(&mut self) -> IoResult<EncodedTerm>;
fn read_spog_quad(&mut self) -> IoResult<EncodedQuad>;
fn read_posg_quad(&mut self) -> IoResult<EncodedQuad>;
fn read_ospg_quad(&mut self) -> IoResult<EncodedQuad>;
fn read_gspo_quad(&mut self) -> IoResult<EncodedQuad>;
fn read_gpos_quad(&mut self) -> IoResult<EncodedQuad>;
fn read_gosp_quad(&mut self) -> IoResult<EncodedQuad>;
}
impl<R: Read> TermReader for R {
fn read_term(&mut self) -> Result<EncodedTerm> {
fn read_term(&mut self) -> IoResult<EncodedTerm> {
let mut type_buffer = [0];
self.read_exact(&mut type_buffer)?;
match type_buffer[0] {
@ -730,11 +730,14 @@ impl<R: Read> TermReader for R {
DayTimeDuration::from_be_bytes(buffer),
))
}
_ => Err(Error::msg("the term buffer has an invalid type id")),
_ => Err(IoError::new(
ErrorKind::InvalidData,
"the term buffer has an invalid type id",
)),
}
}
fn read_spog_quad(&mut self) -> Result<EncodedQuad> {
fn read_spog_quad(&mut self) -> IoResult<EncodedQuad> {
let subject = self.read_term()?;
let predicate = self.read_term()?;
let object = self.read_term()?;
@ -747,7 +750,7 @@ impl<R: Read> TermReader for R {
})
}
fn read_posg_quad(&mut self) -> Result<EncodedQuad> {
fn read_posg_quad(&mut self) -> IoResult<EncodedQuad> {
let predicate = self.read_term()?;
let object = self.read_term()?;
let subject = self.read_term()?;
@ -760,7 +763,7 @@ impl<R: Read> TermReader for R {
})
}
fn read_ospg_quad(&mut self) -> Result<EncodedQuad> {
fn read_ospg_quad(&mut self) -> IoResult<EncodedQuad> {
let object = self.read_term()?;
let subject = self.read_term()?;
let predicate = self.read_term()?;
@ -773,7 +776,7 @@ impl<R: Read> TermReader for R {
})
}
fn read_gspo_quad(&mut self) -> Result<EncodedQuad> {
fn read_gspo_quad(&mut self) -> IoResult<EncodedQuad> {
let graph_name = self.read_term()?;
let subject = self.read_term()?;
let predicate = self.read_term()?;
@ -786,7 +789,7 @@ impl<R: Read> TermReader for R {
})
}
fn read_gpos_quad(&mut self) -> Result<EncodedQuad> {
fn read_gpos_quad(&mut self) -> IoResult<EncodedQuad> {
let graph_name = self.read_term()?;
let predicate = self.read_term()?;
let object = self.read_term()?;
@ -799,7 +802,7 @@ impl<R: Read> TermReader for R {
})
}
fn read_gosp_quad(&mut self) -> Result<EncodedQuad> {
fn read_gosp_quad(&mut self) -> IoResult<EncodedQuad> {
let graph_name = self.read_term()?;
let object = self.read_term()?;
let subject = self.read_term()?;
@ -906,7 +909,7 @@ pub enum QuadEncoding {
}
impl QuadEncoding {
pub fn decode(self, buffer: &[u8]) -> Result<EncodedQuad> {
pub fn decode(self, buffer: &[u8]) -> IoResult<EncodedQuad> {
let mut cursor = Cursor::new(&buffer);
match self {
QuadEncoding::SPOG => cursor.read_spog_quad(),

@ -759,7 +759,7 @@ impl<'a> Iterator for DecodingIndexIterator<'a> {
fn next(&mut self) -> Option<Result<EncodedQuad>> {
if let Some(key) = self.iter.key() {
if key.starts_with(&self.prefix) {
let result = self.encoding.decode(key);
let result = self.encoding.decode(key).map_err(crate::Error::from);
self.iter.next();
Some(result)
} else {

@ -4,7 +4,7 @@ use crate::model::*;
use crate::sparql::{GraphPattern, QueryOptions, QueryResult, SimplePreparedQuery};
use crate::store::numeric_encoder::*;
use crate::store::{load_dataset, load_graph, ReadableEncodedStore, WritableEncodedStore};
use crate::{DatasetSyntax, GraphSyntax, Result};
use crate::{DatasetSyntax, Error, GraphSyntax, Result};
use sled::{Config, Iter, Tree};
use std::io::BufRead;
use std::path::Path;
@ -556,7 +556,7 @@ impl Iterator for DecodingQuadIterator {
fn next(&mut self) -> Option<Result<EncodedQuad>> {
Some(match self.iter.next()? {
Ok((encoded, _)) => self.order.decode(&encoded),
Ok((encoded, _)) => self.order.decode(&encoded).map_err(Error::from),
Err(error) => Err(error.into()),
})
}

Loading…
Cancel
Save