Skip to content

Commit

Permalink
No longer need to recreate static db after crash, and take cost of re…
Browse files Browse the repository at this point in the history
…ading in ntriples initially instead of at first query.
  • Loading branch information
magbak committed Nov 1, 2023
1 parent 59dd580 commit 8c86dc3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion chrontext/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::error::Error;
pub struct Engine {
pushdown_settings: HashSet<PushdownSetting>,
time_series_database: Option<Box<dyn TimeSeriesQueryable>>,
sparql_database: Option<Box<dyn SparqlQueryable>>,
pub sparql_database: Option<Box<dyn SparqlQueryable>>,
}

impl Engine {
Expand Down
2 changes: 1 addition & 1 deletion py_chrontext/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "py_chrontext"
version = "0.5.0"
version = "0.5.1"
edition = "2021"

[workspace]
Expand Down
27 changes: 18 additions & 9 deletions py_chrontext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ timeseries_opcua_db: Optional[TimeseriesOPCUADatabase])")]
timeseries_bigquery_db: Option<TimeseriesBigQueryDatabase>,
timeseries_opcua_db: Option<TimeseriesOPCUADatabase>,
) -> PyResult<Engine> {
let num_sparql = sparql_endpoint.is_some() as usize + sparql_embedded_oxigraph.is_some() as usize;
let num_sparql =
sparql_endpoint.is_some() as usize + sparql_embedded_oxigraph.is_some() as usize;
let num_ts = timeseries_dremio_db.is_some() as usize
+ timeseries_bigquery_db.is_some() as usize
+ timeseries_opcua_db.is_some() as usize;
Expand All @@ -102,14 +103,17 @@ timeseries_opcua_db: Optional[TimeseriesOPCUADatabase])")]
return Err(PyQueryError::MultipleTimeSeriesDatabases.into());
}

Ok(Engine {
let mut engine = Engine {
engine: None,
sparql_endpoint,
sparql_embedded_oxigraph,
timeseries_dremio_db,
timeseries_bigquery_db,
timeseries_opcua_db,
})
};

engine.init_engine()?;
Ok(engine)
}

pub fn init_engine(&mut self) -> PyResult<()> {
Expand All @@ -123,7 +127,15 @@ timeseries_opcua_db: Optional[TimeseriesOPCUADatabase])")]
return Err(PyQueryError::MissingTimeSeriesDatabaseError.into());
};

let sparql_db = if let Some(endpoint) = &self.sparql_endpoint {
let mut sparql_db = if self.engine.is_some() {
self.engine.as_mut().unwrap().sparql_database.take()
} else {
None
};

let sparql_db = if let Some(sparql_db) = sparql_db {
sparql_db
} else if let Some(endpoint) = &self.sparql_endpoint {
Box::new(SparqlEndpoint {
endpoint: endpoint.to_string(),
})
Expand Down Expand Up @@ -185,13 +197,10 @@ pub struct SparqlEmbeddedOxigraph {
#[pymethods]
impl SparqlEmbeddedOxigraph {
#[new]
pub fn new(
path: Option<String>,
ntriples_file: Option<String>,
) -> SparqlEmbeddedOxigraph {
pub fn new(path: Option<String>, ntriples_file: Option<String>) -> SparqlEmbeddedOxigraph {
SparqlEmbeddedOxigraph {
path,
ntriples_file
ntriples_file,
}
}
}
Expand Down

0 comments on commit 8c86dc3

Please sign in to comment.