diff --git a/chrontext/src/engine.rs b/chrontext/src/engine.rs index e4dd22a..61e492c 100644 --- a/chrontext/src/engine.rs +++ b/chrontext/src/engine.rs @@ -13,7 +13,7 @@ use std::error::Error; pub struct Engine { pushdown_settings: HashSet, time_series_database: Option>, - sparql_database: Option>, + pub sparql_database: Option>, } impl Engine { diff --git a/py_chrontext/Cargo.toml b/py_chrontext/Cargo.toml index 386c0f2..bebefc9 100644 --- a/py_chrontext/Cargo.toml +++ b/py_chrontext/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "py_chrontext" -version = "0.5.0" +version = "0.5.1" edition = "2021" [workspace] diff --git a/py_chrontext/src/lib.rs b/py_chrontext/src/lib.rs index bca19f1..158b871 100644 --- a/py_chrontext/src/lib.rs +++ b/py_chrontext/src/lib.rs @@ -83,7 +83,8 @@ timeseries_opcua_db: Optional[TimeseriesOPCUADatabase])")] timeseries_bigquery_db: Option, timeseries_opcua_db: Option, ) -> PyResult { - 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; @@ -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<()> { @@ -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(), }) @@ -185,13 +197,10 @@ pub struct SparqlEmbeddedOxigraph { #[pymethods] impl SparqlEmbeddedOxigraph { #[new] - pub fn new( - path: Option, - ntriples_file: Option, - ) -> SparqlEmbeddedOxigraph { + pub fn new(path: Option, ntriples_file: Option) -> SparqlEmbeddedOxigraph { SparqlEmbeddedOxigraph { path, - ntriples_file + ntriples_file, } } }