Removes The default_graph_uris and named_graph_uris parameters from Python query methods

pull/58/head
Tpt 4 years ago
parent 1fc952e7fc
commit 39fe1b1704
  1. 5
      CHANGELOG.md
  2. 2
      lib/src/model/parser.rs
  3. 18
      python/src/memory_store.rs
  4. 18
      python/src/sled_store.rs
  5. 17
      python/src/sparql.rs

@ -5,7 +5,10 @@
- [SPARQL 1.1 Query Results CSV and TSV Formats](https://www.w3.org/TR/sparql11-results-csv-tsv/) serializers and TSV format parser. - [SPARQL 1.1 Query Results CSV and TSV Formats](https://www.w3.org/TR/sparql11-results-csv-tsv/) serializers and TSV format parser.
- `std::str::FromStr` implementations to `NamedNode`, `BlankNode`, `Literal`, `Term` and `Variable` allowing to easily parse Turtle/SPARQL serialization of these terms. - `std::str::FromStr` implementations to `NamedNode`, `BlankNode`, `Literal`, `Term` and `Variable` allowing to easily parse Turtle/SPARQL serialization of these terms.
## Changed ### Removed
- The `default_graph_uris` and `named_graph_uris` parameters from `pyoxigraph` `query` methods.
### Changed
- Fixes evaluation of `MONTH()` and `DAY()` functions on the `xsd:date` values. - Fixes evaluation of `MONTH()` and `DAY()` functions on the `xsd:date` values.
- `Variable::new` now validates the variable name. - `Variable::new` now validates the variable name.

@ -258,7 +258,7 @@ impl FromStr for Variable {
/// assert_eq!(Variable::from_str("$foo").unwrap(), Variable::new("foo").unwrap()) /// assert_eq!(Variable::from_str("$foo").unwrap(), Variable::new("foo").unwrap())
/// ``` /// ```
fn from_str(s: &str) -> Result<Self, TermParseError> { fn from_str(s: &str) -> Result<Self, TermParseError> {
if !s.starts_with("?") && !s.starts_with('$') { if !s.starts_with('?') && !s.starts_with('$') {
return Err(TermParseError::msg( return Err(TermParseError::msg(
"Variable serialization should start with ? or $", "Variable serialization should start with ? or $",
)); ));

@ -117,10 +117,6 @@ impl PyMemoryStore {
/// :type default_graph: NamedNode or BlankNode or DefaultGraph or list(NamedNode or BlankNode or DefaultGraph) or None, optional /// :type default_graph: NamedNode or BlankNode or DefaultGraph or list(NamedNode or BlankNode or DefaultGraph) or None, optional
/// :param named_graphs: list of the named graphs that could be used in SPARQL `GRAPH` clause. By default, all the store named graphs are available. /// :param named_graphs: list of the named graphs that could be used in SPARQL `GRAPH` clause. By default, all the store named graphs are available.
/// :type named_graphs: list(NamedNode or BlankNode) or None, optional /// :type named_graphs: list(NamedNode or BlankNode) or None, optional
/// :param default_graph_uris: deprecated, use ``default_graph`` instead
/// :type default_graph_uris: list(NamedNode) or None, optional
/// :param named_graph_uris: deprecated, use ``named_graphs`` instead
/// :type named_graph_uris: list(NamedNode) or None, optional
/// :return: a :py:class:`bool` for ``ASK`` queries, an iterator of :py:class:`Triple` for ``CONSTRUCT`` and ``DESCRIBE`` queries and an iterator of :py:class:`QuerySolution` for ``SELECT`` queries. /// :return: a :py:class:`bool` for ``ASK`` queries, an iterator of :py:class:`Triple` for ``CONSTRUCT`` and ``DESCRIBE`` queries and an iterator of :py:class:`QuerySolution` for ``SELECT`` queries.
/// :rtype: QuerySolutions or QueryTriples or bool /// :rtype: QuerySolutions or QueryTriples or bool
/// :raises SyntaxError: if the provided query is invalid /// :raises SyntaxError: if the provided query is invalid
@ -145,13 +141,11 @@ impl PyMemoryStore {
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> store.query('ASK { ?s ?p ?o }') /// >>> store.query('ASK { ?s ?p ?o }')
/// True /// True
#[text_signature = "($self, query, *, use_default_graph_as_union, default_graph_uris, named_graph_uris, default_graph, named_graphs)"] #[text_signature = "($self, query, *, use_default_graph_as_union, default_graph, named_graphs)"]
#[args( #[args(
query, query,
"*", "*",
use_default_graph_as_union = "false", use_default_graph_as_union = "false",
default_graph_uris = "None",
named_graph_uris = "None",
default_graph = "None", default_graph = "None",
named_graphs = "None" named_graphs = "None"
)] )]
@ -159,19 +153,11 @@ impl PyMemoryStore {
&self, &self,
query: &str, query: &str,
use_default_graph_as_union: bool, use_default_graph_as_union: bool,
default_graph_uris: Option<&PyAny>,
named_graph_uris: Option<&PyAny>,
default_graph: Option<&PyAny>, default_graph: Option<&PyAny>,
named_graphs: Option<&PyAny>, named_graphs: Option<&PyAny>,
py: Python<'_>, py: Python<'_>,
) -> PyResult<PyObject> { ) -> PyResult<PyObject> {
let options = build_query_options( let options = build_query_options(use_default_graph_as_union, default_graph, named_graphs)?;
use_default_graph_as_union,
default_graph_uris,
named_graph_uris,
default_graph,
named_graphs,
)?;
let results = self let results = self
.inner .inner
.query(query, options) .query(query, options)

@ -130,10 +130,6 @@ impl PySledStore {
/// :type default_graph: NamedNode or BlankNode or DefaultGraph or list(NamedNode or BlankNode or DefaultGraph) or None, optional /// :type default_graph: NamedNode or BlankNode or DefaultGraph or list(NamedNode or BlankNode or DefaultGraph) or None, optional
/// :param named_graphs: list of the named graphs that could be used in SPARQL `GRAPH` clause. By default, all the store named graphs are available. /// :param named_graphs: list of the named graphs that could be used in SPARQL `GRAPH` clause. By default, all the store named graphs are available.
/// :type named_graphs: list(NamedNode or BlankNode) or None, optional /// :type named_graphs: list(NamedNode or BlankNode) or None, optional
/// :param default_graph_uris: deprecated, use ``default_graph`` instead
/// :type default_graph_uris: list(NamedNode) or None, optional
/// :param named_graph_uris: deprecated, use ``named_graphs`` instead
/// :type named_graph_uris: list(NamedNode) or None, optional
/// :return: a :py:class:`bool` for ``ASK`` queries, an iterator of :py:class:`Triple` for ``CONSTRUCT`` and ``DESCRIBE`` queries and an iterator of :py:class:`QuerySolution` for ``SELECT`` queries. /// :return: a :py:class:`bool` for ``ASK`` queries, an iterator of :py:class:`Triple` for ``CONSTRUCT`` and ``DESCRIBE`` queries and an iterator of :py:class:`QuerySolution` for ``SELECT`` queries.
/// :rtype: QuerySolutions or QueryTriples or bool /// :rtype: QuerySolutions or QueryTriples or bool
/// :raises SyntaxError: if the provided query is invalid /// :raises SyntaxError: if the provided query is invalid
@ -159,13 +155,11 @@ impl PySledStore {
/// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1'))) /// >>> store.add(Quad(NamedNode('http://example.com'), NamedNode('http://example.com/p'), Literal('1')))
/// >>> store.query('ASK { ?s ?p ?o }') /// >>> store.query('ASK { ?s ?p ?o }')
/// True /// True
#[text_signature = "($self, query, *, use_default_graph_as_union, default_graph_uris, named_graph_uris, default_graph, named_graphs)"] #[text_signature = "($self, query, *, use_default_graph_as_union, default_graph, named_graphs)"]
#[args( #[args(
query, query,
"*", "*",
use_default_graph_as_union = "false", use_default_graph_as_union = "false",
default_graph_uris = "None",
named_graph_uris = "None",
default_graph = "None", default_graph = "None",
named_graphs = "None" named_graphs = "None"
)] )]
@ -173,19 +167,11 @@ impl PySledStore {
&self, &self,
query: &str, query: &str,
use_default_graph_as_union: bool, use_default_graph_as_union: bool,
default_graph_uris: Option<&PyAny>,
named_graph_uris: Option<&PyAny>,
default_graph: Option<&PyAny>, default_graph: Option<&PyAny>,
named_graphs: Option<&PyAny>, named_graphs: Option<&PyAny>,
py: Python<'_>, py: Python<'_>,
) -> PyResult<PyObject> { ) -> PyResult<PyObject> {
let options = build_query_options( let options = build_query_options(use_default_graph_as_union, default_graph, named_graphs)?;
use_default_graph_as_union,
default_graph_uris,
named_graph_uris,
default_graph,
named_graphs,
)?;
let results = self let results = self
.inner .inner
.query(query, options) .query(query, options)

@ -13,28 +13,15 @@ use std::vec::IntoIter;
pub fn build_query_options( pub fn build_query_options(
use_default_graph_as_union: bool, use_default_graph_as_union: bool,
default_graph_uris: Option<&PyAny>,
named_graph_uris: Option<&PyAny>,
default_graph: Option<&PyAny>, default_graph: Option<&PyAny>,
named_graphs: Option<&PyAny>, named_graphs: Option<&PyAny>,
) -> PyResult<QueryOptions> { ) -> PyResult<QueryOptions> {
if default_graph_uris.is_some() && default_graph.is_some() {
return Err(ValueError::py_err(
"The query() method default_graph and default_graph_uris parameters cannot be set at the same time",
));
}
if named_graph_uris.is_some() && named_graphs.is_some() {
return Err(ValueError::py_err(
"The query() method named_graphs and named_graph_uris parameters cannot be set at the same time",
));
}
let mut options = QueryOptions::default(); let mut options = QueryOptions::default();
if use_default_graph_as_union { if use_default_graph_as_union {
options = options.with_default_graph_as_union(); options = options.with_default_graph_as_union();
} }
if let Some(default_graph) = default_graph.or(default_graph_uris) { if let Some(default_graph) = default_graph {
if let Ok(default_graphs) = default_graph.iter() { if let Ok(default_graphs) = default_graph.iter() {
if default_graph.is_empty()? { if default_graph.is_empty()? {
return Err(ValueError::py_err( return Err(ValueError::py_err(
@ -53,7 +40,7 @@ pub fn build_query_options(
} }
} }
if let Some(named_graphs) = named_graphs.or(named_graph_uris) { if let Some(named_graphs) = named_graphs {
if named_graphs.is_empty()? { if named_graphs.is_empty()? {
return Err(ValueError::py_err( return Err(ValueError::py_err(
"The query() method named_graphs argument cannot be empty", "The query() method named_graphs argument cannot be empty",

Loading…
Cancel
Save